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);
}
}
Aggregations