Search in sources :

Example 1 with BlobSasPermission

use of com.azure.storage.blob.sas.BlobSasPermission in project conductor by Netflix.

the class AzureBlobPayloadStorage method getLocation.

/**
 * @param operation   the type of {@link Operation} to be performed
 * @param payloadType the {@link PayloadType} that is being accessed
 * @return a {@link ExternalStorageLocation} object which contains the pre-signed URL and the azure blob name
 *  for the json payload
 */
@Override
public ExternalStorageLocation getLocation(Operation operation, PayloadType payloadType, String path) {
    try {
        ExternalStorageLocation externalStorageLocation = new ExternalStorageLocation();
        String objectKey;
        if (StringUtils.isNotBlank(path)) {
            objectKey = path;
        } else {
            objectKey = getObjectKey(payloadType);
        }
        externalStorageLocation.setPath(objectKey);
        BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(objectKey).getBlockBlobClient();
        String blobUrl = Utility.urlDecode(blockBlobClient.getBlobUrl());
        if (sasTokenCredential != null) {
            blobUrl = blobUrl + "?" + sasTokenCredential.getSasToken();
        } else {
            BlobSasPermission blobSASPermission = new BlobSasPermission();
            if (operation.equals(Operation.READ)) {
                blobSASPermission.setReadPermission(true);
            } else if (operation.equals(Operation.WRITE)) {
                blobSASPermission.setWritePermission(true);
                blobSASPermission.setCreatePermission(true);
            }
            BlobServiceSasSignatureValues blobServiceSasSignatureValues = new BlobServiceSasSignatureValues(OffsetDateTime.now(ZoneOffset.UTC).plusSeconds(expirationSec), blobSASPermission);
            blobUrl = blobUrl + "?" + blockBlobClient.generateSas(blobServiceSasSignatureValues);
        }
        externalStorageLocation.setUri(blobUrl);
        return externalStorageLocation;
    } catch (BlobStorageException e) {
        String msg = "Error communicating with Azure";
        logger.error(msg, e);
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e);
    }
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) BlockBlobClient(com.azure.storage.blob.specialized.BlockBlobClient) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) BlobSasPermission(com.azure.storage.blob.sas.BlobSasPermission) ExternalStorageLocation(com.netflix.conductor.common.run.ExternalStorageLocation) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Aggregations

BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 BlobSasPermission (com.azure.storage.blob.sas.BlobSasPermission)1 BlobServiceSasSignatureValues (com.azure.storage.blob.sas.BlobServiceSasSignatureValues)1 BlockBlobClient (com.azure.storage.blob.specialized.BlockBlobClient)1 ExternalStorageLocation (com.netflix.conductor.common.run.ExternalStorageLocation)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1