Search in sources :

Example 1 with BlobContainerSasPermission

use of com.azure.storage.blob.sas.BlobContainerSasPermission 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 2 with BlobContainerSasPermission

use of com.azure.storage.blob.sas.BlobContainerSasPermission 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 3 with BlobContainerSasPermission

use of com.azure.storage.blob.sas.BlobContainerSasPermission 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 4 with BlobContainerSasPermission

use of com.azure.storage.blob.sas.BlobContainerSasPermission 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

BlobContainerSasPermission (com.azure.storage.blob.sas.BlobContainerSasPermission)4 BlobServiceSasSignatureValues (com.azure.storage.blob.sas.BlobServiceSasSignatureValues)4 BlobCopyInfo (com.azure.storage.blob.models.BlobCopyInfo)1 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 OffsetDateTime (java.time.OffsetDateTime)1 AzureSasToken (org.eclipse.dataspaceconnector.azure.blob.core.AzureSasToken)1