Skip to content

Commit

Permalink
DVX-563: Added support for Azure Blob presigned URL uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Aug 12, 2024
1 parent b20cc7b commit d38bd41
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
37 changes: 36 additions & 1 deletion atlan/assets/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,41 @@ func (ac *AtlanClient) s3PresignedUrlFileUpload(api *API, uploadFile *os.File, u
return nil
}

func (ac *AtlanClient) azureBlobPresignedUrlFileUpload(api *API, uploadFile *os.File, uploadFileSize int64) error {
// Remove authorization and returns the auth value
auth, err := ac.removeAuthorization()
if err != nil {
return err
}

// Add mandatory headers for Azure Blob storage
if headers, ok := ac.requestParams["headers"].(map[string]string); ok {
headers["x-ms-blob-type"] = "BlockBlob"
}

// Call the API with upload file options
uploadProgressBarDescription := "Uploading file to the object store:"
uploadProgressBar := initFileProgressBar(uploadFileSize, uploadProgressBarDescription)
options := map[string]interface{}{
"use_presigned_url": true,
"file_size": uploadFileSize,
"progress_bar": uploadProgressBar,
}
_, err = ac.CallAPI(api, nil, uploadFile, options)
if err != nil {
return err
}

// Restore authorization after API call
err = ac.restoreAuthorization(auth)
if err != nil {
ac.logger.Errorf("failed to restore authorization: %s", err)
return err
}

return nil
}

func (ac *AtlanClient) s3PresignedUrlFileDownload(api *API, downloadFilePath string) error {
// Remove authorization and returns the auth value
auth, err := ac.removeAuthorization()
Expand Down Expand Up @@ -414,7 +449,7 @@ func (ac *AtlanClient) CallAPI(api *API, queryParams interface{}, requestObj int
}
}

ac.logger.Infof("Successfully downloaded file: %s", file.Name())
ac.logger.Debugf("Successfully downloaded file: %s", file.Name())
return []byte{}, nil
}

Expand Down
12 changes: 10 additions & 2 deletions atlan/assets/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ func (client *FileClient) GeneratePresignedURL(request *model.PresignedURLReques

// Uploads a file to Atlan's object storage.
func (client *FileClient) UploadFile(presignedUrl string, filePath string) error {
var PRESIGNED_URL_UPLOAD = API{
var PRESIGNED_URL_UPLOAD_S3 = API{
Path: presignedUrl,
Method: http.MethodPut,
Status: http.StatusOK,
Endpoint: HeraclesEndpoint,
}
var PRESIGNED_URL_UPLOAD_AZURE_BLOB = API{
Path: presignedUrl,
Method: http.MethodPut,
Status: http.StatusCreated,
Endpoint: HeraclesEndpoint,
}

file, fileInfo, err := handleFileUpload(filePath)
if err != nil {
Expand All @@ -76,7 +82,9 @@ func (client *FileClient) UploadFile(presignedUrl string, filePath string) error
// Currently supported upload methods for different cloud storage providers
switch {
case strings.Contains(presignedUrl, string(model.S3)):
err = client.s3PresignedUrlFileUpload(&PRESIGNED_URL_UPLOAD, file, fileInfo.Size())
err = client.s3PresignedUrlFileUpload(&PRESIGNED_URL_UPLOAD_S3, file, fileInfo.Size())
case strings.Contains(presignedUrl, string(model.AzureBlob)):
err = client.azureBlobPresignedUrlFileUpload(&PRESIGNED_URL_UPLOAD_AZURE_BLOB, file, fileInfo.Size())
default:
return InvalidRequestError{AtlanError{ErrorCode: errorCodes[UNSUPPORTED_PRESIGNED_URL]}}
}
Expand Down

0 comments on commit d38bd41

Please sign in to comment.