Search in sources :

Example 1 with BlobServiceSasSignatureValues

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

Example 2 with BlobServiceSasSignatureValues

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);
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) OffsetDateTime(java.time.OffsetDateTime) BlobContainerSasPermission(com.azure.storage.blob.sas.BlobContainerSasPermission)

Example 3 with BlobServiceSasSignatureValues

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)));
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) BlobContainerSasPermission(com.azure.storage.blob.sas.BlobContainerSasPermission) AzureSasToken(org.eclipse.dataspaceconnector.azure.blob.core.AzureSasToken)

Example 4 with BlobServiceSasSignatureValues

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);
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) BlobContainerSasPermission(com.azure.storage.blob.sas.BlobContainerSasPermission)

Example 5 with BlobServiceSasSignatureValues

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;
    }
}
Also used : BlobServiceSasSignatureValues(com.azure.storage.blob.sas.BlobServiceSasSignatureValues) BlobContainerSasPermission(com.azure.storage.blob.sas.BlobContainerSasPermission) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) BlobCopyInfo(com.azure.storage.blob.models.BlobCopyInfo)

Aggregations

BlobServiceSasSignatureValues (com.azure.storage.blob.sas.BlobServiceSasSignatureValues)5 BlobContainerSasPermission (com.azure.storage.blob.sas.BlobContainerSasPermission)4 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)2 BlobCopyInfo (com.azure.storage.blob.models.BlobCopyInfo)1 BlobSasPermission (com.azure.storage.blob.sas.BlobSasPermission)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 OffsetDateTime (java.time.OffsetDateTime)1 AzureSasToken (org.eclipse.dataspaceconnector.azure.blob.core.AzureSasToken)1