use of com.azure.storage.blob.sas.BlobServiceSasSignatureValues 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);
}
}
use of com.azure.storage.blob.sas.BlobServiceSasSignatureValues in project azure-iot-sdk-java by Azure.
the class ExportImportTests method getContainerSasUri.
private static String getContainerSasUri(BlobContainerClient blobContainerClient) {
OffsetDateTime expiryTime = OffsetDateTime.now().plusDays(1);
BlobContainerSasPermission permission = new BlobContainerSasPermission().setReadPermission(true).setAddPermission(true).setCreatePermission(true).setDeletePermission(true).setListPermission(true);
BlobServiceSasSignatureValues values = new BlobServiceSasSignatureValues(expiryTime, permission).setStartTime(OffsetDateTime.now());
return blobContainerClient.generateSas(values);
}
use of com.azure.storage.blob.sas.BlobServiceSasSignatureValues in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AzureDataFactoryCopyIntegrationTest method setSecret.
private void setSecret(Account account, Vault vault, String secretName) {
// ADF SLA to start an activity is 4 minutes.
var expiryTime = OffsetDateTime.now().plusMinutes(8);
var permission = new BlobContainerSasPermission().setWritePermission(true);
var sasSignatureValues = new BlobServiceSasSignatureValues(expiryTime, permission).setStartTime(OffsetDateTime.now());
var sasToken = account.client.getBlobContainerClient(account.containerName).generateSas(sasSignatureValues);
var edcAzureSas = new AzureSasToken(sasToken, expiryTime.toEpochSecond());
// Set Secret
vault.secretClient().setSecret(secretName, typeManager.writeValueAsString(edcAzureSas)).block(Duration.ofMinutes(1));
// Add for clean up test data
secretCleanup.add(() -> vault.secretClient().beginDeleteSecret(secretName).blockLast(Duration.ofMinutes(1)));
secretCleanup.add(() -> vault.secretClient().purgeDeletedSecret(secretName).block(Duration.ofMinutes(1)));
}
use of com.azure.storage.blob.sas.BlobServiceSasSignatureValues in project DataSpaceConnector by eclipse-dataspaceconnector.
the class BlobStoreApiImpl method createContainerSasToken.
@Override
public String createContainerSasToken(String accountName, String containerName, String permissionSpec, OffsetDateTime expiry) {
BlobContainerSasPermission permissions = BlobContainerSasPermission.parse(permissionSpec);
BlobServiceSasSignatureValues vals = new BlobServiceSasSignatureValues(expiry, permissions);
return getBlobServiceClient(accountName).getBlobContainerClient(containerName).generateSas(vals);
}
use of com.azure.storage.blob.sas.BlobServiceSasSignatureValues in project bulk-scan-processor by hmcts.
the class BlobManager method copyToRejectedContainer.
private void copyToRejectedContainer(BlobClient sourceBlob, BlobClient targetBlob) {
String sasToken = sourceBlob.generateSas(new BlobServiceSasSignatureValues(OffsetDateTime.of(LocalDateTime.now().plus(5, ChronoUnit.MINUTES), ZoneOffset.UTC), new BlobContainerSasPermission().setReadPermission(true)));
var start = System.nanoTime();
SyncPoller<BlobCopyInfo, Void> poller = null;
try {
poller = targetBlob.beginCopy(sourceBlob.getBlobUrl() + "?" + sasToken, META_DATA_MAP, null, null, null, null, Duration.ofSeconds(2));
PollResponse<BlobCopyInfo> pollResponse = poller.waitForCompletion(Duration.ofMinutes(5));
targetBlob.setMetadata(null);
log.info("Moved to rejected container from {}. Poll response: {}, Copy status: {} ,Takes {} second", sourceBlob.getBlobUrl(), pollResponse.getStatus(), pollResponse.getValue().getCopyStatus(), TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start));
} catch (Exception ex) {
log.error("Copy Error, for {} to rejected container", sourceBlob.getBlobUrl(), ex);
if (poller != null) {
try {
targetBlob.abortCopyFromUrl(poller.poll().getValue().getCopyId());
} catch (Exception exc) {
log.error("Abort Copy From Url got Error, From {} to rejected container", sourceBlob.getBlobUrl(), exc);
}
}
throw ex;
}
}
Aggregations