/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String containerName = this.getName(); return String.format("/%s/%s/%s", SR.BLOB, accountName, containerName); }
/** * Returns the canonical name for shared access. * * @return the canonical name for shared access. */ private String getSharedAccessCanonicalName() { String accountName = this.getServiceClient().getCredentials().getAccountName(); String containerName = this.getName(); return String.format("/%s/%s/%s", SR.BLOB, accountName, containerName); }
protected CloudBlobContainer getAzureContainer() throws DataStoreException { CloudBlobContainer container = Utils.getBlobContainer(connectionString, containerName); RequestOptions requestOptions = container.getServiceClient().getDefaultRequestOptions(); if (retryPolicy != null) { requestOptions.setRetryPolicyFactory(retryPolicy); } if (requestTimeout != null) { requestOptions.setTimeoutIntervalInMs(requestTimeout); } return container; }
@Override public HttpURLConnection buildRequest(CloudBlobClient client, CloudBlobContainer container, OperationContext context) throws Exception { StorageUri transformedblobUri = CloudBlobContainer.this.getServiceClient().getCredentials().transformUri(blobUri, context); return BlobRequest.getBlobProperties(transformedblobUri.getUri(this.getCurrentLocation()), options, context, accessCondition, snapshotID); }
@Override public HttpURLConnection buildRequest(CloudBlobClient client, CloudBlobContainer container, OperationContext context) throws Exception { StorageUri transformedblobUri = CloudBlobContainer.this.getServiceClient().getCredentials().transformUri(blobUri, context); return BlobRequest.getBlobProperties(transformedblobUri.getUri(this.getCurrentLocation()), options, context, accessCondition, snapshotID); }
@Override public CloudBlobContainerWrapper getContainerReference(String name) throws URISyntaxException, StorageException { try { CloudBlobContainer container = new CloudBlobContainer(sasKeyGenerator.getContainerSASUri( storageAccount, name)); if (retryPolicy != null) { container.getServiceClient().getDefaultRequestOptions().setRetryPolicyFactory(retryPolicy); } if (timeoutIntervalInMs > 0) { container.getServiceClient().getDefaultRequestOptions().setTimeoutIntervalInMs(timeoutIntervalInMs); } return (useContainerSasKeyForAllAccess) ? new SASCloudBlobContainerWrapperImpl(storageAccount, container, null) : new SASCloudBlobContainerWrapperImpl(storageAccount, container, sasKeyGenerator); } catch (SASKeyGenerationException sasEx) { String errorMsg = "Encountered SASKeyGeneration exception while " + "generating SAS Key for container : " + name + " inside Storage account : " + storageAccount; LOG.error(errorMsg); throw new StorageException(SAS_ERROR_CODE, errorMsg, sasEx); } }
/** * Creates an instance of the <code>CloudBlob</code> class using the specified type, name, snapshot ID, and * container. * * @param type * A {@link BlobType} value which represents the type of the blob. * @param blobName * Name of the blob. * @param snapshotID * A <code>String</code> that represents the snapshot version, if applicable. * @param container * The reference to the parent container. * @throws URISyntaxException * If the resource URI is invalid. */ protected CloudBlob(final BlobType type, String blobName, String snapshotID, CloudBlobContainer container) throws URISyntaxException { Utility.assertNotNullOrEmpty("blobName", blobName); Utility.assertNotNull("container", container); this.storageUri = PathUtility.appendPathToUri(container.getStorageUri(), blobName); this.name = blobName; this.blobServiceClient = container.getServiceClient(); this.container = container; this.snapshotID = snapshotID; this.properties = new BlobProperties(type); }
/** * Creates an instance of the <code>CloudBlob</code> class using the specified type, name, snapshot ID, and * container. * * @param type * A {@link BlobType} value which represents the type of the blob. * @param blobName * Name of the blob. * @param snapshotID * A <code>String</code> that represents the snapshot version, if applicable. * @param container * The reference to the parent container. * @throws URISyntaxException * If the resource URI is invalid. */ protected CloudBlob(final BlobType type, String blobName, String snapshotID, CloudBlobContainer container) throws URISyntaxException { Utility.assertNotNullOrEmpty("blobName", blobName); Utility.assertNotNull("container", container); this.storageUri = PathUtility.appendPathToUri(container.getStorageUri(), blobName); this.name = blobName; this.blobServiceClient = container.getServiceClient(); this.container = container; this.snapshotID = snapshotID; this.properties = new BlobProperties(type); }
@Override public CloudBlobWrapper getBlockBlobReference(String relativePath) throws URISyntaxException, StorageException { try { CloudBlockBlob blob = (sasKeyGenerator!=null) ? new CloudBlockBlob(sasKeyGenerator.getRelativeBlobSASUri(storageAccount, getName(), relativePath)) : container.getBlockBlobReference(relativePath); blob.getServiceClient().setDefaultRequestOptions( container.getServiceClient().getDefaultRequestOptions()); return new SASCloudBlockBlobWrapperImpl(blob); } catch (SASKeyGenerationException sasEx) { String errorMsg = "Encountered SASKeyGeneration exception while " + "generating SAS Key for relativePath : " + relativePath + " inside container : " + getName() + " Storage account : " + storageAccount; LOG.error(errorMsg); throw new StorageException(SAS_ERROR_CODE, errorMsg, sasEx); } }
@Override public CloudBlobWrapper getPageBlobReference(String relativePath) throws URISyntaxException, StorageException { try { CloudPageBlob blob = (sasKeyGenerator!=null) ? new CloudPageBlob(sasKeyGenerator.getRelativeBlobSASUri(storageAccount, getName(), relativePath)) : container.getPageBlobReference(relativePath); blob.getServiceClient().setDefaultRequestOptions( container.getServiceClient().getDefaultRequestOptions()); return new SASCloudPageBlobWrapperImpl(blob); } catch (SASKeyGenerationException sasEx) { String errorMsg = "Encountered SASKeyGeneration exception while " + "generating SAS Key for relativePath : " + relativePath + " inside container : " + getName() + " Storage account : " + storageAccount; LOG.error(errorMsg); throw new StorageException(SAS_ERROR_CODE, errorMsg, sasEx); } } }
containerReadListSas)); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), readListContainer.getServiceClient() .getCredentials().getClass().toString()); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), containerFromUri.getServiceClient() .getCredentials().getClass().toString()); CloudBlobClient bClient = new CloudBlobClient(this.container.getServiceClient().getStorageUri(), creds); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), containerFromClient.getServiceClient() .getCredentials().getClass().toString()); assertEquals(bClient, containerFromClient.getServiceClient());
PathUtility.addToQuery(httpUri, containerSasHttps)); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob httpBlob = httpContainer.getBlockBlobReference(this.blob.getName()); httpBlob.download(new ByteArrayOutputStream()); PathUtility.addToQuery(httpsUri, containerSasHttps)); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpsContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob httpsBlob = httpsContainer.getBlockBlobReference(this.blob.getName()); httpsBlob.download(new ByteArrayOutputStream()); PathUtility.addToQuery(httpUri, containerSasHttp)); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpContainer.getServiceClient().getCredentials().getClass().toString()); CloudBlockBlob httpBlob = httpContainer.getBlockBlobReference(this.blob.getName()); httpBlob.download(new ByteArrayOutputStream()); PathUtility.addToQuery(httpsUri, containerSasHttp)); assertEquals(StorageCredentialsSharedAccessSignature.class.toString(), httpsContainer.getServiceClient().getCredentials().getClass().toString()); httpsBlob = httpsContainer.getBlockBlobReference(this.blob.getName()); httpsBlob.download(new ByteArrayOutputStream());
noneContainer.getServiceClient().getCredentials().getClass().toString()); oneContainer.getServiceClient().getCredentials().getClass().toString()); allContainer.getServiceClient().getCredentials().getClass().toString());
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerUploadMetadata() throws StorageException, URISyntaxException { this.container.create(); CloudBlobContainer container2 = this.container.getServiceClient().getContainerReference( this.container.getName()); container2.downloadAttributes(); assertEquals(0, container2.getMetadata().size()); this.container.getMetadata().put("key1", "value1"); this.container.uploadMetadata(); container2.downloadAttributes(); assertEquals(1, container2.getMetadata().size()); assertEquals("value1", container2.getMetadata().get("key1")); Iterable<CloudBlobContainer> containers = this.container.getServiceClient().listContainers( this.container.getName(), ContainerListingDetails.METADATA, null, null); for (CloudBlobContainer container3 : containers) { assertEquals(1, container3.getMetadata().size()); assertEquals("value1", container3.getMetadata().get("key1")); } this.container.getMetadata().clear(); this.container.uploadMetadata(); container2.downloadAttributes(); assertEquals(0, container2.getMetadata().size()); }
private static void testContainerDownloadAttributes(LocationMode optionsLocationMode, LocationMode clientLocationMode, StorageLocation initialLocation, List<RetryContext> retryContextList, List<RetryInfo> retryInfoList) throws URISyntaxException, StorageException { CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); MultiLocationTestHelper helper = new MultiLocationTestHelper(container.getServiceClient().getStorageUri(), initialLocation, retryContextList, retryInfoList); container.getServiceClient().getDefaultRequestOptions().setLocationMode(clientLocationMode); BlobRequestOptions options = new BlobRequestOptions(); options.setLocationMode(optionsLocationMode); options.setRetryPolicyFactory(helper.retryPolicy); try { container.downloadAttributes(null, options, helper.operationContext); } catch (StorageException ex) { assertEquals(HttpURLConnection.HTTP_NOT_FOUND, ex.getHttpStatusCode()); } finally { helper.close(); } }
assertEquals(containerUri, container.getStorageUri()); assertEquals(containerUri.getPrimaryUri(), container.getUri()); assertEquals(endpoint, container.getServiceClient().getStorageUri()); assertEquals(endpoint, container.getServiceClient().getStorageUri());