Search in sources :

Example 1 with BlobContainerPermissions

use of com.microsoft.azure.storage.blob.BlobContainerPermissions in project azure-sdk-for-java by Azure.

the class ManageWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 2 with BlobContainerPermissions

use of com.microsoft.azure.storage.blob.BlobContainerPermissions in project azure-sdk-for-java by Azure.

the class ManageLinuxWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 3 with BlobContainerPermissions

use of com.microsoft.azure.storage.blob.BlobContainerPermissions in project cloudbreak by hortonworks.

the class AzureClient method setPublicPermissionOnContainer.

public void setPublicPermissionOnContainer(String resourceGroup, String storageName, String containerName) {
    LOGGER.debug("set public permission on container: RG={}, storageName={}, containerName={}", resourceGroup, storageName, containerName);
    CloudBlobContainer container = getBlobContainer(resourceGroup, storageName, containerName);
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
    try {
        container.uploadPermissions(containerPermissions);
    } catch (StorageException e) {
        throw new CloudConnectorException("can't set public permission on container, storage service error occurred", e);
    }
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with BlobContainerPermissions

use of com.microsoft.azure.storage.blob.BlobContainerPermissions in project components by Talend.

the class AzureStorageBlobService method setPublicAccess.

public void setPublicAccess(String containerName) throws URISyntaxException, StorageException, InvalidKeyException {
    CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
    cloudBlobContainer.uploadPermissions(containerPermissions);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions)

Aggregations

BlobContainerPermissions (com.microsoft.azure.storage.blob.BlobContainerPermissions)4 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)4 StorageException (com.microsoft.azure.storage.StorageException)3 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 URISyntaxException (java.net.URISyntaxException)2 InvalidKeyException (java.security.InvalidKeyException)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1