From 66be278907e3f2e4b3b53feca43d7c7193d60ce6 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Wed, 10 Jul 2019 13:49:02 -0700 Subject: [PATCH 1/9] Removed raw clients --- .../storage/blob/AppendBlobAsyncClient.java | 47 +- .../blob/AppendBlobAsyncRawClient.java | 192 ----- .../azure/storage/blob/AppendBlobClient.java | 17 +- .../azure/storage/blob/BlobAsyncClient.java | 208 +++-- .../storage/blob/BlobAsyncRawClient.java | 766 ------------------ .../com/azure/storage/blob/BlobClient.java | 3 +- .../azure/storage/blob/BlobInputStream.java | 2 +- .../azure/storage/blob/BlobOutputStream.java | 4 +- .../com/azure/storage/blob/BlobURLParts.java | 8 +- .../storage/blob/BlockBlobAsyncClient.java | 50 +- .../storage/blob/BlockBlobAsyncRawClient.java | 364 --------- .../azure/storage/blob/BlockBlobClient.java | 14 +- .../storage/blob/ContainerAsyncClient.java | 290 +++++-- .../storage/blob/ContainerAsyncRawClient.java | 708 ---------------- .../azure/storage/blob/ContainerClient.java | 7 +- .../storage/blob/ContainerRawClient.java | 652 --------------- .../storage/blob/PageBlobAsyncClient.java | 210 +++-- .../storage/blob/PageBlobAsyncRawClient.java | 620 -------------- .../azure/storage/blob/PageBlobClient.java | 12 +- .../storage/blob/StorageAsyncClient.java | 84 +- .../storage/blob/StorageAsyncRawClient.java | 172 ---- .../com/azure/storage/blob/StorageClient.java | 3 +- .../azure/storage/blob/StorageRawClient.java | 259 ------ .../java/com/azure/storage/blob/Sample.java | 6 +- 24 files changed, 717 insertions(+), 3981 deletions(-) delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index 7b4585580e16f..60376a3d990ab 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -5,6 +5,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.AppendBlobAccessConditions; import com.azure.storage.blob.models.AppendBlobItem; @@ -13,12 +14,13 @@ import com.azure.storage.blob.models.BlobRange; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.Unpooled; +import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.net.URL; -import java.nio.ByteBuffer; + +import static com.azure.storage.blob.Utility.postProcessResponse; /** @@ -45,8 +47,6 @@ * object through {@link Mono#toFuture()}. */ public final class AppendBlobAsyncClient extends BlobAsyncClient { - final AppendBlobAsyncRawClient appendBlobAsyncRawClient; - /** * Indicates the maximum number of bytes that can be sent in a call to appendBlock. */ @@ -63,7 +63,6 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient { */ AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - appendBlobAsyncRawClient = new AppendBlobAsyncRawClient(azureBlobStorageBuilder.build()); } /** @@ -90,8 +89,13 @@ public Mono> create() { * A reactive response containing the information of the created appended blob. */ public Mono> create(BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return appendBlobAsyncRawClient - .create(headers, metadata, accessConditions) + metadata = (metadata == null) ? new Metadata() : metadata; + accessConditions = (accessConditions == null) ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.appendBlobs().createWithRestResponseAsync(null, + null, 0, null, metadata, null, null, + null, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } @@ -111,7 +115,7 @@ public Mono> create(BlobHTTPHeaders headers, Metadata m * @return * A reactive response containing the information of the append blob operation. */ - public Mono> appendBlock(Flux data, long length) { + public Mono> appendBlock(Flux data, long length) { return this.appendBlock(data, length, null); } @@ -133,10 +137,17 @@ public Mono> appendBlock(Flux data, long le * @return * A reactive response containing the information of the append blob operation. */ - public Mono> appendBlock(Flux data, long length, - AppendBlobAccessConditions appendBlobAccessConditions) { - return appendBlobAsyncRawClient - .appendBlock(data.map(Unpooled::wrappedBuffer), length, appendBlobAccessConditions) + public Mono> appendBlock(Flux data, long length, + AppendBlobAccessConditions appendBlobAccessConditions) { + appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() + : appendBlobAccessConditions; + + return postProcessResponse(this.azureBlobStorage.appendBlobs().appendBlockWithRestResponseAsync( + null, null, data, length, null, null, + null, null, null, null, + appendBlobAccessConditions.leaseAccessConditions(), + appendBlobAccessConditions.appendPositionAccessConditions(), + appendBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } @@ -183,8 +194,16 @@ public Mono> appendBlockFromUrl(URL sourceURL, BlobRang public Mono> appendBlockFromUrl(URL sourceURL, BlobRange sourceRange, byte[] sourceContentMD5, AppendBlobAccessConditions destAccessConditions, SourceModifiedAccessConditions sourceAccessConditions) { - return appendBlobAsyncRawClient - .appendBlockFromUrl(sourceURL, sourceRange, sourceContentMD5, destAccessConditions, sourceAccessConditions) + sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; + destAccessConditions = destAccessConditions == null + ? new AppendBlobAccessConditions() : destAccessConditions; + + return postProcessResponse( + this.azureBlobStorage.appendBlobs().appendBlockFromUrlWithRestResponseAsync(null, null, + sourceURL, 0, sourceRange.toString(), sourceContentMD5, null, null, + destAccessConditions.leaseAccessConditions(), + destAccessConditions.appendPositionAccessConditions(), + destAccessConditions.modifiedAccessConditions(), sourceAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java deleted file mode 100644 index 15bf8e09e4d1f..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.AppendBlobAccessConditions; -import com.azure.storage.blob.models.AppendBlobsAppendBlockFromUrlResponse; -import com.azure.storage.blob.models.AppendBlobsAppendBlockResponse; -import com.azure.storage.blob.models.AppendBlobsCreateResponse; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - - -/** - * Represents a URL to an append blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular append blob but is instead a - * convenient way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - */ -final class AppendBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the maximum number of bytes that can be sent in a call to appendBlock. - */ - public static final int MAX_APPEND_BLOCK_BYTES = 4 * Constants.MB; - - /** - * Indicates the maximum number of blocks allowed in an append blob. - */ - public static final int MAX_BLOCKS = 50000; - - /** - * Creates a {@code AppendBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - AppendBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - super(azureBlobStorage, null); - } - - /** - * Creates a 0-length append blob. Call AppendBlock to append data to an append blob. For more information, see - * the Azure Docs. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create() { - return this.create(null, null, null); - } - - /** - * Creates a 0-length append blob. Call AppendBlock to append data to an append blob. For more information, see - * the Azure Docs. - * - * @param headers {@link BlobHTTPHeaders} - * @param metadata {@link Metadata} - * @param accessConditions {@link BlobAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(BlobHTTPHeaders headers, Metadata metadata, - BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.appendBlobs().createWithRestResponseAsync(null, - null, 0, null, metadata, null, null, - null, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Commits a new block of data to the end of the existing append blob. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.appendBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlock(Flux data, long length) { - return this.appendBlock(data, length, null); - } - - /** - * Commits a new block of data to the end of the existing append blob. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param appendBlobAccessConditions {@link AppendBlobAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.appendBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlock(Flux data, long length, - AppendBlobAccessConditions appendBlobAccessConditions) { - appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() - : appendBlobAccessConditions; - - return postProcessResponse(this.azureBlobStorage.appendBlobs().appendBlockWithRestResponseAsync( - null, null, data, length, null, null, - null, null, null, null, - appendBlobAccessConditions.leaseAccessConditions(), - appendBlobAccessConditions.appendPositionAccessConditions(), - appendBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Commits a new block of data from another blob to the end of this append blob. For more information, see the - * Azure Docs. - *

- * - * @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange The source {@link BlobRange} to copy. - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobAsyncRawClient.appendBlockFromUrl")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlockFromUrl(URL sourceURL, BlobRange sourceRange) { - return this.appendBlockFromUrl(sourceURL, sourceRange, null, null, - null); - } - - /** - * Commits a new block of data from another blob to the end of this append blob. For more information, see the - * Azure Docs. - *

- * - * @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange {@link BlobRange} - * @param sourceContentMD5 An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param destAccessConditions {@link AppendBlobAccessConditions} - * @param sourceAccessConditions {@link SourceModifiedAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobAsyncRawClient.appendBlockFromUrl")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlockFromUrl(URL sourceURL, BlobRange sourceRange, - byte[] sourceContentMD5, AppendBlobAccessConditions destAccessConditions, - SourceModifiedAccessConditions sourceAccessConditions) { - - sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; - destAccessConditions = destAccessConditions == null - ? new AppendBlobAccessConditions() : destAccessConditions; - - return postProcessResponse( - this.azureBlobStorage.appendBlobs().appendBlockFromUrlWithRestResponseAsync(null, null, - sourceURL, 0, sourceRange.toString(), sourceContentMD5, null, null, - destAccessConditions.leaseAccessConditions(), - destAccessConditions.appendPositionAccessConditions(), - destAccessConditions.modifiedAccessConditions(), sourceAccessConditions, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java index 47a379649659f..6be2bf7f4e5aa 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java @@ -11,13 +11,14 @@ import com.azure.storage.blob.models.BlobRange; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import java.io.InputStream; import java.net.URL; -import java.nio.ByteBuffer; import java.time.Duration; @@ -37,18 +38,17 @@ * for more information. */ public final class AppendBlobClient extends BlobClient { - - AppendBlobAsyncClient appendBlobAsyncClient; + private AppendBlobAsyncClient appendBlobAsyncClient; /** * Indicates the maximum number of bytes that can be sent in a call to appendBlock. */ - public static final int MAX_APPEND_BLOCK_BYTES = 4 * Constants.MB; + public static final int MAX_APPEND_BLOCK_BYTES = AppendBlobAsyncClient.MAX_APPEND_BLOCK_BYTES; /** * Indicates the maximum number of blocks allowed in an append blob. */ - public static final int MAX_BLOCKS = 50000; + public static final int MAX_BLOCKS = AppendBlobAsyncClient.MAX_BLOCKS; /** * Package-private constructor for use by {@link AppendBlobClientBuilder}. @@ -58,7 +58,7 @@ public final class AppendBlobClient extends BlobClient { super(appendBlobAsyncClient); this.appendBlobAsyncClient = appendBlobAsyncClient; } - + /** * Creates and opens an output stream to write data to the append blob. If the blob already exists on the service, * it will be overwritten. @@ -160,7 +160,7 @@ public Response appendBlock(InputStream data, long length) { */ public Response appendBlock(InputStream data, long length, AppendBlobAccessConditions appendBlobAccessConditions, Duration timeout) { - Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) MAX_APPEND_BLOCK_BYTES)) + Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) MAX_APPEND_BLOCK_BYTES)) .map(i -> i * MAX_APPEND_BLOCK_BYTES) .concatMap(pos -> Mono.fromCallable(() -> { long count = pos + MAX_APPEND_BLOCK_BYTES > length ? length - pos : MAX_APPEND_BLOCK_BYTES; @@ -169,7 +169,8 @@ public Response appendBlock(InputStream data, long length, while (read < count) { read += data.read(cache, read, (int) count - read); } - return ByteBuffer.wrap(cache); + + return ByteBufAllocator.DEFAULT.buffer((int) count).writeBytes(cache); })); Mono> response = appendBlobAsyncClient.appendBlock(fbb.subscribeOn(Schedulers.elastic()), length, appendBlobAccessConditions); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index 7ec72ecf30b53..fa4a0e77edac5 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -9,7 +9,9 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.http.UrlBuilder; import com.azure.core.implementation.util.FluxUtil; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -20,6 +22,7 @@ import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.ModifiedAccessConditions; import com.azure.storage.blob.models.ReliableDownloadOptions; +import com.azure.storage.blob.models.SourceModifiedAccessConditions; import com.azure.storage.blob.models.StorageAccountInfo; import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; @@ -38,6 +41,8 @@ import java.util.ArrayList; import java.util.List; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} or via * the method {@link ContainerAsyncClient#getBlobAsyncClient(String)}. This class does not hold any state about a particular @@ -68,14 +73,16 @@ public class BlobAsyncClient { private static final int BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB; private static final int BLOB_MAX_DOWNLOAD_BLOCK_SIZE = 100 * Constants.MB; - final BlobAsyncRawClient blobAsyncRawClient; + protected final AzureBlobStorageImpl azureBlobStorage; + protected final String snapshot; /** * Package-private constructor for use by {@link BlobClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - this.blobAsyncRawClient = new BlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); + this.azureBlobStorage = azureBlobStorageBuilder.build(); + this.snapshot = snapshot; } /** @@ -86,7 +93,9 @@ public class BlobAsyncClient { * A {@link BlockBlobAsyncClient} to this resource. */ public BlockBlobAsyncClient asBlockBlobAsyncClient() { - return new BlockBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -97,7 +106,9 @@ public BlockBlobAsyncClient asBlockBlobAsyncClient() { * A {@link AppendBlobAsyncClient} to this resource. */ public AppendBlobAsyncClient asAppendBlobAsyncClient() { - return new AppendBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -108,7 +119,9 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() { * A {@link PageBlobAsyncClient} to this resource. */ public PageBlobAsyncClient asPageBlobAsyncClient() { - return new PageBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new PageBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -122,7 +135,7 @@ public ContainerAsyncClient getContainerAsyncClient() { BlobURLParts parts = URLParser.parse(getBlobUrl()); return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s://%s/%s", parts.scheme(), parts.host(), parts.containerName())) - .pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** @@ -132,13 +145,13 @@ public ContainerAsyncClient getContainerAsyncClient() { */ public URL getBlobUrl() { try { - UrlBuilder urlBuilder = UrlBuilder.parse(blobAsyncRawClient.azureBlobStorage.url()); - if (blobAsyncRawClient.snapshot != null) { - urlBuilder.query("snapshot=" + blobAsyncRawClient.snapshot); + UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.url()); + if (snapshot != null) { + urlBuilder.query("snapshot=" + snapshot); } return urlBuilder.toURL(); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), blobAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } @@ -192,8 +205,21 @@ public Mono> startCopyFromURL(URL sourceURL) { */ public Mono> startCopyFromURL(URL sourceURL, Metadata metadata, ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - return blobAsyncRawClient - .startCopyFromURL(sourceURL, metadata, sourceModifiedAccessConditions, destAccessConditions) + metadata = metadata == null ? new Metadata() : metadata; + sourceModifiedAccessConditions = sourceModifiedAccessConditions == null + ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; + destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; + + // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. + SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() + .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) + .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) + .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) + .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); + + return postProcessResponse(this.azureBlobStorage.blobs().startCopyFromURLWithRestResponseAsync( + null, null, sourceURL, null, metadata, null, sourceConditions, + destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyId())); } @@ -225,8 +251,8 @@ public Mono abortCopyFromURL(String copyId) { * A reactive response signalling completion. */ public Mono abortCopyFromURL(String copyId, LeaseAccessConditions leaseAccessConditions) { - return blobAsyncRawClient - .abortCopyFromURL(copyId, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().abortCopyFromURLWithRestResponseAsync( + null, null, copyId, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -263,8 +289,21 @@ public Mono> copyFromURL(URL copySource) { */ public Mono> copyFromURL(URL copySource, Metadata metadata, ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - return blobAsyncRawClient - .syncCopyFromURL(copySource, metadata, sourceModifiedAccessConditions, destAccessConditions) + metadata = metadata == null ? new Metadata() : metadata; + sourceModifiedAccessConditions = sourceModifiedAccessConditions == null + ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; + destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; + + // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. + SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() + .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) + .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) + .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) + .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); + + return postProcessResponse(this.azureBlobStorage.blobs().copyFromURLWithRestResponseAsync( + null, null, copySource, null, metadata, null, sourceConditions, + destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyId())); } @@ -293,13 +332,60 @@ public Mono>> download() { */ public Mono>> download(BlobRange range, BlobAccessConditions accessConditions, boolean rangeGetContentMD5, ReliableDownloadOptions options) { - return blobAsyncRawClient - .download(range, accessConditions, rangeGetContentMD5) + return this.download(range, accessConditions, rangeGetContentMD5) .map(response -> new SimpleResponse<>( response.rawResponse(), response.body(options).map(ByteBuf::nioBuffer).switchIfEmpty(Flux.just(ByteBuffer.allocate(0))))); } + /** + * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more + * information, see the Azure Docs. + *

+ * Note that the response body has reliable download functionality built in, meaning that a failed download stream + * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. + * + * @param range + * {@link BlobRange} + * @param accessConditions + * {@link BlobAccessConditions} + * @param rangeGetContentMD5 + * Whether the contentMD5 for the specified blob range should be returned. + * + * @return Emits the successful response. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlobAsyncClient.download")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + */ + Mono download(BlobRange range, BlobAccessConditions accessConditions, boolean rangeGetContentMD5) { + range = range == null ? new BlobRange(0) : range; + Boolean getMD5 = rangeGetContentMD5 ? rangeGetContentMD5 : null; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + HTTPGetterInfo info = new HTTPGetterInfo() + .offset(range.offset()) + .count(range.count()) + .eTag(accessConditions.modifiedAccessConditions().ifMatch()); + + // TODO: range is BlobRange but expected as String + // TODO: figure out correct response + return postProcessResponse(this.azureBlobStorage.blobs().downloadWithRestResponseAsync( + null, null, snapshot, null, null, range.toHeaderValue(), getMD5, + null, null, null, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) + // Convert the autorest response to a DownloadAsyncResponse, which enable reliable download. + .map(response -> { + // If there wasn't an etag originally specified, lock on the one returned. + info.eTag(response.deserializedHeaders().eTag()); + return new DownloadAsyncResponse(response, info, + // In the event of a stream failure, make a new request to pick up where we left off. + newInfo -> + this.download(new BlobRange(newInfo.offset(), newInfo.count()), + new BlobAccessConditions().modifiedAccessConditions( + new ModifiedAccessConditions().ifMatch(info.eTag())), false)); + }); + } + /** * Downloads the entire blob into a file specified by the path. The file will be created if it doesn't exist. * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. @@ -346,8 +432,7 @@ public Mono downloadToFile(String filePath, BlobRange range, Integer block channel -> Mono.justOrEmpty(range) .switchIfEmpty(getFullBlobRange(accessConditions)) .flatMapMany(rg -> Flux.fromIterable(sliceBlobRange(rg, blockSize))) - .flatMap(chunk -> blobAsyncRawClient - .download(chunk, accessConditions, rangeGetContentMD5) + .flatMap(chunk -> this.download(chunk, accessConditions, rangeGetContentMD5) .subscribeOn(Schedulers.elastic()) .flatMap(dar -> FluxUtil.bytebufStreamToFile(dar.body(options), channel, chunk.offset() - (range == null ? 0 : range.offset())))) .then(), this::downloadToFileCleanup); @@ -415,8 +500,12 @@ public Mono delete() { */ public Mono delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .delete(deleteBlobSnapshotOptions, accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().deleteWithRestResponseAsync( + null, null, snapshot, null, null, deleteBlobSnapshotOptions, + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .map(VoidResponse::new); } @@ -440,8 +529,12 @@ public Mono> getProperties() { * A reactive response containing the blob properties and metadata. */ public Mono> getProperties(BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .getProperties(accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().getPropertiesWithRestResponseAsync( + null, null, snapshot, null, null, null, + null, null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlobProperties(rb.deserializedHeaders()))); } @@ -476,8 +569,11 @@ public Mono setHTTPHeaders(BlobHTTPHeaders headers) { * A reactive response signalling completion. */ public Mono setHTTPHeaders(BlobHTTPHeaders headers, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .setHTTPHeaders(headers, accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().setHTTPHeadersWithRestResponseAsync( + null, null, null, null, headers, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -510,8 +606,13 @@ public Mono setMetadata(Metadata metadata) { * A reactive response signalling completion. */ public Mono setMetadata(Metadata metadata, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .setMetadata(metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().setMetadataWithRestResponseAsync( + null, null, null, metadata, null, null, + null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -537,8 +638,13 @@ public Mono> createSnapshot() { * A reactive response containing the ID of the new snapshot. */ public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .createSnapshot(metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().createSnapshotWithRestResponseAsync( + null, null, null, metadata, null, null, + null, null, accessConditions.modifiedAccessConditions(), + accessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().snapshot())); } @@ -572,8 +678,10 @@ public Mono setTier(AccessTier tier) { * A reactive response signalling completion. */ public Mono setTier(AccessTier tier, LeaseAccessConditions leaseAccessConditions) { - return blobAsyncRawClient - .setTier(tier, leaseAccessConditions) + Utility.assertNotNull("tier", tier); + + return postProcessResponse(this.azureBlobStorage.blobs().setTierWithRestResponseAsync( + null, null, tier, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -584,8 +692,8 @@ public Mono setTier(AccessTier tier, LeaseAccessConditions leaseAc * A reactive response signalling completion. */ public Mono undelete() { - return blobAsyncRawClient - .undelete() + return postProcessResponse(this.azureBlobStorage.blobs().undeleteWithRestResponseAsync(null, + null, Context.NONE)) .map(VoidResponse::new); } @@ -622,10 +730,18 @@ public Mono> acquireLease(String proposedId, int duration) { * * @return * A reactive response containing the lease ID. + * @throws IllegalArgumentException If {@code duration} is outside the bounds of 15 to 60 or isn't -1. */ public Mono> acquireLease(String proposedID, int duration, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .acquireLease(proposedID, duration, modifiedAccessConditions) + if (!(duration == -1 || (duration >= 15 && duration <= 60))) { + // Throwing is preferred to Mono.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("Duration must be -1 or between 15 and 60."); + } + + return postProcessResponse(this.azureBlobStorage.blobs().acquireLeaseWithRestResponseAsync( + null, null, null, duration, proposedID, null, + modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -656,8 +772,8 @@ public Mono> renewLease(String leaseID) { * A reactive response containing the renewed lease ID. */ public Mono> renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .renewLease(leaseID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().renewLeaseWithRestResponseAsync(null, + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -688,8 +804,8 @@ public Mono releaseLease(String leaseID) { * A reactive response signalling completion. */ public Mono releaseLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .releaseLease(leaseID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().releaseLeaseWithRestResponseAsync(null, + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -723,8 +839,8 @@ public Mono> breakLease() { * A reactive response containing the remaining time in the broken lease in seconds. */ public Mono> breakLease(Integer breakPeriodInSeconds, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .breakLease(breakPeriodInSeconds, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().breakLeaseWithRestResponseAsync(null, + null, null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseTime())); } @@ -758,8 +874,8 @@ public Mono> changeLease(String leaseId, String proposedID) { * @return A reactive response containing the new lease ID. */ public Mono> changeLease(String leaseId, String proposedID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .changeLease(leaseId, proposedID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().changeLeaseWithRestResponseAsync(null, + null, leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -770,8 +886,8 @@ public Mono> changeLease(String leaseId, String proposedID, Mod */ // TODO (unknown): determine this return type public Mono> getAccountInfo() { - return blobAsyncRawClient - .getAccountInfo() + return postProcessResponse( + this.azureBlobStorage.blobs().getAccountInfoWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java deleted file mode 100644 index 002ba761a3bf8..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java +++ /dev/null @@ -1,766 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.AccessTier; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.BlobStartCopyFromURLHeaders; -import com.azure.storage.blob.models.BlobsAbortCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsAcquireLeaseResponse; -import com.azure.storage.blob.models.BlobsBreakLeaseResponse; -import com.azure.storage.blob.models.BlobsChangeLeaseResponse; -import com.azure.storage.blob.models.BlobsCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsCreateSnapshotResponse; -import com.azure.storage.blob.models.BlobsDeleteResponse; -import com.azure.storage.blob.models.BlobsGetAccountInfoResponse; -import com.azure.storage.blob.models.BlobsGetPropertiesResponse; -import com.azure.storage.blob.models.BlobsReleaseLeaseResponse; -import com.azure.storage.blob.models.BlobsRenewLeaseResponse; -import com.azure.storage.blob.models.BlobsSetHTTPHeadersResponse; -import com.azure.storage.blob.models.BlobsSetMetadataResponse; -import com.azure.storage.blob.models.BlobsSetTierResponse; -import com.azure.storage.blob.models.BlobsStartCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsUndeleteResponse; -import com.azure.storage.blob.models.DeleteSnapshotsOptionType; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.ReliableDownloadOptions; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import reactor.core.publisher.Mono; - -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a blob of any type: block, append, or page. It may be obtained by direct construction or via the - * create method on a {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is - * instead a convenient way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs for more information. - */ -class BlobAsyncRawClient { - - protected AzureBlobStorageImpl azureBlobStorage; - - final String snapshot; - - /** - * Creates a {@code BlobAsyncRawClient} object pointing to the account specified by the URL and using the provided pipeline to - * make HTTP requests.. - */ - BlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - this.azureBlobStorage = azureBlobStorage; - this.snapshot = snapshot; - } - - /** - * Copies the data at the source URL to a blob. For more information, see the Azure Docs - * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy "Sample code for BlobAsyncRawClient.startCopyFromURL")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy_helper "Helper for start_copy sample.")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono startCopyFromURL(URL sourceURL) { - return this.startCopyFromURL(sourceURL, null, null, null); - } - - /** - * Copies the data at the source URL to a blob. For more information, see the Azure Docs - * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy "Sample code for BlobAsyncRawClient.startCopyFromURL")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy_helper "Helper for start_copy sample.")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono startCopyFromURL(URL sourceURL, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - sourceModifiedAccessConditions = sourceModifiedAccessConditions == null - ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; - destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; - - // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. - SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() - .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) - .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) - .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) - .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); - - return postProcessResponse(this.azureBlobStorage.blobs().startCopyFromURLWithRestResponseAsync( - null, null, sourceURL, null, metadata, null, sourceConditions, - destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For - * more information, see the Azure Docs. - * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=abort_copy "Sample code for BlobAsyncRawClient.abortCopyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono abortCopyFromURL(String copyId) { - return this.abortCopyFromURL(copyId, null); - } - - /** - * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For - * more information, see the Azure Docs. - * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=abort_copy "Sample code for BlobAsyncRawClient.abortCopyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono abortCopyFromURL(String copyId, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().abortCopyFromURLWithRestResponseAsync( - null, null, copyId, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. - * For more information, see the Azure Docs - * - * @param copySource - * The source URL to copy from. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=sync_copy "Sample code for BlobAsyncRawClient.copyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono syncCopyFromURL(URL copySource) { - return this.syncCopyFromURL(copySource, null, null, null); - } - - /** - * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. - * For more information, see the Azure Docs - * - * @param copySource - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=sync_copy "Sample code for BlobAsyncRawClient.copyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono syncCopyFromURL(URL copySource, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - sourceModifiedAccessConditions = sourceModifiedAccessConditions == null - ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; - destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; - - // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. - SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() - .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) - .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) - .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) - .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); - - return postProcessResponse(this.azureBlobStorage.blobs().copyFromURLWithRestResponseAsync( - null, null, copySource, null, metadata, null, sourceConditions, - destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more - * information, see the Azure Docs. - *

- * Note that the response body has reliable download functionality built in, meaning that a failed download stream - * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download - * "Sample code for BlobAsyncRawClient.download")] \n For more samples, please see the [Samples - * file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono download() { - return this.download(null, null, false); - } - - /** - * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more - * information, see the Azure Docs. - *

- * Note that the response body has reliable download functionality built in, meaning that a failed download stream - * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. - * - * @param range - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlobAsyncRawClient.download")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono download(BlobRange range, BlobAccessConditions accessConditions, - boolean rangeGetContentMD5) { - range = range == null ? new BlobRange(0) : range; - Boolean getMD5 = rangeGetContentMD5 ? rangeGetContentMD5 : null; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - HTTPGetterInfo info = new HTTPGetterInfo() - .offset(range.offset()) - .count(range.count()) - .eTag(accessConditions.modifiedAccessConditions().ifMatch()); - - // TODO: range is BlobRange but expected as String - // TODO: figure out correct response - return postProcessResponse(this.azureBlobStorage.blobs().downloadWithRestResponseAsync( - null, null, snapshot, null, null, range.toHeaderValue(), getMD5, - null, null, null, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) - // Convert the autorest response to a DownloadAsyncResponse, which enable reliable download. - .map(response -> { - // If there wasn't an etag originally specified, lock on the one returned. - info.eTag(response.deserializedHeaders().eTag()); - return new DownloadAsyncResponse(response, info, - // In the event of a stream failure, make a new request to pick up where we left off. - newInfo -> - this.download(new BlobRange(newInfo.offset(), newInfo.count()), - new BlobAccessConditions().modifiedAccessConditions( - new ModifiedAccessConditions().ifMatch(info.eTag())), false)); - }); - } - - /** - * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. For more - * information, see the Azure Docs. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_delete - * "Sample code for BlobAsyncRawClient.delete")] \n For more samples, please see the [Samples - * file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete() { - return this.delete(null, null); - } - - /** - * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. For more - * information, see the Azure Docs. - * - * @param deleteBlobSnapshotOptions - * Specifies the behavior for deleting the snapshots on this blob. {@code Include} will delete the base blob - * and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being deleted, you must - * pass null. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_delete "Sample code for BlobAsyncRawClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, - BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().deleteWithRestResponseAsync( - null, null, snapshot, null, null, deleteBlobSnapshotOptions, - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - } - - /** - * Returns the blob's metadata and properties. For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return this.getProperties(null); - } - - /** - * Returns the blob's metadata and properties. For more information, see the Azure Docs. - * - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties(BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().getPropertiesWithRestResponseAsync( - null, null, snapshot, null, null, null, - null, null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Changes a blob's HTTP header properties. For more information, see the Azure - * Docs. - * - * @param headers - * {@link BlobHTTPHeaders} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setHTTPHeaders")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setHTTPHeaders(BlobHTTPHeaders headers) { - return this.setHTTPHeaders(headers, null); - } - - /** - * Changes a blob's HTTP header properties. For more information, see the Azure Docs. - * - * @param headers - * {@link BlobHTTPHeaders} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setHTTPHeaders")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setHTTPHeaders(BlobHTTPHeaders headers, - BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().setHTTPHeadersWithRestResponseAsync( - null, null, null, null, headers, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Changes a blob's metadata. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null); - } - - /** - * Changes a blob's metadata. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().setMetadataWithRestResponseAsync( - null, null, null, metadata, null, null, - null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Creates a read-only snapshot of a blob. For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=snapshot "Sample code for BlobAsyncRawClient.createSnapshot")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono createSnapshot() { - return this.createSnapshot(null, null); - } - - /** - * Creates a read-only snapshot of a blob. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=snapshot "Sample code for BlobAsyncRawClient.createSnapshot")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().createSnapshotWithRestResponseAsync( - null, null, null, metadata, null, null, - null, null, accessConditions.modifiedAccessConditions(), - accessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in - * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - *

- * For detailed information about block blob level tiering see the Azure Docs. - * - * @param tier - * The new tier for the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=tier "Sample code for BlobAsyncRawClient.setTier")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setTier(AccessTier tier) { - return this.setTier(tier, null); - } - - /** - * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in - * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - *

- * For detailed information about block blob level tiering see the Azure Docs. - * - * @param tier - * The new tier for the blob. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=tier "Sample code for BlobAsyncRawClient.setTier")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setTier(AccessTier tier, LeaseAccessConditions leaseAccessConditions) { - Utility.assertNotNull("tier", tier); - - return postProcessResponse(this.azureBlobStorage.blobs().setTierWithRestResponseAsync( - null, null, tier, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots. - * For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=undelete "Sample code for BlobAsyncRawClient.undelete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono undelete() { - return postProcessResponse(this.azureBlobStorage.blobs().undeleteWithRestResponseAsync(null, - null, Context.NONE)); - } - - /** - * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 - * seconds, or infinite (-1). For more information, see the Azure Docs. - * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null); - } - - /** - * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 - * seconds, or infinite (-1). For more information, see the Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code duration} is outside the bounds of 15 to 60 or isn't -1. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions) { - if (!(duration == -1 || (duration >= 15 && duration <= 60))) { - // Throwing is preferred to Mono.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("Duration must be -1 or between 15 and 60."); - } - - return postProcessResponse(this.azureBlobStorage.blobs().acquireLeaseWithRestResponseAsync( - null, null, null, duration, proposedID, null, - modifiedAccessConditions, Context.NONE)); - } - - /** - * Renews the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID) { - return this.renewLease(leaseID, null); - } - - /** - * Renews the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().renewLeaseWithRestResponseAsync(null, - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Releases the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID) { - return this.releaseLease(leaseID, null); - } - - /** - * Releases the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().releaseLeaseWithRestResponseAsync(null, - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant - * to break a fixed-duration lease when it expires or an infinite lease immediately. For more information, see the - * Azure Docs. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return - * Emits the successful response. - */ - public Mono breakLease() { - return this.breakLease(null, null); - } - - /** - * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant - * to break a fixed-duration lease when it expires or an infinite lease immediately. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().breakLeaseWithRestResponseAsync(null, - null, null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseId, String proposedID) { - return this.changeLease(leaseId, proposedID, null); - } - - /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseId, String proposedID, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().changeLeaseWithRestResponseAsync(null, - null, leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for BlobAsyncRawClient.getAccountInfo")] \n - * For more samples, please see the [Samples file](https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.blobs().getAccountInfoWithRestResponseAsync(null, null, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java index f47c3cf6d7830..106b84729a39d 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java @@ -44,7 +44,6 @@ * for more information. */ public class BlobClient { - private static final int BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB; private final BlobAsyncClient blobAsyncClient; /** @@ -339,7 +338,7 @@ public VoidResponse download(OutputStream stream, ReliableDownloadOptions option * @throws IOException If an I/O error occurs */ public void downloadToFile(String filePath) throws IOException { - this.downloadToFile(filePath, null, null, BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE, null, false, null); + blobAsyncClient.downloadToFile(filePath); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java index 2e093f50738f2..1a990e179688b 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java @@ -189,7 +189,7 @@ public synchronized void close() throws IOException { */ private synchronized void dispatchRead(final int readLength) throws IOException { try { - this.currentBuffer = this.blobClient.blobAsyncRawClient.download(new BlobRange(this.currentAbsoluteReadPosition, (long) readLength), this.accessCondition, false) + this.currentBuffer = this.blobClient.download(new BlobRange(this.currentAbsoluteReadPosition, (long) readLength), this.accessCondition, false) .flatMap(res -> ByteBufFlux.fromInbound(res.body(null)).aggregate().asByteBuffer()) .block(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java index 176fe06c321d1..c733a580f2500 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java @@ -295,7 +295,7 @@ private Mono writePages(Flux pageData, long offset, long writeLen PageBlobAccessConditions pageBlobAccessConditions = accessCondition == null ? null : new PageBlobAccessConditions().leaseAccessConditions(accessCondition.leaseAccessConditions()).modifiedAccessConditions(accessCondition.modifiedAccessConditions()); - return blobRef.pageBlobAsyncRawClient.uploadPages(new PageRange().start(offset).end(offset + writeLength - 1), pageData, pageBlobAccessConditions) + return blobRef.uploadPages(new PageRange().start(offset).end(offset + writeLength - 1), pageData, pageBlobAccessConditions) .then() .onErrorResume(t -> t instanceof StorageException, e -> { this.lastError = new IOException(e); @@ -312,7 +312,7 @@ private Mono appendBlock(Flux blockData, long offset, long writeL this.appendPositionAccessConditions.appendPosition(offset); AppendBlobAccessConditions appendBlobAccessConditions = accessCondition == null ? null : new AppendBlobAccessConditions().leaseAccessConditions(accessCondition.leaseAccessConditions()).modifiedAccessConditions(accessCondition.modifiedAccessConditions()); - return blobRef.appendBlobAsyncRawClient.appendBlock(blockData, writeLength, appendBlobAccessConditions) + return blobRef.appendBlock(blockData, writeLength, appendBlobAccessConditions) .then() .onErrorResume(t -> t instanceof IOException || t instanceof StorageException, e -> { this.lastError = new IOException(e); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java index 473d998c446b2..1200e960f7501 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java @@ -76,14 +76,14 @@ public BlobURLParts host(String host) { } /** - * The container name or {@code null} if a {@link StorageAsyncRawClient} was parsed. + * The container name or {@code null} if a {@link StorageAsyncClient} was parsed. */ public String containerName() { return containerName; } /** - * The container name or {@code null} if a {@link StorageAsyncRawClient} was parsed. + * The container name or {@code null} if a {@link StorageAsyncClient} was parsed. */ public BlobURLParts containerName(String containerName) { this.containerName = containerName; @@ -91,14 +91,14 @@ public BlobURLParts containerName(String containerName) { } /** - * The blob name or {@code null} if a {@link StorageAsyncRawClient} or {@link ContainerAsyncClient} was parsed. + * The blob name or {@code null} if a {@link StorageAsyncClient} or {@link ContainerAsyncClient} was parsed. */ public String blobName() { return blobName; } /** - * The blob name or {@code null} if a {@link StorageAsyncRawClient} or {@link ContainerAsyncClient} was parsed. + * The blob name or {@code null} if a {@link StorageAsyncClient} or {@link ContainerAsyncClient} was parsed. */ public BlobURLParts blobName(String blobName) { this.blobName = blobName; diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java index ada7a125d4ef1..e7d8aa9b0c03d 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java @@ -8,6 +8,7 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.util.FluxUtil; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -15,11 +16,11 @@ import com.azure.storage.blob.models.BlockBlobItem; import com.azure.storage.blob.models.BlockItem; import com.azure.storage.blob.models.BlockListType; +import com.azure.storage.blob.models.BlockLookupList; import com.azure.storage.blob.models.LeaseAccessConditions; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -27,7 +28,6 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; -import java.nio.ByteBuffer; import java.nio.channels.AsynchronousFileChannel; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; @@ -39,6 +39,8 @@ import java.util.TreeMap; import java.util.UUID; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** * Client to a block blob. It may only be instantiated through a {@link BlockBlobClientBuilder}, via * the method {@link BlobAsyncClient#asBlockBlobAsyncClient()}, or via the method @@ -66,8 +68,6 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = 4 * Constants.MB; static final int BLOB_MAX_UPLOAD_BLOCK_SIZE = 100 * Constants.MB; - final BlockBlobAsyncRawClient blockBlobAsyncRawClient; - /** * Indicates the maximum number of bytes that can be sent in a call to upload. */ @@ -89,7 +89,6 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { */ BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - this.blockBlobAsyncRawClient = new BlockBlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); } /** @@ -114,7 +113,7 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { * @return * A reactive response containing the information of the uploaded block blob. */ - public Mono> upload(Flux data, long length) { + public Mono> upload(Flux data, long length) { return this.upload(data, length, null, null, null); } @@ -146,10 +145,15 @@ public Mono> upload(Flux data, long length) * @return * A reactive response containing the information of the uploaded block blob. */ - public Mono> upload(Flux data, long length, BlobHTTPHeaders headers, + public Mono> upload(Flux data, long length, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return blockBlobAsyncRawClient - .upload(data.map(Unpooled::wrappedBuffer), length, headers, metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blockBlobs().uploadWithRestResponseAsync(null, + null, data, length, null, metadata, null, null, + null, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); } @@ -291,8 +295,9 @@ public Mono stageBlock(String base64BlockID, Flux data, */ public Mono stageBlock(String base64BlockID, Flux data, long length, LeaseAccessConditions leaseAccessConditions) { - return blockBlobAsyncRawClient - .stageBlock(base64BlockID, data, length, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blockBlobs().stageBlockWithRestResponseAsync(null, + null, base64BlockID, length, data, null, null, null, + null, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -349,8 +354,13 @@ public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions, SourceModifiedAccessConditions sourceModifiedAccessConditions) { - return blockBlobAsyncRawClient - .stageBlockFromURL(base64BlockID, sourceURL, sourceRange, sourceContentMD5, leaseAccessConditions, sourceModifiedAccessConditions) + sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; + + return postProcessResponse( + this.azureBlobStorage.blockBlobs().stageBlockFromURLWithRestResponseAsync(null, null, + base64BlockID, 0, sourceURL, sourceRange.toHeaderValue(), sourceContentMD5, null, + null, null, null, null, + leaseAccessConditions, sourceModifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -386,8 +396,9 @@ public Flux listBlocks(BlockListType listType) { */ public Flux listBlocks(BlockListType listType, LeaseAccessConditions leaseAccessConditions) { - return blockBlobAsyncRawClient - .listBlocks(listType, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync( + null, null, listType, snapshot, null, null, null, + leaseAccessConditions, Context.NONE)) .map(ResponseBase::value) .flatMapMany(bl -> { Flux committed = Flux.fromIterable(bl.committedBlocks()) @@ -440,8 +451,13 @@ public Mono> commitBlockList(List base64BlockIDs */ public Mono> commitBlockList(List base64BlockIDs, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return blockBlobAsyncRawClient - .commitBlockList(base64BlockIDs, headers, metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blockBlobs().commitBlockListWithRestResponseAsync( + null, null, new BlockLookupList().latest(base64BlockIDs), null, metadata, + null, null, null, null, headers, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java deleted file mode 100644 index 03b7e650167b6..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java +++ /dev/null @@ -1,364 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.BlockBlobsCommitBlockListResponse; -import com.azure.storage.blob.models.BlockBlobsGetBlockListResponse; -import com.azure.storage.blob.models.BlockBlobsStageBlockFromURLResponse; -import com.azure.storage.blob.models.BlockBlobsStageBlockResponse; -import com.azure.storage.blob.models.BlockBlobsUploadResponse; -import com.azure.storage.blob.models.BlockListType; -import com.azure.storage.blob.models.BlockLookupList; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.URL; -import java.util.List; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a block blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is instead a convenient - * way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - * for more information on block blobs. - */ -final class BlockBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the maximum number of bytes that can be sent in a call to upload. - */ - public static final int MAX_UPLOAD_BLOB_BYTES = 256 * Constants.MB; - - /** - * Indicates the maximum number of bytes that can be sent in a call to stageBlock. - */ - public static final int MAX_STAGE_BLOCK_BYTES = 100 * Constants.MB; - - /** - * Indicates the maximum number of blocks allowed in a block blob. - */ - public static final int MAX_BLOCKS = 50000; - - /** - * Creates a {@code BlockBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - */ - BlockBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - super(azureBlobStorage, snapshot); - } - - - /** - * Creates a new block blob, or updates the content of an existing block blob. - * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not - * supported with PutBlob; the content of the existing blob is overwritten with the new content. To - * perform a partial update of a block blob's, use PutBlock and PutBlockList. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - *

- * - * @param data - * The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobAsyncRawClient.upload")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono upload(Flux data, long length) { - return this.upload(data, length, null, null, null); - } - - /** - * Creates a new block blob, or updates the content of an existing block blob. - * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not - * supported with PutBlob; the content of the existing blob is overwritten with the new content. To - * perform a partial update of a block blob's, use PutBlock and PutBlockList. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - *

- * - * @param data - * The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobAsyncRawClient.upload")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono upload(Flux data, long length, BlobHTTPHeaders headers, - Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blockBlobs().uploadWithRestResponseAsync(null, - null, data, length, null, metadata, null, null, - null, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Uploads the specified block to the block blob's "staging area" to be later committed by a call to - * commitBlockList. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param data - * The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.stageBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlock(String base64BlockID, Flux data, - long length) { - return this.stageBlock(base64BlockID, data, length, null); - } - - /** - * Uploads the specified block to the block blob's "staging area" to be later committed by a call to - * commitBlockList. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param data - * The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.stageBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlock(String base64BlockID, Flux data, long length, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blockBlobs().stageBlockWithRestResponseAsync(null, - null, base64BlockID, length, data, null, null, null, - null, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more - * information, see the Azure Docs. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceRange - * {@link BlobRange} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobAsyncRawClient.stageBlockFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, - BlobRange sourceRange) { - return this.stageBlockFromURL(base64BlockID, sourceURL, sourceRange, null, - null, null); - } - - /** - * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more - * information, see the Azure Docs. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange - * {@link BlobRange} - * @param sourceContentMD5 - * An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param sourceModifiedAccessConditions - * {@link SourceModifiedAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobAsyncRawClient.stageBlockFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, - BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions, - SourceModifiedAccessConditions sourceModifiedAccessConditions) { - sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; - - return postProcessResponse( - this.azureBlobStorage.blockBlobs().stageBlockFromURLWithRestResponseAsync(null, null, - base64BlockID, 0, sourceURL, sourceRange.toHeaderValue(), sourceContentMD5, null, - null, null, null, null, - leaseAccessConditions, sourceModifiedAccessConditions, Context.NONE)); - } - - /** - * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. - * For more information, see the - * Azure Docs. - * - * @param listType - * Specifies which type of blocks to return. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlocks(BlockListType listType) { - return this.listBlocks(listType, null); - } - - /** - * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. - * For more information, see the - * Azure Docs. - * - * @param listType - * Specifies which type of blocks to return. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlocks(BlockListType listType, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync( - null, null, listType, snapshot, null, null, null, - leaseAccessConditions, Context.NONE)); - } - - /** - * Writes a blob by specifying the list of block IDs that are to make up the blob. - * In order to be written as part of a blob, a block must have been successfully written - * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob - * by uploading only those blocks that have changed, then committing the new and existing - * blocks together. Any blocks not specified in the block list and permanently deleted. - * For more information, see the - * Azure Docs. - *

- * - * @param base64BlockIDs - * A list of base64 encode {@code String}s that specifies the block IDs to be committed. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.commitBlockList")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono commitBlockList(List base64BlockIDs) { - return this.commitBlockList(base64BlockIDs, null, null, null); - } - - /** - * Writes a blob by specifying the list of block IDs that are to make up the blob. - * In order to be written as part of a blob, a block must have been successfully written - * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob - * by uploading only those blocks that have changed, then committing the new and existing - * blocks together. Any blocks not specified in the block list and permanently deleted. - * For more information, see the - * Azure Docs. - *

- * - * @param base64BlockIDs - * A list of base64 encode {@code String}s that specifies the block IDs to be committed. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.commitBlockList")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono commitBlockList(List base64BlockIDs, - BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blockBlobs().commitBlockListWithRestResponseAsync( - null, null, new BlockLookupList().latest(base64BlockIDs), null, metadata, - null, null, null, null, headers, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java index 9dced1f87022b..ec76f684c1bb4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java @@ -4,7 +4,6 @@ package com.azure.storage.blob; import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -44,22 +43,22 @@ * for more information. */ public final class BlockBlobClient extends BlobClient { + private final BlockBlobAsyncClient blockBlobAsyncClient; - private BlockBlobAsyncClient blockBlobAsyncClient; /** * Indicates the maximum number of bytes that can be sent in a call to upload. */ - public static final int MAX_UPLOAD_BLOB_BYTES = 256 * Constants.MB; + public static final int MAX_UPLOAD_BLOB_BYTES = BlockBlobAsyncClient.MAX_UPLOAD_BLOB_BYTES; /** * Indicates the maximum number of bytes that can be sent in a call to stageBlock. */ - public static final int MAX_STAGE_BLOCK_BYTES = 100 * Constants.MB; + public static final int MAX_STAGE_BLOCK_BYTES = BlockBlobAsyncClient.MAX_STAGE_BLOCK_BYTES; /** * Indicates the maximum number of blocks allowed in a block blob. */ - public static final int MAX_BLOCKS = 50000; + public static final int MAX_BLOCKS = BlockBlobAsyncClient.MAX_BLOCKS; /** * Package-private constructor for use by {@link BlockBlobClientBuilder}. @@ -161,9 +160,8 @@ public Response upload(InputStream data, long length, BlobHTTPHea return ByteBufAllocator.DEFAULT.buffer((int) count).writeBytes(cache); })); - Mono> upload = blockBlobAsyncClient.blockBlobAsyncRawClient - .upload(fbb.subscribeOn(Schedulers.elastic()), length, headers, metadata, accessConditions) - .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); + Mono> upload = blockBlobAsyncClient + .upload(fbb.subscribeOn(Schedulers.elastic()), length, headers, metadata, accessConditions); try { return Utility.blockWithOptionalTimeout(upload, timeout); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 406a7440b0c5b..b61d2b36f3c31 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -9,6 +9,7 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobFlatListSegment; import com.azure.storage.blob.models.BlobHierarchyListSegment; import com.azure.storage.blob.models.BlobItem; @@ -30,8 +31,11 @@ import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.List; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** * Client to a container. It may only be instantiated through a {@link ContainerClientBuilder} or via the method * {@link StorageAsyncClient#getContainerAsyncClient(String)}. This class does not hold any @@ -54,20 +58,20 @@ * object through {@link Mono#toFuture()}. */ public final class ContainerAsyncClient { - ContainerAsyncRawClient containerAsyncRawClient; - public static final String ROOT_CONTAINER_NAME = "$root"; public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; public static final String LOG_CONTAINER_NAME = "$logs"; + private final AzureBlobStorageImpl azureBlobStorage; + /** * Package-private constructor for use by {@link ContainerClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ ContainerAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.containerAsyncRawClient = new ContainerAsyncRawClient(azureBlobStorageBuilder.build()); + this.azureBlobStorage = azureBlobStorageBuilder.build(); } /** @@ -103,7 +107,7 @@ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName, String snapshot) { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -139,7 +143,7 @@ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName) { public PageBlobAsyncClient getPageBlobAsyncClient(String blobName, String snapshot) { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -175,7 +179,7 @@ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName) { public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName, String snapshot) { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -211,7 +215,7 @@ public BlobAsyncClient getBlobAsyncClient(String blobName) { public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { return new BlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** @@ -223,7 +227,7 @@ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { public StorageAsyncClient getStorageAsyncClient() { return new StorageAsyncClient(new AzureBlobStorageBuilder() .url(Utility.stripLastPathSegment(getContainerUrl()).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** @@ -233,9 +237,9 @@ public StorageAsyncClient getStorageAsyncClient() { */ public URL getContainerUrl() { try { - return new URL(containerAsyncRawClient.azureBlobStorage.url()); + return new URL(azureBlobStorage.url()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), containerAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } @@ -281,8 +285,10 @@ public Mono create() { * A reactive response signalling completion. */ public Mono create(Metadata metadata, PublicAccessType accessType) { - return containerAsyncRawClient - .create(metadata, accessType) + metadata = metadata == null ? new Metadata() : metadata; + + return postProcessResponse(this.azureBlobStorage.containers().createWithRestResponseAsync( + null, null, metadata, accessType, null, Context.NONE)) .map(VoidResponse::new); } @@ -303,15 +309,23 @@ public Mono delete() { * deleted during garbage collection. For more information, see the * Azure Docs. * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param accessConditions {@link ContainerAccessConditions} + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either + * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. */ public Mono delete(ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .delete(accessConditions) + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + + if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .deleteWithRestResponseAsync(null, null, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -338,8 +352,9 @@ public Mono> getProperties() { * A reactive response containing the container properties. */ public Mono> getProperties(LeaseAccessConditions leaseAccessConditions) { - return containerAsyncRawClient - .getProperties(leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.containers() + .getPropertiesWithRestResponseAsync(null, null, null, + leaseAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new ContainerProperties(rb.deserializedHeaders()))); } @@ -361,18 +376,27 @@ public Mono setMetadata(Metadata metadata) { * Sets the container's metadata. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @param accessConditions {@link ContainerAccessConditions} + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has anything + * set other than {@link ModifiedAccessConditions#ifModifiedSince()}. */ public Mono setMetadata(Metadata metadata, ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .setMetadata(metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + if (!validateNoEtag(accessConditions.modifiedAccessConditions()) + || accessConditions.modifiedAccessConditions().ifUnmodifiedSince() != null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "If-Modified-Since is the only HTTP access condition supported for this API"); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .setMetadataWithRestResponseAsync(null, null, metadata, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -401,7 +425,8 @@ public Mono> getAccessPolicy() { * A reactive response containing the container access policy. */ public Mono> getAccessPolicy(LeaseAccessConditions leaseAccessConditions) { - return containerAsyncRawClient.getAccessPolicy(leaseAccessConditions); + return postProcessResponse(this.azureBlobStorage.containers().getAccessPolicyWithRestResponseAsync(null, null, null, leaseAccessConditions, Context.NONE) + .map(response -> new SimpleResponse<>(response, new ContainerAccessPolicies(response.deserializedHeaders().blobPublicAccess(), response.value())))); } /** @@ -442,13 +467,43 @@ public Mono setAccessPolicy(PublicAccessType accessType, * @param accessConditions * {@link ContainerAccessConditions} * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either + * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. */ public Mono setAccessPolicy(PublicAccessType accessType, List identifiers, ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .setAccessPolicy(accessType, identifiers, accessConditions) + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + + if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); + } + + /* + We truncate to seconds because the service only supports nanoseconds or seconds, but doing an + OffsetDateTime.now will only give back milliseconds (more precise fields are zeroed and not serialized). This + allows for proper serialization with no real detriment to users as sub-second precision on active time for + signed identifiers is not really necessary. + */ + if (identifiers != null) { + for (SignedIdentifier identifier : identifiers) { + if (identifier.accessPolicy() != null && identifier.accessPolicy().start() != null) { + identifier.accessPolicy().start( + identifier.accessPolicy().start().truncatedTo(ChronoUnit.SECONDS)); + } + if (identifier.accessPolicy() != null && identifier.accessPolicy().expiry() != null) { + identifier.accessPolicy().expiry( + identifier.accessPolicy().expiry().truncatedTo(ChronoUnit.SECONDS)); + } + } + } + + return postProcessResponse(this.azureBlobStorage.containers() + .setAccessPolicyWithRestResponseAsync(null, identifiers, null, accessType, + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .map(VoidResponse::new); } @@ -502,9 +557,36 @@ public Flux listBlobsFlat() { * A reactive response emitting the listed blobs, flattened. */ public Flux listBlobsFlat(ListBlobsOptions options) { - return containerAsyncRawClient - .listBlobsFlatSegment(null, options) - .flatMapMany(response -> listBlobsFlatHelper(options, response)); + return listBlobsFlatSegment(null, options).flatMapMany(response -> listBlobsFlatHelper(options, response)); + } + + /* + * Returns a single segment of blobs starting from the specified Marker. Use an empty + * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. + * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned + * Marker) to get the next segment. For more information, see the + * Azure Docs. + * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. + * @param options + * {@link ListBlobsOptions} + * + * @return Emits the successful response. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + */ + private Mono listBlobsFlatSegment(String marker, ListBlobsOptions options) { + options = options == null ? new ListBlobsOptions() : options; + + return postProcessResponse(this.azureBlobStorage.containers() + .listBlobFlatSegmentWithRestResponseAsync(null, options.prefix(), marker, + options.maxResults(), options.details().toList(), null, null, Context.NONE)); } private Flux listBlobsFlatHelper(ListBlobsOptions options, ContainersListBlobFlatSegmentResponse response) { @@ -518,7 +600,7 @@ private Flux listBlobsFlatHelper(ListBlobsOptions options, ContainersL if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(containerAsyncRawClient.listBlobsFlatSegment(response.value().nextMarker(), options) + result = result.concatWith(listBlobsFlatSegment(response.value().nextMarker(), options) .flatMapMany(r -> listBlobsFlatHelper(options, r))); } @@ -594,10 +676,48 @@ public Flux listBlobsHierarchy(String directory) { * A reactive response emitting the prefixes and blobs. */ public Flux listBlobsHierarchy(String delimiter, ListBlobsOptions options) { - return containerAsyncRawClient.listBlobsHierarchySegment(null, delimiter, options) + return listBlobsHierarchySegment(null, delimiter, options) .flatMapMany(response -> listBlobsHierarchyHelper(delimiter, options, Context.NONE, response)); } + /* + * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty + * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. + * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned + * Marker) to get the next segment. For more information, see the + * Azure Docs. + * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. + * @param delimiter + * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs + * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may + * be a single character or a string. + * @param options + * {@link ListBlobsOptions} + * + * @return Emits the successful response. + * @throws UnsupportedOperationException If {@link ListBlobsOptions#details()} has {@link BlobListDetails#snapshots()} + * set. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + */ + private Mono listBlobsHierarchySegment(String marker, String delimiter, ListBlobsOptions options) { + options = options == null ? new ListBlobsOptions() : options; + if (options.details().snapshots()) { + throw new UnsupportedOperationException("Including snapshots in a hierarchical listing is not supported."); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .listBlobHierarchySegmentWithRestResponseAsync(null, delimiter, options.prefix(), marker, + options.maxResults(), options.details().toList(), null, null, Context.NONE)); + } + private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptions options, Context context, ContainersListBlobHierarchySegmentResponse response) { Flux blobs; @@ -617,7 +737,7 @@ private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptio if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(containerAsyncRawClient.listBlobsHierarchySegment(response.value().nextMarker(), delimiter, options) + result = result.concatWith(listBlobsHierarchySegment(response.value().nextMarker(), delimiter, options) .flatMapMany(r -> listBlobsHierarchyHelper(delimiter, options, context, r))); } @@ -723,12 +843,20 @@ public Mono> acquireLease(String proposedId, int duration) { * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response containing the lease ID. + * @return A reactive response containing the lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or + * {@link ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> acquireLease(String proposedID, int duration, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .acquireLease(proposedID, duration, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().acquireLeaseWithRestResponseAsync( + null, null, duration, proposedID, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -755,12 +883,20 @@ public Mono> renewLease(String leaseID) { * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response containing the renewed lease ID. + * @return A reactive response containing the renewed lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or + * {@link ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .renewLease(leaseID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().renewLeaseWithRestResponseAsync(null, + leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -787,12 +923,20 @@ public Mono releaseLease(String leaseID) { * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or + * {@link ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono releaseLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .releaseLease(leaseID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().releaseLeaseWithRestResponseAsync( + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -822,12 +966,20 @@ public Mono> breakLease() { * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response containing the remaining time in the broken lease. + * @return A reactive response containing the remaining time in the broken lease. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or + * {@link ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> breakLease(Integer breakPeriodInSeconds, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .breakLease(breakPeriodInSeconds, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().breakLeaseWithRestResponseAsync(null, + null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, Duration.ofSeconds(rb.deserializedHeaders().leaseTime()))); } @@ -859,10 +1011,19 @@ public Mono> changeLease(String leaseId, String proposedID) { * will fail if the specified condition is not satisfied. * * @return A reactive response containing the new lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or + * {@link ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> changeLease(String leaseId, String proposedID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .changeLease(leaseId, proposedID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().changeLeaseWithRestResponseAsync(null, + leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -874,8 +1035,15 @@ public Mono> changeLease(String leaseId, String proposedID, Mod * A reactive response containing the account info. */ public Mono> getAccountInfo() { - return containerAsyncRawClient - .getAccountInfo() + return postProcessResponse( + this.azureBlobStorage.containers().getAccountInfoWithRestResponseAsync(null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } + + private boolean validateNoEtag(ModifiedAccessConditions modifiedAccessConditions) { + if (modifiedAccessConditions == null) { + return true; + } + return modifiedAccessConditions.ifMatch() == null && modifiedAccessConditions.ifNoneMatch() == null; + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java deleted file mode 100644 index e4106549b208c..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java +++ /dev/null @@ -1,708 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.SimpleResponse; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobListDetails; -import com.azure.storage.blob.models.ContainerAccessConditions; -import com.azure.storage.blob.models.ContainerAccessPolicies; -import com.azure.storage.blob.models.ContainersAcquireLeaseResponse; -import com.azure.storage.blob.models.ContainersBreakLeaseResponse; -import com.azure.storage.blob.models.ContainersChangeLeaseResponse; -import com.azure.storage.blob.models.ContainersCreateResponse; -import com.azure.storage.blob.models.ContainersDeleteResponse; -import com.azure.storage.blob.models.ContainersGetAccountInfoResponse; -import com.azure.storage.blob.models.ContainersGetPropertiesResponse; -import com.azure.storage.blob.models.ContainersListBlobFlatSegmentResponse; -import com.azure.storage.blob.models.ContainersListBlobHierarchySegmentResponse; -import com.azure.storage.blob.models.ContainersReleaseLeaseResponse; -import com.azure.storage.blob.models.ContainersRenewLeaseResponse; -import com.azure.storage.blob.models.ContainersSetAccessPolicyResponse; -import com.azure.storage.blob.models.ContainersSetMetadataResponse; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.ListBlobsOptions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PublicAccessType; -import com.azure.storage.blob.models.SignedIdentifier; -import reactor.core.publisher.Mono; - -import java.time.temporal.ChronoUnit; -import java.util.List; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a container. It may be obtained by direct construction or via the create method on a - * {@link StorageAsyncRawClient} object. This class does not hold any state about a particular blob but is instead a convenient way - * of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs. - * Please refer to the - * Azure Docs - * for more information on containers. - */ -final class ContainerAsyncRawClient { - - public static final String ROOT_CONTAINER_NAME = "$root"; - - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; - - public static final String LOG_CONTAINER_NAME = "$logs"; - - AzureBlobStorageImpl azureBlobStorage; - - /** - * Creates a {@code ContainerAsyncClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - ContainerAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.azureBlobStorage = azureBlobStorage; - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create() { - return this.create(null, null); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(Metadata metadata, PublicAccessType accessType) { - metadata = metadata == null ? new Metadata() : metadata; - - return postProcessResponse(this.azureBlobStorage.containers().createWithRestResponseAsync( - null, null, metadata, accessType, null, Context.NONE)); - - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete() { - return this.delete(null); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either - * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete(ContainerAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - - if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .deleteWithRestResponseAsync(null, null, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return this.getProperties(null); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties(LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.containers() - .getPropertiesWithRestResponseAsync(null, null, null, - leaseAccessConditions, Context.NONE)); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has anything - * set other than {@link ModifiedAccessConditions#ifModifiedSince()}. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - if (!validateNoEtag(accessConditions.modifiedAccessConditions()) - || accessConditions.modifiedAccessConditions().ifUnmodifiedSince() != null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "If-Modified-Since is the only HTTP access condition supported for this API"); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .setMetadataWithRestResponseAsync(null, null, metadata, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono> getAccessPolicy() { - return this.getAccessPolicy(null); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono> getAccessPolicy(LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.containers().getAccessPolicyWithRestResponseAsync(null, null, null, leaseAccessConditions, Context.NONE) - .map(response -> new SimpleResponse<>(response, new ContainerAccessPolicies(response.deserializedHeaders().blobPublicAccess(), response.value())))); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers) { - return this.setAccessPolicy(accessType, identifiers, null); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either - * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - - if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); - } - - /* - We truncate to seconds because the service only supports nanoseconds or seconds, but doing an - OffsetDateTime.now will only give back milliseconds (more precise fields are zeroed and not serialized). This - allows for proper serialization with no real detriment to users as sub-second precision on active time for - signed identifiers is not really necessary. - */ - if (identifiers != null) { - for (SignedIdentifier identifier : identifiers) { - if (identifier.accessPolicy() != null && identifier.accessPolicy().start() != null) { - identifier.accessPolicy().start( - identifier.accessPolicy().start().truncatedTo(ChronoUnit.SECONDS)); - } - if (identifier.accessPolicy() != null && identifier.accessPolicy().expiry() != null) { - identifier.accessPolicy().expiry( - identifier.accessPolicy().expiry().truncatedTo(ChronoUnit.SECONDS)); - } - } - } - - return postProcessResponse(this.azureBlobStorage.containers() - .setAccessPolicyWithRestResponseAsync(null, identifiers, null, accessType, - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - - } - - private boolean validateNoEtag(ModifiedAccessConditions modifiedAccessConditions) { - if (modifiedAccessConditions == null) { - return true; - } - return modifiedAccessConditions.ifMatch() == null && modifiedAccessConditions.ifNoneMatch() == null; - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @param proposedId - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().acquireLeaseWithRestResponseAsync( - null, null, duration, proposedID, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID) { - return this.renewLease(leaseID, null); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().renewLeaseWithRestResponseAsync(null, - leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID) { - return this.releaseLease(leaseID, null); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().releaseLeaseWithRestResponseAsync( - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return Emits the successful response. - */ - public Mono breakLease() { - return this.breakLease(null, null); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time - * remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().breakLeaseWithRestResponseAsync(null, - null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)); - - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseID, String proposedID) { - return this.changeLease(leaseID, proposedID, null); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseID, String proposedID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().changeLeaseWithRestResponseAsync(null, - leaseID, proposedID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlobsFlatSegment(String marker, ListBlobsOptions options) { - options = options == null ? new ListBlobsOptions() : options; - - return postProcessResponse(this.azureBlobStorage.containers() - .listBlobFlatSegmentWithRestResponseAsync(null, options.prefix(), marker, - options.maxResults(), options.details().toList(), null, null, Context.NONE)); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ListBlobsOptions#details()} has {@link BlobListDetails#snapshots()} - * set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options) { - options = options == null ? new ListBlobsOptions() : options; - if (options.details().snapshots()) { - throw new UnsupportedOperationException("Including snapshots in a hierarchical listing is not supported."); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .listBlobHierarchySegmentWithRestResponseAsync(null, delimiter, options.prefix(), marker, - options.maxResults(), options.details().toList(), null, null, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.containers().getAccountInfoWithRestResponseAsync(null, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java index b8c1f9d8bd09e..40ed0d25daa1f 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java @@ -37,14 +37,13 @@ * for more information on containers. */ public final class ContainerClient { - private ContainerAsyncClient containerAsyncClient; - public static final String ROOT_CONTAINER_NAME = "$root"; + public static final String ROOT_CONTAINER_NAME = ContainerAsyncClient.ROOT_CONTAINER_NAME; - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; + public static final String STATIC_WEBSITE_CONTAINER_NAME = ContainerAsyncClient.STATIC_WEBSITE_CONTAINER_NAME; - public static final String LOG_CONTAINER_NAME = "$logs"; + public static final String LOG_CONTAINER_NAME = ContainerAsyncClient.LOG_CONTAINER_NAME; /** * Package-private constructor for use by {@link ContainerClientBuilder}. diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java deleted file mode 100644 index 19d10f5444ee5..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java +++ /dev/null @@ -1,652 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.rest.Response; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.ContainerAccessConditions; -import com.azure.storage.blob.models.ContainerAccessPolicies; -import com.azure.storage.blob.models.ContainersAcquireLeaseResponse; -import com.azure.storage.blob.models.ContainersBreakLeaseResponse; -import com.azure.storage.blob.models.ContainersChangeLeaseResponse; -import com.azure.storage.blob.models.ContainersCreateResponse; -import com.azure.storage.blob.models.ContainersDeleteResponse; -import com.azure.storage.blob.models.ContainersGetAccountInfoResponse; -import com.azure.storage.blob.models.ContainersGetPropertiesResponse; -import com.azure.storage.blob.models.ContainersListBlobFlatSegmentResponse; -import com.azure.storage.blob.models.ContainersListBlobHierarchySegmentResponse; -import com.azure.storage.blob.models.ContainersReleaseLeaseResponse; -import com.azure.storage.blob.models.ContainersRenewLeaseResponse; -import com.azure.storage.blob.models.ContainersSetAccessPolicyResponse; -import com.azure.storage.blob.models.ContainersSetMetadataResponse; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.ListBlobsOptions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PublicAccessType; -import com.azure.storage.blob.models.SignedIdentifier; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.util.List; - -/** - * Represents a URL to a container. It may be obtained by direct construction or via the create method on a - * {@link StorageAsyncRawClient} object. This class does not hold any state about a particular blob but is instead a convenient way - * of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs. - * Please refer to the - * Azure Docs - * for more information on containers. - */ -final class ContainerRawClient { - - private ContainerAsyncRawClient containerAsyncRawClient; - - public static final String ROOT_CONTAINER_NAME = "$root"; - - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; - - public static final String LOG_CONTAINER_NAME = "$logs"; - - - /** - * Creates a {@code ContainerAsyncClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - ContainerRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.containerAsyncRawClient = new ContainerAsyncRawClient(azureBlobStorage); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersCreateResponse create() { - return this.create(null, null, null); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersCreateResponse create(Metadata metadata, PublicAccessType accessType, Duration timeout) { - Mono response = containerAsyncRawClient.create(metadata, accessType); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersDeleteResponse delete() { - return this.delete(null, null); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersDeleteResponse delete(ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.delete(accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetPropertiesResponse getProperties() { - return this.getProperties(null, null); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetPropertiesResponse getProperties(LeaseAccessConditions leaseAccessConditions, - Duration timeout) { - Mono response = containerAsyncRawClient.getProperties(leaseAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetMetadataResponse setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null, null); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetMetadataResponse setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.setMetadata(metadata, accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Response getAccessPolicy() { - return this.getAccessPolicy(null, null); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Response getAccessPolicy(LeaseAccessConditions leaseAccessConditions, - Duration timeout) { - Mono> response = containerAsyncRawClient.getAccessPolicy(leaseAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetAccessPolicyResponse setAccessPolicy(PublicAccessType accessType, - List identifiers) { - return this.setAccessPolicy(accessType, identifiers, null, null); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetAccessPolicyResponse setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.setAccessPolicy(accessType, identifiers, accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @param proposedId - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersAcquireLeaseResponse acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null, null); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersAcquireLeaseResponse acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.acquireLease(proposedID, duration, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersRenewLeaseResponse renewLease(String leaseID) { - return this.renewLease(leaseID, null, null); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersRenewLeaseResponse renewLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.renewLease(leaseID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersReleaseLeaseResponse releaseLease(String leaseID) { - return this.releaseLease(leaseID, null, null); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersReleaseLeaseResponse releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.releaseLease(leaseID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return Emits the successful response. - */ - public ContainersBreakLeaseResponse breakLease() { - return this.breakLease(null, null, null); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time - * remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersBreakLeaseResponse breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.breakLease(breakPeriodInSeconds, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersChangeLeaseResponse changeLease(String leaseID, String proposedID) { - return this.changeLease(leaseID, proposedID, null, null); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersChangeLeaseResponse changeLease(String leaseID, String proposedID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.changeLease(leaseID, proposedID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobFlatSegmentResponse listBlobsFlatSegment(String marker, ListBlobsOptions options) { - return this.listBlobsFlatSegment(marker, options, null); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobFlatSegmentResponse listBlobsFlatSegment(String marker, ListBlobsOptions options, - Duration timeout) { - Mono response = containerAsyncRawClient.listBlobsFlatSegment(marker, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobHierarchySegmentResponse listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options) { - return this.listBlobsHierarchySegment(marker, delimiter, options, null); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobHierarchySegmentResponse listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options, Duration timeout) { - Mono response = containerAsyncRawClient.listBlobsHierarchySegment(marker, delimiter, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetAccountInfoResponse getAccountInfo() { - return this.getAccountInfo(null); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetAccountInfoResponse getAccountInfo(Duration timeout) { - Mono response = containerAsyncRawClient.getAccountInfo(); - return Utility.blockWithOptionalTimeout(response, timeout); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index 073df29744582..72f052fd27573 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -5,6 +5,8 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.implementation.http.UrlBuilder; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -17,12 +19,14 @@ import com.azure.storage.blob.models.PageRange; import com.azure.storage.blob.models.SequenceNumberActionType; import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.Unpooled; +import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.net.MalformedURLException; import java.net.URL; -import java.nio.ByteBuffer; + +import static com.azure.storage.blob.Utility.postProcessResponse; /** * Client to a page blob. It may only be instantiated through a {@link PageBlobClientBuilder}, via @@ -48,9 +52,6 @@ * object through {@link Mono#toFuture()}. */ public final class PageBlobAsyncClient extends BlobAsyncClient { - - final PageBlobAsyncRawClient pageBlobAsyncRawClient; - /** * Indicates the number of bytes in a page. */ @@ -67,7 +68,6 @@ public final class PageBlobAsyncClient extends BlobAsyncClient { */ PageBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - this.pageBlobAsyncRawClient = new PageBlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); } /** @@ -104,13 +104,30 @@ public Mono> create(long size) { * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response containing the information of the created page blob. + * @return A reactive response containing the information of the created page blob. + * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncClient#PAGE_BYTES} + * or {@code sequenceNumber} isn't null and is less than 0. */ public Mono> create(long size, Long sequenceNumber, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .create(size, sequenceNumber, headers, metadata, accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + if (size % PAGE_BYTES != 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncClient.PAGE_BYTES."); + } + if (sequenceNumber != null && sequenceNumber < 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); + } + metadata = metadata == null ? new Metadata() : metadata; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().createWithRestResponseAsync(null, + null, 0, size, null, metadata, null, null, + null, sequenceNumber, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -133,7 +150,7 @@ public Mono> create(long size, Long sequenceNumber, BlobH * @return * A reactive response containing the information of the uploaded pages. */ - public Mono> uploadPages(PageRange pageRange, Flux body) { + public Mono> uploadPages(PageRange pageRange, Flux body) { return this.uploadPages(pageRange, body, null); } @@ -155,13 +172,25 @@ public Mono> uploadPages(PageRange pageRange, Flux> uploadPages(PageRange pageRange, Flux body, + public Mono> uploadPages(PageRange pageRange, Flux body, PageBlobAccessConditions pageBlobAccessConditions) { - return pageBlobAsyncRawClient - .uploadPages(pageRange, body.map(Unpooled::wrappedBuffer), pageBlobAccessConditions) + pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() : pageBlobAccessConditions; + + if (pageRange == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("pageRange cannot be null."); + } + String pageRangeStr = pageRangeToString(pageRange); + + return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesWithRestResponseAsync(null, + null, body, pageRange.end() - pageRange.start() + 1, null, + null, pageRangeStr, null, null, null, null, + pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), + pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -218,15 +247,33 @@ public Mono> uploadPagesFromURL(PageRange range, URL sour * @param sourceAccessConditions * {@link SourceModifiedAccessConditions} * - * @return - * A reactive response containing the information of the uploaded pages. + * @return A reactive response containing the information of the uploaded pages. + * @throws IllegalArgumentException If {@code range} is {@code null} */ public Mono> uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset, byte[] sourceContentMD5, PageBlobAccessConditions destAccessConditions, SourceModifiedAccessConditions sourceAccessConditions) { + if (range == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("range cannot be null."); + } + + String rangeString = pageRangeToString(range); - return pageBlobAsyncRawClient - .uploadPagesFromURL(range, sourceURL, sourceOffset, sourceContentMD5, destAccessConditions, sourceAccessConditions) + if (sourceOffset == null) { + sourceOffset = 0L; + } + + String sourceRangeString = pageRangeToString(new PageRange().start(sourceOffset).end(sourceOffset + (range.end() - range.start()))); + + destAccessConditions = destAccessConditions == null ? new PageBlobAccessConditions() : destAccessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesFromURLWithRestResponseAsync( + null, null, sourceURL, sourceRangeString, 0, rangeString, sourceContentMD5, + null, null, destAccessConditions.leaseAccessConditions(), + destAccessConditions.sequenceNumberAccessConditions(), destAccessConditions.modifiedAccessConditions(), + sourceAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -259,13 +306,23 @@ public Mono> clearPages(PageRange pageRange) { * @param pageBlobAccessConditions * {@link PageBlobAccessConditions} * - * @return - * A reactive response containing the information of the cleared pages. + * @return A reactive response containing the information of the cleared pages. + * @throws IllegalArgumentException If {@code pageRange} is {@code null} */ public Mono> clearPages(PageRange pageRange, PageBlobAccessConditions pageBlobAccessConditions) { - return pageBlobAsyncRawClient - .clearPages(pageRange, pageBlobAccessConditions) + pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() : pageBlobAccessConditions; + if (pageRange == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("pageRange cannot be null."); + } + String pageRangeStr = pageRangeToString(pageRange); + + return postProcessResponse(this.azureBlobStorage.pageBlobs().clearPagesWithRestResponseAsync(null, + null, 0, null, pageRangeStr, null, + pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), + pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -295,10 +352,14 @@ public Flux getPageRanges(BlobRange blobRange) { * @return * A reactive response emitting all the page ranges. */ - public Flux getPageRanges(BlobRange blobRange, - BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .getPageRanges(blobRange, accessConditions) + public Flux getPageRanges(BlobRange blobRange, BlobAccessConditions accessConditions) { + blobRange = blobRange == null ? new BlobRange(0) : blobRange; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesWithRestResponseAsync( + null, null, snapshot, null, null, blobRange.toHeaderValue(), + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .flatMapMany(response -> Flux.fromIterable(response.value().pageRange())); } @@ -333,13 +394,21 @@ public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapsho * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting all the different page ranges. + * @return A reactive response emitting all the different page ranges. + * @throws IllegalArgumentException If {@code prevSnapshot} is {@code null} */ - public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapshot, - BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .getPageRangesDiff(blobRange, prevSnapshot, accessConditions) + public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapshot, BlobAccessConditions accessConditions) { + blobRange = blobRange == null ? new BlobRange(0) : blobRange; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + if (prevSnapshot == null) { + throw new IllegalArgumentException("prevSnapshot cannot be null"); + } + + return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesDiffWithRestResponseAsync( + null, null, snapshot, null, null, prevSnapshot, + blobRange.toHeaderValue(), null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .flatMapMany(response -> Flux.fromIterable(response.value().pageRange())); } @@ -368,12 +437,20 @@ public Mono> resize(long size) { * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting the resized page blob. + * @return A reactive response emitting the resized page blob. + * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncClient#PAGE_BYTES} */ public Mono> resize(long size, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .resize(size, accessConditions) + if (size % PAGE_BYTES != 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncClient.PAGE_BYTES."); + } + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().resizeWithRestResponseAsync(null, + null, size, null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -407,13 +484,22 @@ public Mono> updateSequenceNumber(SequenceNumberActionTyp * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting the updated page blob. + * @return A reactive response emitting the updated page blob. + * @throws IllegalArgumentException If {@code sequenceNumber} isn't null and is less than 0 */ - public Mono> updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .updateSequenceNumber(action, sequenceNumber, accessConditions) + public Mono> updateSequenceNumber(SequenceNumberActionType action, Long sequenceNumber, BlobAccessConditions accessConditions) { + if (sequenceNumber != null && sequenceNumber < 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); + } + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + sequenceNumber = action == SequenceNumberActionType.INCREMENT ? null : sequenceNumber; + + return postProcessResponse( + this.azureBlobStorage.pageBlobs().updateSequenceNumberWithRestResponseAsync(null, + null, action, null, sequenceNumber, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -454,13 +540,37 @@ public Mono> copyIncremental(URL source, String snapsho * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response emitting the copy status. + * @return A reactive response emitting the copy status. + * @throws Error If {@code source} and {@code snapshot} form a malformed URL. */ - public Mono> copyIncremental(URL source, String snapshot, - ModifiedAccessConditions modifiedAccessConditions) { - return pageBlobAsyncRawClient - .copyIncremental(source, snapshot, modifiedAccessConditions) + public Mono> copyIncremental(URL source, String snapshot, ModifiedAccessConditions modifiedAccessConditions) { + UrlBuilder builder = UrlBuilder.parse(source); + builder.setQueryParameter(Constants.SNAPSHOT_QUERY_PARAMETER, snapshot); + try { + source = builder.toURL(); + } catch (MalformedURLException e) { + // We are parsing a valid url and adding a query parameter. If this fails, we can't recover. + throw new Error(e); + } + return postProcessResponse(this.azureBlobStorage.pageBlobs().copyIncrementalWithRestResponseAsync( + null, null, source, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyStatus())); } + + private static String pageRangeToString(PageRange pageRange) { + if (pageRange.start() < 0 || pageRange.end() <= 0) { + throw new IllegalArgumentException("PageRange's start and end values must be greater than or equal to " + + "0 if specified."); + } + if (pageRange.start() % PAGE_BYTES != 0) { + throw new IllegalArgumentException("PageRange's start value must be a multiple of 512."); + } + if (pageRange.end() % PAGE_BYTES != PAGE_BYTES - 1) { + throw new IllegalArgumentException("PageRange's end value must be 1 less than a multiple of 512."); + } + if (pageRange.end() <= pageRange.start()) { + throw new IllegalArgumentException("PageRange's End value must be after the start."); + } + return "bytes=" + pageRange.start() + '-' + pageRange.end(); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java deleted file mode 100644 index fba55bd8d7455..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java +++ /dev/null @@ -1,620 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.implementation.http.UrlBuilder; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PageBlobAccessConditions; -import com.azure.storage.blob.models.PageBlobsClearPagesResponse; -import com.azure.storage.blob.models.PageBlobsCopyIncrementalResponse; -import com.azure.storage.blob.models.PageBlobsCreateResponse; -import com.azure.storage.blob.models.PageBlobsGetPageRangesDiffResponse; -import com.azure.storage.blob.models.PageBlobsGetPageRangesResponse; -import com.azure.storage.blob.models.PageBlobsResizeResponse; -import com.azure.storage.blob.models.PageBlobsUpdateSequenceNumberResponse; -import com.azure.storage.blob.models.PageBlobsUploadPagesFromURLResponse; -import com.azure.storage.blob.models.PageBlobsUploadPagesResponse; -import com.azure.storage.blob.models.PageRange; -import com.azure.storage.blob.models.SequenceNumberActionType; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.MalformedURLException; -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a page blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is instead a convenient - * way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - * for more information. - */ -final class PageBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the number of bytes in a page. - */ - public static final int PAGE_BYTES = 512; - - /** - * Indicates the maximum number of bytes that may be sent in a call to putPage. - */ - public static final int MAX_PUT_PAGES_BYTES = 4 * Constants.MB; - - /** - * Creates a {@code PageBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - * - */ - PageBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - super(azureBlobStorage, snapshot); - } - - private static String pageRangeToString(PageRange pageRange) { - if (pageRange.start() < 0 || pageRange.end() <= 0) { - throw new IllegalArgumentException("PageRange's start and end values must be greater than or equal to " - + "0 if specified."); - } - if (pageRange.start() % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - throw new IllegalArgumentException("PageRange's start value must be a multiple of 512."); - } - if (pageRange.end() % PageBlobAsyncRawClient.PAGE_BYTES != PageBlobAsyncRawClient.PAGE_BYTES - 1) { - throw new IllegalArgumentException("PageRange's end value must be 1 less than a multiple of 512."); - } - if (pageRange.end() <= pageRange.start()) { - throw new IllegalArgumentException("PageRange's End value must be after the start."); - } - return new StringBuilder("bytes=").append(pageRange.start()).append('-').append(pageRange.end()).toString(); - } - - /** - * Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. - * For more information, see the - * Azure Docs. - * - * @param size - * Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a - * 512-byte boundary. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(long size) { - return this.create(size, null, null, null, null); - } - - /** - * Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. - * For more information, see the - * Azure Docs. - * - * @param size - * Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a - * 512-byte boundary. - * @param sequenceNumber - * A user-controlled value that you can use to track requests. The value of the sequence number must be - * between 0 and 2^63 - 1.The default value is 0. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncRawClient#PAGE_BYTES} - * or {@code sequenceNumber} isn't null and is less than 0. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(long size, Long sequenceNumber, BlobHTTPHeaders headers, - Metadata metadata, BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - if (size % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncRawClient.PAGE_BYTES."); - } - if (sequenceNumber != null && sequenceNumber < 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); - } - metadata = metadata == null ? new Metadata() : metadata; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().createWithRestResponseAsync(null, - null, 0, size, null, metadata, null, null, - null, sequenceNumber, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset must - * be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges are - * 0-511, 512-1023, etc. - * @param body - * The data to upload. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.uploadPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPages(PageRange pageRange, Flux body) { - return this.uploadPages(pageRange, body, null); - } - - /** - * Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param body - * The data to upload. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param pageBlobAccessConditions - * {@link PageBlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code pageRange} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.uploadPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPages(PageRange pageRange, Flux body, - PageBlobAccessConditions pageBlobAccessConditions) { - pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() - : pageBlobAccessConditions; - - if (pageRange == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("pageRange cannot be null."); - } - String pageRangeStr = pageRangeToString(pageRange); - - return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesWithRestResponseAsync(null, - null, body, pageRange.end() - pageRange.start() + 1, null, - null, pageRangeStr, null, null, null, null, - pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), - pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Writes 1 or more pages from the source page blob to this page blob. The start and end offsets must be a multiple - * of 512. - * For more information, see the - * Azure Docs. - *

- * - * @param range - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceOffset - * The source offset to copy from. Pass null or 0 to copy from the beginning of source page blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_from_url "Sample code for PageBlobAsyncRawClient.uploadPagesFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset) { - return this.uploadPagesFromURL(range, sourceURL, sourceOffset, null, null, - null); - } - - /** - * Writes 1 or more pages from the source page blob to this page blob. The start and end offsets must be a multiple - * of 512. - * For more information, see the - * Azure Docs. - *

- * - * @param range - * The destination {@link PageRange} range. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceOffset - * The source offset to copy from. Pass null or 0 to copy from the beginning of source blob. - * @param sourceContentMD5 - * An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param destAccessConditions - * {@link PageBlobAccessConditions} - * @param sourceAccessConditions - * {@link SourceModifiedAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code range} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_from_url "Sample code for PageBlobAsyncRawClient.uploadPagesFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset, - byte[] sourceContentMD5, PageBlobAccessConditions destAccessConditions, - SourceModifiedAccessConditions sourceAccessConditions) { - - if (range == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("range cannot be null."); - } - - String rangeString = pageRangeToString(range); - - if (sourceOffset == null) { - sourceOffset = 0L; - } - - String sourceRangeString = pageRangeToString(new PageRange().start(sourceOffset).end(sourceOffset + (range.end() - range.start()))); - - destAccessConditions = destAccessConditions == null ? new PageBlobAccessConditions() : destAccessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesFromURLWithRestResponseAsync( - null, null, sourceURL, sourceRangeString, 0, rangeString, sourceContentMD5, - null, null, destAccessConditions.leaseAccessConditions(), - destAccessConditions.sequenceNumberAccessConditions(), destAccessConditions.modifiedAccessConditions(), - sourceAccessConditions, Context.NONE)); - } - - /** - * Frees the specified pages from the page blob. - * For more information, see the - * Azure Docs. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.clearPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono clearPages(PageRange pageRange) { - return this.clearPages(pageRange, null); - } - - /** - * Frees the specified pages from the page blob. - * For more information, see the - * Azure Docs. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param pageBlobAccessConditions - * {@link PageBlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code pageRange} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.clearPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono clearPages(PageRange pageRange, - PageBlobAccessConditions pageBlobAccessConditions) { - pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() - : pageBlobAccessConditions; - if (pageRange == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("pageRange cannot be null."); - } - String pageRangeStr = pageRangeToString(pageRange); - - return postProcessResponse(this.azureBlobStorage.pageBlobs().clearPagesWithRestResponseAsync(null, - null, 0, null, pageRangeStr, null, - pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), - pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the list of valid page ranges for a page blob or snapshot of a page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.getPageRanges")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRanges(BlobRange blobRange) { - return this.getPageRanges(blobRange, null); - } - - /** - * Returns the list of valid page ranges for a page blob or snapshot of a page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.getPageRanges")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRanges(BlobRange blobRange, - BlobAccessConditions accessConditions) { - blobRange = blobRange == null ? new BlobRange(0) : blobRange; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesWithRestResponseAsync( - null, null, snapshot, null, null, blobRange.toHeaderValue(), - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - } - - /** - * Gets the collection of page ranges that differ between a specified snapshot and this page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param prevSnapshot - * Specifies that the response will contain only pages that were changed between target blob and previous - * snapshot. Changed pages include both updated and cleared pages. The target - * blob may be a snapshot, as long as the snapshot specified by prevsnapshot is the older of the two. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_diff "Sample code for PageBlobAsyncRawClient.getPageRangesDiff")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRangesDiff(BlobRange blobRange, String prevSnapshot) { - return this.getPageRangesDiff(blobRange, prevSnapshot, null); - } - - /** - * Gets the collection of page ranges that differ between a specified snapshot and this page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param prevSnapshot - * Specifies that the response will contain only pages that were changed between target blob and previous - * snapshot. Changed pages include both updated and cleared pages. The target - * blob may be a snapshot, as long as the snapshot specified by prevsnapshot is the older of the two. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code prevSnapshot} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_diff "Sample code for PageBlobAsyncRawClient.getPageRangesDiff")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRangesDiff(BlobRange blobRange, String prevSnapshot, - BlobAccessConditions accessConditions) { - blobRange = blobRange == null ? new BlobRange(0) : blobRange; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - if (prevSnapshot == null) { - throw new IllegalArgumentException("prevSnapshot cannot be null"); - } - - return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesDiffWithRestResponseAsync( - null, null, snapshot, null, null, prevSnapshot, - blobRange.toHeaderValue(), null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Resizes the page blob to the specified size (which must be a multiple of 512). - * For more information, see the Azure Docs. - * - * @param size - * Resizes a page blob to the specified size. If the specified value is less than the current size of the - * blob, then all pages above the specified value are cleared. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.resize")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono resize(long size) { - return this.resize(size, null); - } - - /** - * Resizes the page blob to the specified size (which must be a multiple of 512). - * For more information, see the Azure Docs. - * - * @param size - * Resizes a page blob to the specified size. If the specified value is less than the current size of the - * blob, then all pages above the specified value are cleared. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncRawClient#PAGE_BYTES} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.resize")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono resize(long size, BlobAccessConditions accessConditions) { - if (size % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncRawClient.PAGE_BYTES."); - } - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().resizeWithRestResponseAsync(null, - null, size, null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Sets the page blob's sequence number. - * For more information, see the Azure Docs. - * - * @param action - * Indicates how the service should modify the blob's sequence number. - * @param sequenceNumber - * The blob's sequence number. The sequence number is a user-controlled property that you can use to track - * requests and manage concurrency issues. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.updateSequenceNumber")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber) { - return this.updateSequenceNumber(action, sequenceNumber, null); - } - - /** - * Sets the page blob's sequence number. - * For more information, see the Azure Docs. - * - * @param action - * Indicates how the service should modify the blob's sequence number. - * @param sequenceNumber - * The blob's sequence number. The sequence number is a user-controlled property that you can use to track - * requests and manage concurrency issues. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code sequenceNumber} isn't null and is less than 0 - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.updateSequenceNumber")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber, BlobAccessConditions accessConditions) { - if (sequenceNumber != null && sequenceNumber < 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); - } - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - sequenceNumber = action == SequenceNumberActionType.INCREMENT ? null : sequenceNumber; - - return postProcessResponse( - this.azureBlobStorage.pageBlobs().updateSequenceNumberWithRestResponseAsync(null, - null, action, null, sequenceNumber, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Begins an operation to start an incremental copy from one page blob's snapshot to this page - * blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are - * transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read - * or copied from as usual. For more information, see - * the Azure Docs here and - * here. - * - * @param source - * The source page blob. - * @param snapshot - * The snapshot on the copy source. - * - * @return Emits the successful response. - */ - public Mono copyIncremental(URL source, String snapshot) { - return this.copyIncremental(source, snapshot, null); - } - - /** - * Begins an operation to start an incremental copy from one page blob's snapshot to this page - * blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are - * transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read - * or copied from as usual. For more information, see - * the Azure Docs here and - * here. - * - * @param source - * The source page blob. - * @param snapshot - * The snapshot on the copy source. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws Error If {@code source} and {@code snapshot} form a malformed URL. - */ - public Mono copyIncremental(URL source, String snapshot, - ModifiedAccessConditions modifiedAccessConditions) { - - UrlBuilder builder = UrlBuilder.parse(source); - builder.setQueryParameter(Constants.SNAPSHOT_QUERY_PARAMETER, snapshot); - try { - source = builder.toURL(); - } catch (MalformedURLException e) { - // We are parsing a valid url and adding a query parameter. If this fails, we can't recover. - throw new Error(e); - } - return postProcessResponse(this.azureBlobStorage.pageBlobs().copyIncrementalWithRestResponseAsync( - null, null, source, null, null, modifiedAccessConditions, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java index 284f74d0216ac..62d2146ea8d61 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java @@ -15,13 +15,14 @@ import com.azure.storage.blob.models.PageRange; import com.azure.storage.blob.models.SequenceNumberActionType; import com.azure.storage.blob.models.SourceModifiedAccessConditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import java.io.InputStream; import java.net.URL; -import java.nio.ByteBuffer; import java.time.Duration; /** @@ -45,12 +46,12 @@ public final class PageBlobClient extends BlobClient { /** * Indicates the number of bytes in a page. */ - public static final int PAGE_BYTES = 512; + public static final int PAGE_BYTES = PageBlobAsyncClient.PAGE_BYTES; /** * Indicates the maximum number of bytes that may be sent in a call to putPage. */ - public static final int MAX_PUT_PAGES_BYTES = 4 * Constants.MB; + public static final int MAX_PUT_PAGES_BYTES = PageBlobAsyncClient.MAX_PUT_PAGES_BYTES; /** * Package-private constructor for use by {@link PageBlobClientBuilder}. @@ -189,7 +190,7 @@ public Response uploadPages(PageRange pageRange, InputStream body) public Response uploadPages(PageRange pageRange, InputStream body, PageBlobAccessConditions pageBlobAccessConditions, Duration timeout) { long length = pageRange.end() - pageRange.start(); - Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) PAGE_BYTES)) + Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) PAGE_BYTES)) .map(i -> i * PAGE_BYTES) .concatMap(pos -> Mono.fromCallable(() -> { byte[] cache = new byte[PAGE_BYTES]; @@ -197,7 +198,8 @@ public Response uploadPages(PageRange pageRange, InputStream body, while (read < PAGE_BYTES) { read += body.read(cache, read, PAGE_BYTES - read); } - return ByteBuffer.wrap(cache); + + return ByteBufAllocator.DEFAULT.buffer(read).writeBytes(cache); })); Mono> response = pageBlobAsyncClient.uploadPages(pageRange, diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index d5b0aecc3a3f1..cbb5a91600702 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -8,8 +8,11 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.ContainerItem; +import com.azure.storage.blob.models.KeyInfo; import com.azure.storage.blob.models.ListContainersOptions; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.PublicAccessType; @@ -25,6 +28,8 @@ import java.net.URL; import java.time.OffsetDateTime; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** * Client to a storage account. It may only be instantiated through a {@link StorageClientBuilder}. * This class does not hold any state about a particular storage account but is @@ -47,14 +52,14 @@ * object through {@link Mono#toFuture()}. */ public final class StorageAsyncClient { - StorageAsyncRawClient storageAsyncRawClient; + private final AzureBlobStorageImpl azureBlobStorage; /** * Package-private constructor for use by {@link StorageClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ StorageAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.storageAsyncRawClient = new StorageAsyncRawClient(azureBlobStorageBuilder.build()); + this.azureBlobStorage = azureBlobStorageBuilder.build(); } /** @@ -69,7 +74,7 @@ public final class StorageAsyncClient { public ContainerAsyncClient getContainerAsyncClient(String containerName) { return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getAccountUrl(), containerName).toString()) - .pipeline(storageAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** @@ -111,9 +116,9 @@ public Mono> createContainer(String containerName */ public URL getAccountUrl() { try { - return new URL(storageAsyncRawClient.azureBlobStorage.url()); + return new URL(azureBlobStorage.url()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), storageAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } @@ -139,17 +144,46 @@ public Flux listContainers() { * A reactive response emitting the list of containers. */ public Flux listContainers(ListContainersOptions options) { - return storageAsyncRawClient - .listContainersSegment(null, options) + return listContainersSegment(null, options) .flatMapMany(response -> listContainersHelper(response.value().marker(), options, response)); } + /* + * Returns a Mono segment of containers starting from the specified Marker. + * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. + * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned + * Marker) to get the next segment. For more information, see + * the Azure Docs. + * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. + * @param options + * A {@link ListContainersOptions} which specifies what data should be returned by the service. + * + * @return Emits the successful response. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + */ + private Mono listContainersSegment(String marker, ListContainersOptions options) { + options = options == null ? new ListContainersOptions() : options; + + return postProcessResponse( + this.azureBlobStorage.services().listContainersSegmentWithRestResponseAsync( + options.prefix(), marker, options.maxResults(), options.details().toIncludeType(), null, + null, Context.NONE)); + } + private Flux listContainersHelper(String marker, ListContainersOptions options, ServicesListContainersSegmentResponse response) { Flux result = Flux.fromIterable(response.value().containerItems()); if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(storageAsyncRawClient.listContainersSegment(marker, options) + result = result.concatWith(listContainersSegment(marker, options) .flatMapMany((r) -> listContainersHelper(response.value().nextMarker(), options, r))); } @@ -165,8 +199,8 @@ private Flux listContainersHelper(String marker, ListContainersOp * A reactive response containing the storage account properties. */ public Mono> getProperties() { - return storageAsyncRawClient - .getProperties() + return postProcessResponse( + this.azureBlobStorage.services().getPropertiesWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.value())); } @@ -183,8 +217,8 @@ public Mono> getProperties() { * A reactive response containing the storage account properties. */ public Mono setProperties(StorageServiceProperties properties) { - return storageAsyncRawClient - .setProperties(properties) + return postProcessResponse( + this.azureBlobStorage.services().setPropertiesWithRestResponseAsync(properties, null, null, Context.NONE)) .map(VoidResponse::new); } @@ -197,13 +231,22 @@ public Mono setProperties(StorageServiceProperties properties) { * @param expiry * Expiration of the key's validity. * - * @return - * A reactive response containing the user delegation key. + * @return A reactive response containing the user delegation key. + * @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}. */ public Mono> getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - return storageAsyncRawClient - .getUserDelegationKey(start, expiry) - .map(rb -> new SimpleResponse<>(rb, rb.value())); + Utility.assertNotNull("expiry", expiry); + if (start != null && !start.isBefore(expiry)) { + throw new IllegalArgumentException("`start` must be null or a datetime before `expiry`."); + } + + return postProcessResponse( + this.azureBlobStorage.services().getUserDelegationKeyWithRestResponseAsync( + new KeyInfo() + .start(start == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(start)) + .expiry(Utility.ISO_8601_UTC_DATE_FORMATTER.format(expiry)), + null, null, Context.NONE) + ).map(rb -> new SimpleResponse<>(rb, rb.value())); } /** @@ -216,8 +259,8 @@ public Mono> getUserDelegationKey(OffsetDateTime sta * A reactive response containing the storage account statistics. */ public Mono> getStatistics() { - return storageAsyncRawClient - .getStatistics() + return postProcessResponse( + this.azureBlobStorage.services().getStatisticsWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.value())); } @@ -229,8 +272,7 @@ public Mono> getStatistics() { * A reactive response containing the storage account info. */ public Mono> getAccountInfo() { - return storageAsyncRawClient - .getAccountInfo() + return postProcessResponse(this.azureBlobStorage.services().getAccountInfoWithRestResponseAsync(Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java deleted file mode 100644 index a2b6be965ed30..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.credentials.TokenCredential; -import com.azure.core.http.HttpPipeline; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.KeyInfo; -import com.azure.storage.blob.models.ListContainersOptions; -import com.azure.storage.blob.models.ServicesGetAccountInfoResponse; -import com.azure.storage.blob.models.ServicesGetPropertiesResponse; -import com.azure.storage.blob.models.ServicesGetStatisticsResponse; -import com.azure.storage.blob.models.ServicesGetUserDelegationKeyResponse; -import com.azure.storage.blob.models.ServicesListContainersSegmentResponse; -import com.azure.storage.blob.models.ServicesSetPropertiesResponse; -import com.azure.storage.blob.models.StorageServiceProperties; -import reactor.core.publisher.Mono; - -import java.time.OffsetDateTime; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a storage service. This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. - * Please see here for more - * information on containers. - */ -final class StorageAsyncRawClient { - - final AzureBlobStorageImpl azureBlobStorage; - - /** - * Creates a {@code ServiceURL} object pointing to the account specified by the URL and using the provided pipeline - * to make HTTP requests. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_url "Sample code for ServiceURL constructor")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - StorageAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.azureBlobStorage = azureBlobStorage; - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listContainersSegment(String marker, - ListContainersOptions options) { - options = options == null ? new ListContainersOptions() : options; - - return postProcessResponse( - this.azureBlobStorage.services().listContainersSegmentWithRestResponseAsync( - options.prefix(), marker, options.maxResults(), options.details().toIncludeType(), null, - null, Context.NONE)); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return postProcessResponse( - this.azureBlobStorage.services().getPropertiesWithRestResponseAsync(null, null, Context.NONE)); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setProperties(StorageServiceProperties properties) { - return postProcessResponse( - this.azureBlobStorage.services().setPropertiesWithRestResponseAsync(properties, null, null, Context.NONE)); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link TokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}. - */ - public Mono getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - Utility.assertNotNull("expiry", expiry); - if (start != null && !start.isBefore(expiry)) { - throw new IllegalArgumentException("`start` must be null or a datetime before `expiry`."); - } - - return postProcessResponse( - this.azureBlobStorage.services().getUserDelegationKeyWithRestResponseAsync( - new KeyInfo() - .start(start == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(start)) - .expiry(Utility.ISO_8601_UTC_DATE_FORMATTER.format(expiry)), - null, null, Context.NONE) - ); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getStatistics() { - return postProcessResponse( - this.azureBlobStorage.services().getStatisticsWithRestResponseAsync(null, null, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.services().getAccountInfoWithRestResponseAsync(Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java index f18cf0640fbd9..cc4c6b71c56fa 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java @@ -38,8 +38,7 @@ * information on containers. */ public final class StorageClient { - - private StorageAsyncClient storageAsyncClient; + private final StorageAsyncClient storageAsyncClient; /** * Package-private constructor for use by {@link StorageClientBuilder}. diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java deleted file mode 100644 index cebfdc451ae67..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.HttpPipeline; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.ListContainersOptions; -import com.azure.storage.blob.models.ServicesGetAccountInfoResponse; -import com.azure.storage.blob.models.ServicesGetPropertiesResponse; -import com.azure.storage.blob.models.ServicesGetStatisticsResponse; -import com.azure.storage.blob.models.ServicesGetUserDelegationKeyResponse; -import com.azure.storage.blob.models.ServicesListContainersSegmentResponse; -import com.azure.storage.blob.models.ServicesSetPropertiesResponse; -import com.azure.storage.blob.models.StorageServiceProperties; -import com.azure.storage.common.credentials.SASTokenCredential; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.time.OffsetDateTime; - -/** - * Represents a URL to a storage service. This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. - * Please see here for more - * information on containers. - */ -final class StorageRawClient { - - StorageAsyncRawClient storageAsyncRawClient; - - /** - * Creates a {@code ServiceURL} object pointing to the account specified by the URL and using the provided pipeline - * to make HTTP requests. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_url "Sample code for ServiceURL constructor")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - StorageRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.storageAsyncRawClient = new StorageAsyncRawClient(azureBlobStorage); - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesListContainersSegmentResponse listContainersSegment(String marker, - ListContainersOptions options) { - return this.listContainersSegment(marker, options, null); - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesListContainersSegmentResponse listContainersSegment(String marker, - ListContainersOptions options, Duration timeout) { - Mono response = storageAsyncRawClient.listContainersSegment(marker, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetPropertiesResponse getProperties() { - return this.getProperties(null); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetPropertiesResponse getProperties(Duration timeout) { - Mono response = storageAsyncRawClient.getProperties(); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesSetPropertiesResponse setProperties(StorageServiceProperties properties) { - return this.setProperties(properties, null); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesSetPropertiesResponse setProperties(StorageServiceProperties properties, Duration timeout) { - Mono response = storageAsyncRawClient.setProperties(properties); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link SASTokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - */ - public ServicesGetUserDelegationKeyResponse getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - return this.getUserDelegationKey(start, expiry, null); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link SASTokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - */ - public ServicesGetUserDelegationKeyResponse getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry, - Duration timeout) { - Mono response = storageAsyncRawClient.getUserDelegationKey(start, expiry); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetStatisticsResponse getStatistics() { - return this.getStatistics(null); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetStatisticsResponse getStatistics(Duration timeout) { - Mono response = storageAsyncRawClient.getStatistics(); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetAccountInfoResponse getAccountInfo() { - return this.getAccountInfo(null); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetAccountInfoResponse getAccountInfo(Duration timeout) { - Mono response = storageAsyncRawClient.getAccountInfo(); - return Utility.blockWithOptionalTimeout(response, timeout); - } -} diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java b/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java index 1ac12cbe978da..f6d19d6b84167 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java @@ -8,6 +8,8 @@ import com.azure.storage.blob.models.BlobItem; import com.azure.storage.blob.models.ContainerItem; import com.azure.storage.common.credentials.SharedKeyCredential; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -16,7 +18,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.UUID; @@ -116,8 +117,7 @@ public void asyncSample() throws IOException { for (int i = 0; i < 5; i++) { BlockBlobAsyncClient blobClient = finalContainerClient.getBlockBlobAsyncClient("testblob-" + i); byte[] message = ("test data" + i).getBytes(StandardCharsets.UTF_8); - Flux testdata = Flux.just(ByteBuffer.wrap(message)); - + Flux testdata = Flux.just(ByteBufAllocator.DEFAULT.buffer(message.length).writeBytes(message)); finished = finished.and(blobClient.upload(testdata, message.length) .then(Mono.defer(() -> { From 39ea493812f4a2f9d3f4e5d76c3aa20019ea1452 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Wed, 10 Jul 2019 14:07:24 -0700 Subject: [PATCH 2/9] Added deleteContainer to StorageClient --- .../com/azure/storage/blob/StorageAsyncClient.java | 11 +++++++++++ .../java/com/azure/storage/blob/StorageClient.java | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index cbb5a91600702..4e393eb9cbaf7 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -109,6 +109,17 @@ public Mono> createContainer(String containerName .map(response -> new SimpleResponse<>(response, containerAsyncClient)); } + /** + * Deletes the specified container in the storage account. If the container doesn't exist the operation fails. For + * more information see the Azure Docs. + * + * @param containerName Name of the container to delete + * @return A response containing status code and HTTP headers + */ + public Mono deleteContainer(String containerName) { + return getContainerAsyncClient(containerName).delete(); + } + /** * Gets the URL of the storage account represented by this client. * @return the URL. diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java index cc4c6b71c56fa..763f0fd8a1d9c 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java @@ -92,6 +92,17 @@ public Response createContainer(String containerName, Metadata return new SimpleResponse<>(client.create(metadata, accessType, null), client); } + /** + * Deletes the specified container in the storage account. If the container doesn't exist the operation fails. For + * more information see the Azure Docs. + * + * @param containerName Name of the container to delete + * @return A response containing status code and HTTP headers + */ + public VoidResponse deleteContainer(String containerName) { + return storageAsyncClient.deleteContainer(containerName).block(); + } + /** * Gets the URL of the storage account represented by this client. * @return the URL. From a6f355844ac34aedda3756f780d377a788720721 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 12 Jul 2019 10:55:35 -0700 Subject: [PATCH 3/9] Merged Blob client builders into BlobClientBuilder --- .../storage/blob/AppendBlobAsyncClient.java | 6 +- .../azure/storage/blob/AppendBlobClient.java | 4 +- .../storage/blob/AppendBlobClientBuilder.java | 333 ----------------- .../azure/storage/blob/BlobClientBuilder.java | 83 ++++- .../storage/blob/BlockBlobAsyncClient.java | 4 +- .../azure/storage/blob/BlockBlobClient.java | 4 +- .../storage/blob/BlockBlobClientBuilder.java | 337 ------------------ .../storage/blob/PageBlobAsyncClient.java | 4 +- .../azure/storage/blob/PageBlobClient.java | 4 +- .../storage/blob/PageBlobClientBuilder.java | 333 ----------------- .../com/azure/storage/blob/APISpec.groovy | 10 +- .../com/azure/storage/blob/BlobAPITest.groovy | 7 +- .../storage/blob/ContainerAPITest.groovy | 8 +- 13 files changed, 96 insertions(+), 1041 deletions(-) delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClientBuilder.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClientBuilder.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClientBuilder.java diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index 60376a3d990ab..7275f0fb326fe 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -24,8 +24,8 @@ /** - * Client to an append blob. It may only be instantiated through a {@link AppendBlobClientBuilder#buildAsyncClient()}, via - * the method {@link BlobAsyncClient#asAppendBlobAsyncClient()}, or via the method + * Client to an append blob. It may only be instantiated through a {@link BlobClientBuilder#buildAppendBlobAsyncClient()}, + * via the method {@link BlobAsyncClient#asAppendBlobAsyncClient()}, or via the method * {@link ContainerAsyncClient#getAppendBlobAsyncClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate * requests to the resource on the service. @@ -58,7 +58,7 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient { public static final int MAX_BLOCKS = 50000; /** - * Package-private constructor for use by {@link AppendBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java index 6be2bf7f4e5aa..246fe645af179 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java @@ -23,7 +23,7 @@ /** - * Client to an append blob. It may only be instantiated through a {@link AppendBlobClientBuilder}, via + * Client to an append blob. It may only be instantiated through a {@link BlobClientBuilder}, via * the method {@link BlobClient#asAppendBlobClient()}, or via the method * {@link ContainerClient#getAppendBlobClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate @@ -51,7 +51,7 @@ public final class AppendBlobClient extends BlobClient { public static final int MAX_BLOCKS = AppendBlobAsyncClient.MAX_BLOCKS; /** - * Package-private constructor for use by {@link AppendBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param appendBlobAsyncClient the async append blob client */ AppendBlobClient(AppendBlobAsyncClient appendBlobAsyncClient) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClientBuilder.java deleted file mode 100644 index c46883e7fecf9..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClientBuilder.java +++ /dev/null @@ -1,333 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.credentials.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.http.policy.HttpLoggingPolicy; -import com.azure.core.http.policy.HttpPipelinePolicy; -import com.azure.core.http.policy.RequestIdPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.implementation.util.ImplUtils; -import com.azure.core.util.configuration.Configuration; -import com.azure.core.util.configuration.ConfigurationManager; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; -import com.azure.storage.common.credentials.SASTokenCredential; -import com.azure.storage.common.credentials.SharedKeyCredential; -import com.azure.storage.common.policy.RequestRetryOptions; -import com.azure.storage.common.policy.RequestRetryPolicy; -import com.azure.storage.common.policy.SASTokenCredentialPolicy; -import com.azure.storage.common.policy.SharedKeyCredentialPolicy; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; - -/** - * Fluent AppendBlobClientBuilder for instantiating a {@link AppendBlobClient} or {@link AppendBlobAsyncClient} - * using {@link AppendBlobClientBuilder#buildAsyncClient()} or {@link AppendBlobClientBuilder#buildAsyncClient()} respectively. - * - *

- * The following information must be provided on this builder: - * - *

    - *
  • the endpoint through {@code .endpoint()}, including the container name and blob name, in the format of {@code https://{accountName}.blob.core.windows.net/{containerName}/{blobName}}. - *
  • the credential through {@code .credential()} or {@code .connectionString()} if the container is not publicly accessible. - *
- * - *

- * Once all the configurations are set on this builder, call {@code .buildClient()} to create a - * {@link AppendBlobClient} or {@code .buildAsyncClient()} to create a {@link AppendBlobAsyncClient}. - */ -public final class AppendBlobClientBuilder { - private static final String ACCOUNT_NAME = "accountname"; - private static final String ACCOUNT_KEY = "accountkey"; - private static final String ENDPOINT_PROTOCOL = "defaultendpointsprotocol"; - private static final String ENDPOINT_SUFFIX = "endpointsuffix"; - - private final List policies; - - private String endpoint; - private String containerName; - private String blobName; - private String snapshot; - private SharedKeyCredential sharedKeyCredential; - private TokenCredential tokenCredential; - private SASTokenCredential sasTokenCredential; - private HttpClient httpClient; - private HttpLogDetailLevel logLevel; - private RequestRetryOptions retryOptions; - private Configuration configuration; - - /** - * Creates a builder instance that is able to configure and construct {@link AppendBlobClient AppendBlobClients} - * and {@link AppendBlobAsyncClient AppendBlobAsyncClients}. - */ - public AppendBlobClientBuilder() { - retryOptions = new RequestRetryOptions(); - logLevel = HttpLogDetailLevel.NONE; - policies = new ArrayList<>(); - } - - private AzureBlobStorageBuilder buildImpl() { - Objects.requireNonNull(endpoint); - Objects.requireNonNull(containerName); - Objects.requireNonNull(blobName); - - // Closest to API goes first, closest to wire goes last. - final List policies = new ArrayList<>(); - - if (configuration == null) { - configuration = ConfigurationManager.getConfiguration(); - } - policies.add(new UserAgentPolicy(BlobConfiguration.NAME, BlobConfiguration.VERSION, configuration)); - policies.add(new RequestIdPolicy()); - policies.add(new AddDatePolicy()); - - if (sharedKeyCredential != null) { - policies.add(new SharedKeyCredentialPolicy(sharedKeyCredential)); - } else if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", endpoint))); - } else if (sasTokenCredential != null) { - policies.add(new SASTokenCredentialPolicy(sasTokenCredential)); - } else { - policies.add(new AnonymousCredentialPolicy()); - } - - policies.add(new RequestRetryPolicy(retryOptions)); - - policies.addAll(this.policies); - policies.add(new HttpLoggingPolicy(logLevel)); - - HttpPipeline pipeline = HttpPipeline.builder() - .policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient) - .build(); - - return new AzureBlobStorageBuilder() - .url(String.format("%s/%s/%s", endpoint, containerName, blobName)) - .pipeline(pipeline); - } - - /** - * @return a {@link AppendBlobClient} created from the configurations in this builder. - */ - public AppendBlobClient buildClient() { - return new AppendBlobClient(buildAsyncClient()); - } - - /** - * @return a {@link AppendBlobAsyncClient} created from the configurations in this builder. - */ - public AppendBlobAsyncClient buildAsyncClient() { - return new AppendBlobAsyncClient(buildImpl(), snapshot); - } - - /** - * Sets the service endpoint, additionally parses it for information (SAS token, container name, blob name) - * @param endpoint URL of the service - * @return the updated AppendBlobClientBuilder object - * @throws IllegalArgumentException If {@code endpoint} is a malformed URL or is using an unknown host. - */ - public AppendBlobClientBuilder endpoint(String endpoint) { - Objects.requireNonNull(endpoint); - URL url; - try { - url = new URL(endpoint); - BlobURLParts parts = URLParser.parse(url); - this.endpoint = parts.scheme() + "://" + parts.host(); - - if (parts.containerName() != null) { - this.containerName = parts.containerName(); - } - - if (parts.blobName() != null) { - this.blobName = parts.blobName(); - } - - if (parts.snapshot() != null) { - this.snapshot = parts.snapshot(); - } - } catch (MalformedURLException ex) { - throw new IllegalArgumentException("The Azure Storage Blob endpoint url is malformed."); - } - - SASTokenCredential credential = SASTokenCredential.fromQuery(url.getQuery()); - if (credential != null) { - this.credential(credential); - } - - return this; - } - - /** - * Sets the name of the container this client is connecting to. - * @param containerName the name of the container - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder containerName(String containerName) { - this.containerName = containerName; - return this; - } - - /** - * Sets the name of the blob this client is connecting to. - * @param blobName the name of the blob - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder blobName(String blobName) { - this.blobName = blobName; - return this; - } - - /** - * Sets the snapshot of the blob this client is connecting to. - * @param snapshot the snapshot identifier for the blob - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder snapshot(String snapshot) { - this.snapshot = snapshot; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder credential(SharedKeyCredential credential) { - this.sharedKeyCredential = credential; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder credential(TokenCredential credential) { - this.tokenCredential = credential; - this.sharedKeyCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder credential(SASTokenCredential credential) { - this.sasTokenCredential = credential; - this.sharedKeyCredential = null; - this.tokenCredential = null; - return this; - } - - /** - * Clears the credential used to authorize requests sent to the service - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder anonymousCredential() { - this.sharedKeyCredential = null; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the connection string for the service, parses it for authentication information (account name, account key) - * @param connectionString connection string from access keys section - * @return the updated AppendBlobClientBuilder object - * @throws IllegalArgumentException If {@code connectionString} doesn't contain AccountName or AccountKey. - */ - public AppendBlobClientBuilder connectionString(String connectionString) { - Objects.requireNonNull(connectionString); - - Map connectionKVPs = new HashMap<>(); - for (String s : connectionString.split(";")) { - String[] kvp = s.split("=", 2); - connectionKVPs.put(kvp[0].toLowerCase(Locale.ROOT), kvp[1]); - } - - String accountName = connectionKVPs.get(ACCOUNT_NAME); - String accountKey = connectionKVPs.get(ACCOUNT_KEY); - String endpointProtocol = connectionKVPs.get(ENDPOINT_PROTOCOL); - String endpointSuffix = connectionKVPs.get(ENDPOINT_SUFFIX); - - if (ImplUtils.isNullOrEmpty(accountName) || ImplUtils.isNullOrEmpty(accountKey)) { - throw new IllegalArgumentException("Connection string must contain 'AccountName' and 'AccountKey'."); - } - - if (!ImplUtils.isNullOrEmpty(endpointProtocol) && !ImplUtils.isNullOrEmpty(endpointSuffix)) { - String endpoint = String.format("%s://%s.blob.%s", endpointProtocol, accountName, endpointSuffix.replaceFirst("^\\.", "")); - endpoint(endpoint); - } - - // Use accountName and accountKey to get the SAS token using the credential class. - return credential(new SharedKeyCredential(accountName, accountKey)); - } - - /** - * Sets the http client used to send service requests - * @param httpClient http client to send requests - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Adds a pipeline policy to apply on each request sent - * @param pipelinePolicy a pipeline policy - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { - this.policies.add(pipelinePolicy); - return this; - } - - /** - * Sets the logging level for service requests - * @param logLevel logging level - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder httpLogDetailLevel(HttpLogDetailLevel logLevel) { - this.logLevel = logLevel; - return this; - } - - /** - * Sets the configuration object used to retrieve environment configuration values used to buildClient the client with - * when they are not set in the appendBlobClientBuilder, defaults to Configuration.NONE - * @param configuration configuration store - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder configuration(Configuration configuration) { - this.configuration = configuration; - return this; - } - - /** - * Sets the request retry options for all the requests made through the client. - * @param retryOptions the options to configure retry behaviors - * @return the updated AppendBlobClientBuilder object - */ - public AppendBlobClientBuilder retryOptions(RequestRetryOptions retryOptions) { - this.retryOptions = retryOptions; - return this; - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java index 2238af18e48e9..5141ea6abe772 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java @@ -34,8 +34,7 @@ import java.util.Objects; /** - * Fluent BlobClientBuilder for instantiating a {@link BlobClient} or {@link BlobAsyncClient} - * using {@link BlobClientBuilder#buildClient()} or {@link BlobClientBuilder#buildAsyncClient()} respectively. + * This class provides a fluent builder API to help aid the configuration and instantiation Storage Blob clients. * *

* The following information must be provided on this builder: @@ -46,8 +45,17 @@ * * *

- * Once all the configurations are set on this builder, call {@code .buildClient()} to create a - * {@link BlobClient} or {@code .buildAsyncClient()} to create a {@link BlobAsyncClient}. + * Once all the configurations are set on this builder use the following mapping to construct the given client: + *

    + *
  • {@link BlobClientBuilder#buildBlobClient()} - {@link BlobClient}
  • + *
  • {@link BlobClientBuilder#buildBlobAsyncClient()} - {@link BlobAsyncClient}
  • + *
  • {@link BlobClientBuilder#buildAppendBlobClient()} ()} - {@link AppendBlobClient}
  • + *
  • {@link BlobClientBuilder#buildAppendBlobAsyncClient()} ()} - {@link AppendBlobAsyncClient}
  • + *
  • {@link BlobClientBuilder#buildBlockBlobClient()} ()} - {@link BlockBlobClient}
  • + *
  • {@link BlobClientBuilder#buildBlockBlobAsyncClient()} ()} - {@link BlockBlobAsyncClient}
  • + *
  • {@link BlobClientBuilder#buildPageBlobClient()} ()} - {@link PageBlobClient}
  • + *
  • {@link BlobClientBuilder#buildPageBlobAsyncClient()} ()} - {@link PageBlobAsyncClient}
  • + *
*/ public final class BlobClientBuilder { private static final String ACCOUNT_NAME = "accountname"; @@ -70,8 +78,7 @@ public final class BlobClientBuilder { private Configuration configuration; /** - * Creates a builder instance that is able to configure and construct {@link BlobClient BlobClients} - * and {@link BlobAsyncClient BlobAsyncClients}. + * Creates a builder instance that is able to configure and construct Storage Blob clients. */ public BlobClientBuilder() { retryOptions = new RequestRetryOptions(); @@ -121,18 +128,76 @@ private AzureBlobStorageBuilder buildImpl() { /** * @return a {@link BlobClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. */ - public BlobClient buildClient() { - return new BlobClient(buildAsyncClient()); + public BlobClient buildBlobClient() { + return new BlobClient(buildBlobAsyncClient()); } /** * @return a {@link BlobAsyncClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. */ - public BlobAsyncClient buildAsyncClient() { + public BlobAsyncClient buildBlobAsyncClient() { return new BlobAsyncClient(buildImpl(), snapshot); } + /** + * @return a {@link AppendBlobClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public AppendBlobClient buildAppendBlobClient() { + return new AppendBlobClient(buildAppendBlobAsyncClient()); + } + + /** + * @return a {@link AppendBlobAsyncClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public AppendBlobAsyncClient buildAppendBlobAsyncClient() { + return new AppendBlobAsyncClient(buildImpl(), snapshot); + } + + /** + * @return a {@link BlockBlobClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public BlockBlobClient buildBlockBlobClient() { + return new BlockBlobClient(buildBlockBlobAsyncClient()); + } + + /** + * @return a {@link BlockBlobAsyncClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public BlockBlobAsyncClient buildBlockBlobAsyncClient() { + return new BlockBlobAsyncClient(buildImpl(), snapshot); + } + + /** + * @return a {@link PageBlobClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public PageBlobClient buildPageBlobClient() { + return new PageBlobClient(buildPageBlobAsyncClient()); + } + + /** + * @return a {@link PageBlobAsyncClient} created from the configurations in this builder. + * @throws NullPointerException If {@code endpoint} is {@code null}, {@code containerName} is {@code null}, or + * {@code blobName} is {@code null}. + */ + public PageBlobAsyncClient buildPageBlobAsyncClient() { + return new PageBlobAsyncClient(buildImpl(), snapshot); + } + /** * Sets the service endpoint, additionally parses it for information (SAS token, container name, blob name) * @param endpoint URL of the service diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java index e7d8aa9b0c03d..cdb0a06fa68e2 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java @@ -42,7 +42,7 @@ import static com.azure.storage.blob.Utility.postProcessResponse; /** - * Client to a block blob. It may only be instantiated through a {@link BlockBlobClientBuilder}, via + * Client to a block blob. It may only be instantiated through a {@link BlobClientBuilder}, via * the method {@link BlobAsyncClient#asBlockBlobAsyncClient()}, or via the method * {@link ContainerAsyncClient#getBlockBlobAsyncClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate @@ -84,7 +84,7 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { public static final int MAX_BLOCKS = 50000; /** - * Package-private constructor for use by {@link BlockBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java index ec76f684c1bb4..6af92555c2b00 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java @@ -28,7 +28,7 @@ import java.util.List; /** - * Client to a block blob. It may only be instantiated through a {@link BlockBlobClientBuilder}, via + * Client to a block blob. It may only be instantiated through a {@link BlobClientBuilder}, via * the method {@link BlobClient#asBlockBlobClient()}, or via the method * {@link ContainerClient#getBlockBlobClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate @@ -61,7 +61,7 @@ public final class BlockBlobClient extends BlobClient { public static final int MAX_BLOCKS = BlockBlobAsyncClient.MAX_BLOCKS; /** - * Package-private constructor for use by {@link BlockBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param blockBlobAsyncClient the async block blob client */ BlockBlobClient(BlockBlobAsyncClient blockBlobAsyncClient) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClientBuilder.java deleted file mode 100644 index 4774228c27648..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClientBuilder.java +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.credentials.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.http.policy.HttpLoggingPolicy; -import com.azure.core.http.policy.HttpPipelinePolicy; -import com.azure.core.http.policy.RequestIdPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.implementation.util.ImplUtils; -import com.azure.core.util.configuration.Configuration; -import com.azure.core.util.configuration.ConfigurationManager; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; -import com.azure.storage.common.credentials.SASTokenCredential; -import com.azure.storage.common.credentials.SharedKeyCredential; -import com.azure.storage.common.policy.RequestRetryOptions; -import com.azure.storage.common.policy.RequestRetryPolicy; -import com.azure.storage.common.policy.SASTokenCredentialPolicy; -import com.azure.storage.common.policy.SharedKeyCredentialPolicy; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; - -/** - * Fluent BlockBlobClientBuilder for instantiating a {@link BlockBlobClient} or {@link BlockBlobAsyncClient} - * using {@link BlockBlobClientBuilder#buildClient()} or {@link BlockBlobClientBuilder#buildAsyncClient()} respectively. - * - *

- * The following information must be provided on this builder: - * - *

    - *
  • the endpoint through {@code .endpoint()}, including the container name and blob name, in the format of {@code https://{accountName}.blob.core.windows.net/{containerName}/{blobName}}. - *
  • the credential through {@code .credential()} or {@code .connectionString()} if the container is not publicly accessible. - *
- * - *

- * Once all the configurations are set on this builder, call {@code .buildClient()} to create a - * {@link BlockBlobClient} or {@code .buildAsyncClient()} to create a {@link BlockBlobAsyncClient}. - */ -public final class BlockBlobClientBuilder { - private static final String ACCOUNT_NAME = "accountname"; - private static final String ACCOUNT_KEY = "accountkey"; - private static final String ENDPOINT_PROTOCOL = "defaultendpointsprotocol"; - private static final String ENDPOINT_SUFFIX = "endpointsuffix"; - - private final List policies; - - private String endpoint; - private String containerName; - private String blobName; - private String snapshot; - private SharedKeyCredential sharedKeyCredential; - private TokenCredential tokenCredential; - private SASTokenCredential sasTokenCredential; - private HttpClient httpClient; - private HttpLogDetailLevel logLevel; - private RequestRetryOptions retryOptions; - private Configuration configuration; - - /** - * Creates a builder instance that is able to configure and construct {@link BlockBlobClient BlockBlobClients} - * and {@link BlockBlobAsyncClient BlockBlobAsyncClients}. - */ - public BlockBlobClientBuilder() { - retryOptions = new RequestRetryOptions(); - logLevel = HttpLogDetailLevel.NONE; - policies = new ArrayList<>(); - } - - /** - * Constructs an instance of BlockBlobAsyncClient based on the configurations stored in the appendBlobClientBuilder. - * @return a new client instance - */ - private AzureBlobStorageBuilder buildImpl() { - Objects.requireNonNull(endpoint); - Objects.requireNonNull(containerName); - Objects.requireNonNull(blobName); - - // Closest to API goes first, closest to wire goes last. - final List policies = new ArrayList<>(); - - if (configuration == null) { - configuration = ConfigurationManager.getConfiguration(); - } - policies.add(new UserAgentPolicy(BlobConfiguration.NAME, BlobConfiguration.VERSION, configuration)); - policies.add(new RequestIdPolicy()); - policies.add(new AddDatePolicy()); - - if (sharedKeyCredential != null) { - policies.add(new SharedKeyCredentialPolicy(sharedKeyCredential)); - } else if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", endpoint))); - } else if (sasTokenCredential != null) { - policies.add(new SASTokenCredentialPolicy(sasTokenCredential)); - } else { - policies.add(new AnonymousCredentialPolicy()); - } - - policies.add(new RequestRetryPolicy(retryOptions)); - - policies.addAll(this.policies); - policies.add(new HttpLoggingPolicy(logLevel)); - - HttpPipeline pipeline = HttpPipeline.builder() - .policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient) - .build(); - - return new AzureBlobStorageBuilder() - .url(String.format("%s/%s/%s", endpoint, containerName, blobName)) - .pipeline(pipeline); - } - - /** - * @return a {@link BlockBlobClient} created from the configurations in this builder. - */ - public BlockBlobClient buildClient() { - return new BlockBlobClient(buildAsyncClient()); - } - - /** - * @return a {@link BlockBlobAsyncClient} created from the configurations in this builder. - */ - public BlockBlobAsyncClient buildAsyncClient() { - return new BlockBlobAsyncClient(buildImpl(), snapshot); - } - - /** - * Sets the service endpoint, additionally parses it for information (SAS token, container name, blob name) - * @param endpoint URL of the service - * @return the updated BlockBlobClientBuilder object - * @throws IllegalArgumentException If {@code endpoint} is a malformed URL. - */ - public BlockBlobClientBuilder endpoint(String endpoint) { - Objects.requireNonNull(endpoint); - URL url; - try { - url = new URL(endpoint); - BlobURLParts parts = URLParser.parse(url); - this.endpoint = parts.scheme() + "://" + parts.host(); - - if (parts.containerName() != null) { - this.containerName = parts.containerName(); - } - - if (parts.blobName() != null) { - this.blobName = parts.blobName(); - } - - if (parts.snapshot() != null) { - this.snapshot = parts.snapshot(); - } - } catch (MalformedURLException ex) { - throw new IllegalArgumentException("The Azure Storage Blob endpoint url is malformed."); - } - - SASTokenCredential credential = SASTokenCredential.fromQuery(url.getQuery()); - if (credential != null) { - this.credential(credential); - } - - return this; - } - - /** - * Sets the name of the container this client is connecting to. - * @param containerName the name of the container - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder containerName(String containerName) { - this.containerName = containerName; - return this; - } - - /** - * Sets the name of the blob this client is connecting to. - * @param blobName the name of the blob - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder blobName(String blobName) { - this.blobName = blobName; - return this; - } - - /** - * Sets the snapshot of the blob this client is connecting to. - * @param snapshot the snapshot identifier for the blob - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder snapshot(String snapshot) { - this.snapshot = snapshot; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder credential(SharedKeyCredential credential) { - this.sharedKeyCredential = credential; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder credential(TokenCredential credential) { - this.tokenCredential = credential; - this.sharedKeyCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder credential(SASTokenCredential credential) { - this.sasTokenCredential = credential; - this.sharedKeyCredential = null; - this.tokenCredential = null; - return this; - } - - /** - * Clears the credential used to authorize requests sent to the service - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder anonymousCredential() { - this.sharedKeyCredential = null; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the connection string for the service, parses it for authentication information (account name, account key) - * @param connectionString connection string from access keys section - * @return the updated BlockBlobClientBuilder object - * @throws IllegalArgumentException If {@code connectionString} doesn't contain AccountName or AccountKey - */ - public BlockBlobClientBuilder connectionString(String connectionString) { - Objects.requireNonNull(connectionString); - - Map connectionKVPs = new HashMap<>(); - for (String s : connectionString.split(";")) { - String[] kvp = s.split("=", 2); - connectionKVPs.put(kvp[0].toLowerCase(Locale.ROOT), kvp[1]); - } - - String accountName = connectionKVPs.get(ACCOUNT_NAME); - String accountKey = connectionKVPs.get(ACCOUNT_KEY); - String endpointProtocol = connectionKVPs.get(ENDPOINT_PROTOCOL); - String endpointSuffix = connectionKVPs.get(ENDPOINT_SUFFIX); - - if (ImplUtils.isNullOrEmpty(accountName) || ImplUtils.isNullOrEmpty(accountKey)) { - throw new IllegalArgumentException("Connection string must contain 'AccountName' and 'AccountKey'."); - } - - if (!ImplUtils.isNullOrEmpty(endpointProtocol) && !ImplUtils.isNullOrEmpty(endpointSuffix)) { - String endpoint = String.format("%s://%s.blob.%s", endpointProtocol, accountName, endpointSuffix.replaceFirst("^\\.", "")); - endpoint(endpoint); - } - - // Use accountName and accountKey to get the SAS token using the credential class. - return credential(new SharedKeyCredential(accountName, accountKey)); - } - - /** - * Sets the http client used to send service requests - * @param httpClient http client to send requests - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Adds a pipeline policy to apply on each request sent - * @param pipelinePolicy a pipeline policy - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { - this.policies.add(pipelinePolicy); - return this; - } - - /** - * Sets the logging level for service requests - * @param logLevel logging level - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder httpLogDetailLevel(HttpLogDetailLevel logLevel) { - this.logLevel = logLevel; - return this; - } - - /** - * Sets the configuration object used to retrieve environment configuration values used to buildClient the client with - * when they are not set in the appendBlobClientBuilder, defaults to Configuration.NONE - * @param configuration configuration store - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder configuration(Configuration configuration) { - this.configuration = configuration; - return this; - } - - /** - * Sets the request retry options for all the requests made through the client. - * @param retryOptions the options to configure retry behaviors - * @return the updated BlockBlobClientBuilder object - */ - public BlockBlobClientBuilder retryOptions(RequestRetryOptions retryOptions) { - this.retryOptions = retryOptions; - return this; - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index 72f052fd27573..925f167b2ad91 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -29,7 +29,7 @@ import static com.azure.storage.blob.Utility.postProcessResponse; /** - * Client to a page blob. It may only be instantiated through a {@link PageBlobClientBuilder}, via + * Client to a page blob. It may only be instantiated through a {@link BlobClientBuilder}, via * the method {@link BlobAsyncClient#asPageBlobAsyncClient()}, or via the method * {@link ContainerAsyncClient#getPageBlobAsyncClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate @@ -63,7 +63,7 @@ public final class PageBlobAsyncClient extends BlobAsyncClient { public static final int MAX_PUT_PAGES_BYTES = 4 * Constants.MB; /** - * Package-private constructor for use by {@link PageBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param azureBlobStorageBuilder the API client builder for blob storage API */ PageBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java index 62d2146ea8d61..14c0ea4644ded 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java @@ -26,7 +26,7 @@ import java.time.Duration; /** - * Client to a page blob. It may only be instantiated through a {@link PageBlobClientBuilder}, via + * Client to a page blob. It may only be instantiated through a {@link BlobClientBuilder}, via * the method {@link BlobClient#asPageBlobClient()}, or via the method * {@link ContainerClient#getPageBlobClient(String)}. This class does not hold * any state about a particular blob, but is instead a convenient way of sending appropriate @@ -54,7 +54,7 @@ public final class PageBlobClient extends BlobClient { public static final int MAX_PUT_PAGES_BYTES = PageBlobAsyncClient.MAX_PUT_PAGES_BYTES; /** - * Package-private constructor for use by {@link PageBlobClientBuilder}. + * Package-private constructor for use by {@link BlobClientBuilder}. * @param pageBlobAsyncClient the async page blob client */ PageBlobClient(PageBlobAsyncClient pageBlobAsyncClient) { diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClientBuilder.java deleted file mode 100644 index 77010e0607f84..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClientBuilder.java +++ /dev/null @@ -1,333 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.credentials.TokenCredential; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.policy.AddDatePolicy; -import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; -import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.http.policy.HttpLoggingPolicy; -import com.azure.core.http.policy.HttpPipelinePolicy; -import com.azure.core.http.policy.RequestIdPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.implementation.util.ImplUtils; -import com.azure.core.util.configuration.Configuration; -import com.azure.core.util.configuration.ConfigurationManager; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; -import com.azure.storage.common.credentials.SASTokenCredential; -import com.azure.storage.common.credentials.SharedKeyCredential; -import com.azure.storage.common.policy.RequestRetryOptions; -import com.azure.storage.common.policy.RequestRetryPolicy; -import com.azure.storage.common.policy.SASTokenCredentialPolicy; -import com.azure.storage.common.policy.SharedKeyCredentialPolicy; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; - -/** - * Fluent PageBlobClientBuilder for instantiating a {@link PageBlobClient} or {@link PageBlobAsyncClient} - * using {@link PageBlobClientBuilder#buildClient()} or {@link PageBlobClientBuilder#buildAsyncClient()} respectively. - * - *

- * The following information must be provided on this builder: - * - *

    - *
  • the endpoint through {@code .endpoint()}, including the container name and blob name, in the format of {@code https://{accountName}.blob.core.windows.net/{containerName}/{blobName}}. - *
  • the credential through {@code .credential()} or {@code .connectionString()} if the container is not publicly accessible. - *
- * - *

- * Once all the configurations are set on this builder, call {@code .buildClient()} to create a - * {@link PageBlobClient} or {@code .buildAsyncClient()} to create a {@link PageBlobAsyncClient}. - */ -public final class PageBlobClientBuilder { - private static final String ACCOUNT_NAME = "accountname"; - private static final String ACCOUNT_KEY = "accountkey"; - private static final String ENDPOINT_PROTOCOL = "defaultendpointsprotocol"; - private static final String ENDPOINT_SUFFIX = "endpointsuffix"; - - private final List policies; - - private String endpoint; - private String containerName; - private String blobName; - private String snapshot; - private SharedKeyCredential sharedKeyCredential; - private TokenCredential tokenCredential; - private SASTokenCredential sasTokenCredential; - private HttpClient httpClient; - private HttpLogDetailLevel logLevel; - private RequestRetryOptions retryOptions; - private Configuration configuration; - - /** - * Creates a builder instance that is able to configure and construct {@link PageBlobClient PageBlobClients} - * and {@link PageBlobAsyncClient PageBlobAsyncClients}. - */ - public PageBlobClientBuilder() { - retryOptions = new RequestRetryOptions(); - logLevel = HttpLogDetailLevel.NONE; - policies = new ArrayList<>(); - } - - private AzureBlobStorageBuilder buildImpl() { - Objects.requireNonNull(endpoint); - Objects.requireNonNull(containerName); - Objects.requireNonNull(blobName); - - // Closest to API goes first, closest to wire goes last. - final List policies = new ArrayList<>(); - - if (configuration == null) { - configuration = ConfigurationManager.getConfiguration(); - } - policies.add(new UserAgentPolicy(BlobConfiguration.NAME, BlobConfiguration.VERSION, configuration)); - policies.add(new RequestIdPolicy()); - policies.add(new AddDatePolicy()); - - if (sharedKeyCredential != null) { - policies.add(new SharedKeyCredentialPolicy(sharedKeyCredential)); - } else if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", endpoint))); - } else if (sasTokenCredential != null) { - policies.add(new SASTokenCredentialPolicy(sasTokenCredential)); - } else { - policies.add(new AnonymousCredentialPolicy()); - } - - policies.add(new RequestRetryPolicy(retryOptions)); - - policies.addAll(this.policies); - policies.add(new HttpLoggingPolicy(logLevel)); - - HttpPipeline pipeline = HttpPipeline.builder() - .policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient) - .build(); - - return new AzureBlobStorageBuilder() - .url(String.format("%s/%s/%s", endpoint, containerName, blobName)) - .pipeline(pipeline); - } - - /** - * @return a {@link PageBlobClient} created from the configurations in this builder. - */ - public PageBlobClient buildClient() { - return new PageBlobClient(buildAsyncClient()); - } - - /** - * @return a {@link PageBlobAsyncClient} created from the configurations in this builder. - */ - public PageBlobAsyncClient buildAsyncClient() { - return new PageBlobAsyncClient(buildImpl(), snapshot); - } - - /** - * Sets the service endpoint, additionally parses it for information (SAS token, container name, blob name) - * @param endpoint URL of the service - * @return the updated PageBlobClientBuilder object - * @throws IllegalArgumentException If {@code endpoint} is a malformed URL. - */ - public PageBlobClientBuilder endpoint(String endpoint) { - Objects.requireNonNull(endpoint); - URL url; - try { - url = new URL(endpoint); - BlobURLParts parts = URLParser.parse(url); - this.endpoint = parts.scheme() + "://" + parts.host(); - - if (parts.containerName() != null) { - this.containerName = parts.containerName(); - } - - if (parts.blobName() != null) { - this.blobName = parts.blobName(); - } - - if (parts.snapshot() != null) { - this.snapshot = parts.snapshot(); - } - } catch (MalformedURLException ex) { - throw new IllegalArgumentException("The Azure Storage Blob endpoint url is malformed."); - } - - SASTokenCredential credential = SASTokenCredential.fromQuery(url.getQuery()); - if (credential != null) { - this.credential(credential); - } - - return this; - } - - /** - * Sets the name of the container this client is connecting to. - * @param containerName the name of the container - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder containerName(String containerName) { - this.containerName = containerName; - return this; - } - - /** - * Sets the name of the blob this client is connecting to. - * @param blobName the name of the blob - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder blobName(String blobName) { - this.blobName = blobName; - return this; - } - - /** - * Sets the snapshot of the blob this client is connecting to. - * @param snapshot the snapshot identifier for the blob - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder snapshot(String snapshot) { - this.snapshot = snapshot; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder credential(SharedKeyCredential credential) { - this.sharedKeyCredential = credential; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder credential(TokenCredential credential) { - this.tokenCredential = credential; - this.sharedKeyCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the credential used to authorize requests sent to the service - * @param credential authorization credential - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder credential(SASTokenCredential credential) { - this.sasTokenCredential = credential; - this.sharedKeyCredential = null; - this.tokenCredential = null; - return this; - } - - /** - * Clears the credential used to authorize requests sent to the service - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder anonymousCredential() { - this.sharedKeyCredential = null; - this.tokenCredential = null; - this.sasTokenCredential = null; - return this; - } - - /** - * Sets the connection string for the service, parses it for authentication information (account name, account key) - * @param connectionString connection string from access keys section - * @return the updated PageBlobClientBuilder object - * @throws IllegalArgumentException If {@code connectionString} doesn't contain AccountName or AccountKey - */ - public PageBlobClientBuilder connectionString(String connectionString) { - Objects.requireNonNull(connectionString); - - Map connectionKVPs = new HashMap<>(); - for (String s : connectionString.split(";")) { - String[] kvp = s.split("=", 2); - connectionKVPs.put(kvp[0].toLowerCase(Locale.ROOT), kvp[1]); - } - - String accountName = connectionKVPs.get(ACCOUNT_NAME); - String accountKey = connectionKVPs.get(ACCOUNT_KEY); - String endpointProtocol = connectionKVPs.get(ENDPOINT_PROTOCOL); - String endpointSuffix = connectionKVPs.get(ENDPOINT_SUFFIX); - - if (ImplUtils.isNullOrEmpty(accountName) || ImplUtils.isNullOrEmpty(accountKey)) { - throw new IllegalArgumentException("Connection string must contain 'AccountName' and 'AccountKey'."); - } - - if (!ImplUtils.isNullOrEmpty(endpointProtocol) && !ImplUtils.isNullOrEmpty(endpointSuffix)) { - String endpoint = String.format("%s://%s.blob.%s", endpointProtocol, accountName, endpointSuffix.replaceFirst("^\\.", "")); - endpoint(endpoint); - } - - // Use accountName and accountKey to get the SAS token using the credential class. - return credential(new SharedKeyCredential(accountName, accountKey)); - } - - /** - * Sets the http client used to send service requests - * @param httpClient http client to send requests - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder httpClient(HttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - - /** - * Adds a pipeline policy to apply on each request sent - * @param pipelinePolicy a pipeline policy - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { - this.policies.add(pipelinePolicy); - return this; - } - - /** - * Sets the logging level for service requests - * @param logLevel logging level - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder httpLogDetailLevel(HttpLogDetailLevel logLevel) { - this.logLevel = logLevel; - return this; - } - - /** - * Sets the configuration object used to retrieve environment configuration values used to buildClient the client with - * when they are not set in the appendBlobClientBuilder, defaults to Configuration.NONE - * @param configuration configuration store - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder configuration(Configuration configuration) { - this.configuration = configuration; - return this; - } - - /** - * Sets the request retry options for all the requests made through the client. - * @param retryOptions the options to configure retry behaviors - * @return the updated PageBlobClientBuilder object - */ - public PageBlobClientBuilder retryOptions(RequestRetryOptions retryOptions) { - this.retryOptions = retryOptions; - return this; - } -} diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/APISpec.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/APISpec.groovy index c59095e5f66c6..fb306c17ff358 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/APISpec.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/APISpec.groovy @@ -7,10 +7,8 @@ import com.azure.core.http.* import com.azure.core.http.policy.HttpLogDetailLevel import com.azure.core.http.policy.HttpPipelinePolicy import com.azure.core.http.rest.Response -import com.azure.core.util.Context import com.azure.core.util.configuration.ConfigurationManager import com.azure.identity.credential.EnvironmentCredential -import com.azure.storage.blob.BlobProperties import com.azure.storage.blob.models.* import com.azure.storage.common.credentials.SharedKeyCredential import org.junit.Assume @@ -42,8 +40,6 @@ class APISpec extends Specification { static final ByteBuffer defaultData = ByteBuffer.wrap(defaultText.getBytes(StandardCharsets.UTF_8)) - static final Flux defaultFlux = Flux.just(defaultData) - static final Supplier defaultInputStream = new Supplier() { @Override InputStream get() { @@ -112,10 +108,6 @@ class APISpec extends Specification { */ static final String defaultContextKey = "Key" - static final String defaultContextValue = "Value" - - static final Context defaultContext = new Context(defaultContextKey, defaultContextValue) - static String getTestName(ISpecificationContext ctx) { return ctx.getCurrentFeature().name.replace(' ', '').toLowerCase() } @@ -271,11 +263,13 @@ class APISpec extends Specification { } catch (Exception e) { } + try { blobStorageServiceURL = getGenericServiceURL(getGenericCreds("BLOB_STORAGE_")) } catch (Exception e) { } + try { premiumServiceURL = getGenericServiceURL(getGenericCreds("PREMIUM_STORAGE_")) } diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy index 0cf250d85d174..d0be4d532642a 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy @@ -7,7 +7,6 @@ import com.azure.core.http.HttpHeaders import com.azure.core.http.rest.Response import com.azure.core.http.rest.VoidResponse import com.azure.core.implementation.util.ImplUtils -import com.azure.storage.blob.BlobProperties import com.azure.storage.blob.models.* import spock.lang.Unroll @@ -241,7 +240,7 @@ class BlobAPITest extends APISpec { .endpoint(bu.getBlobUrl().toString()) .snapshot(snapshot) .credential(primaryCreds) - .buildClient() + .buildBlobClient() ByteArrayOutputStream snapshotStream = new ByteArrayOutputStream() bu3.download(snapshotStream) snapshotStream.toByteArray() == originalStream.toByteArray() @@ -987,7 +986,7 @@ class BlobAPITest extends APISpec { .endpoint(bu.getBlobUrl().toString()) .credential(primaryCreds) .snapshot(snapshotResponse.value()) - .buildClient() + .buildBlobClient() then: bu2.getProperties().statusCode() == 200 @@ -1015,7 +1014,7 @@ class BlobAPITest extends APISpec { .endpoint(bu.getBlobUrl().toString()) .credential(primaryCreds) .snapshot(response.value()) - .buildClient() + .buildBlobClient() expect: response.statusCode() == 201 diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy index 9b28d87cd7b31..86da9838d53bb 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy @@ -1539,11 +1539,11 @@ class ContainerAPITest extends APISpec { cu.create() } - AppendBlobClient bu = new AppendBlobClientBuilder() + AppendBlobClient bu = new BlobClientBuilder() .credential(primaryCreds) .endpoint("http://" + primaryCreds.accountName() + ".blob.core.windows.net/\$root/rootblob") .httpClient(getHttpClient()) - .buildClient() + .buildAppendBlobClient() when: Response createResponse = bu.create() @@ -1565,11 +1565,11 @@ class ContainerAPITest extends APISpec { cu.create() } - AppendBlobClient bu = new AppendBlobClientBuilder() + AppendBlobClient bu = new BlobClientBuilder() .credential(primaryCreds) .endpoint("http://" + primaryCreds.accountName() + ".blob.core.windows.net/rootblob") .httpClient(getHttpClient()) - .buildClient() + .buildAppendBlobClient() when: Response createResponse = bu.create() From 1ec9438d210a125ec9b265c121a9b70c217e5922 Mon Sep 17 00:00:00 2001 From: Gauri Prasad <51212198+gapra-msft@users.noreply.github.com> Date: Fri, 12 Jul 2019 11:57:48 -0700 Subject: [PATCH 4/9] Storage SAS implementation (#4404) * SAS implementation * Fixed some minor formatting issues * Fixed checkstyle problems and test issue --- .../azure/storage/blob/BlobAsyncClient.java | 259 ++++ .../com/azure/storage/blob/BlobClient.java | 207 ++++ .../com/azure/storage/blob/Constants.java | 15 + .../storage/blob/ContainerAsyncClient.java | 231 ++++ .../azure/storage/blob/ContainerClient.java | 188 +++ .../storage/blob/SASQueryParameters.java | 4 +- .../blob/ServiceSASSignatureValues.java | 182 +-- .../storage/blob/StorageAsyncClient.java | 70 ++ .../com/azure/storage/blob/StorageClient.java | 49 + .../java/com/azure/storage/blob/Utility.java | 23 + .../credentials/SASTokenCredential.java | 96 +- .../policy/SharedKeyCredentialPolicy.java | 9 + .../com/azure/storage/blob/SASTest.groovy | 1079 +++++++++++++++++ 13 files changed, 2315 insertions(+), 97 deletions(-) create mode 100644 storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index 7ec72ecf30b53..5042f9e782af5 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -21,6 +21,8 @@ import com.azure.storage.blob.models.ModifiedAccessConditions; import com.azure.storage.blob.models.ReliableDownloadOptions; import com.azure.storage.blob.models.StorageAccountInfo; +import com.azure.storage.blob.models.UserDelegationKey; +import com.azure.storage.common.credentials.SharedKeyCredential; import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,6 +37,7 @@ import java.nio.channels.AsynchronousFileChannel; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; +import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; @@ -774,4 +777,260 @@ public Mono> getAccountInfo() { .getAccountInfo() .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } + + /** + * Generates a user delegation SAS with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime) { + return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null /* + startTime */, null /* version */, null /*sasProtocol */, null /* ipRange */, null /* cacheControl */, null + /*contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { + return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, + version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /* + contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { + + ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, + startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, null /* identifier*/, + cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + + ServiceSASSignatureValues values = configureServiceSASSignatureValues(serviceSASSignatureValues, accountName); + + SASQueryParameters sasQueryParameters = values.generateSASQueryParameters(userDelegationKey); + + return sasQueryParameters.encode(); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(BlobSASPermission permissions, OffsetDateTime expiryTime) { + return this.generateSAS(null, permissions, expiryTime, null /* startTime */, /* identifier */ null /* + version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /* contentLanguage*/, + null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier) { + return this.generateSAS(identifier, null /* permissions */, null /* expiryTime */, null /* startTime */, + null /* version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /* + contentLanguage*/, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + return this.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null + /* cacheControl */, null /* contentLanguage*/, null /* contentEncoding */, null /* contentLanguage */, + null /* contentType */); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + + ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, + startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, identifier, + cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + + SharedKeyCredential sharedKeyCredential = + Utility.getSharedKeyCredential(this.blobAsyncRawClient.azureBlobStorage.httpPipeline()); + + Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); + + ServiceSASSignatureValues values = configureServiceSASSignatureValues(serviceSASSignatureValues, + sharedKeyCredential.accountName()); + + SASQueryParameters sasQueryParameters = values.generateSASQueryParameters(sharedKeyCredential); + + return sasQueryParameters.encode(); + } + + /** + * Sets serviceSASSignatureValues parameters dependent on the current blob type + */ + ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignatureValues serviceSASSignatureValues, + String accountName) { + + // Set canonical name + serviceSASSignatureValues.canonicalName(this.blobAsyncRawClient.azureBlobStorage.url(), accountName); + + // Set snapshotId + serviceSASSignatureValues.snapshotId(getSnapshotId()); + + // Set resource + if (isSnapshot()) { + serviceSASSignatureValues.resource(Constants.UrlConstants.SAS_BLOB_SNAPSHOT_CONSTANT); + } else { + serviceSASSignatureValues.resource(Constants.UrlConstants.SAS_BLOB_CONSTANT); + } + + return serviceSASSignatureValues; + } + + /** + * Gets the snapshotId for a blob resource + * + * @return + * A string that represents the snapshotId of the snapshot blob + */ + public String getSnapshotId() { + return this.blobAsyncRawClient.snapshot; + } + + /** + * Determines if a blob is a snapshot + * + * @return + * A boolean that indicates if a blob is a snapshot + */ + public boolean isSnapshot() { + return this.blobAsyncRawClient.snapshot != null; + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java index f47c3cf6d7830..21a2212713f5c 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java @@ -16,6 +16,7 @@ import com.azure.storage.blob.models.ModifiedAccessConditions; import com.azure.storage.blob.models.ReliableDownloadOptions; import com.azure.storage.blob.models.StorageAccountInfo; +import com.azure.storage.blob.models.UserDelegationKey; import reactor.core.publisher.Mono; import java.io.IOException; @@ -23,6 +24,7 @@ import java.io.UncheckedIOException; import java.net.URL; import java.time.Duration; +import java.time.OffsetDateTime; /** * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} or via @@ -800,4 +802,209 @@ public Response getAccountInfo(Duration timeout) { return Utility.blockWithOptionalTimeout(response, timeout); } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime) { + return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { + return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, + startTime, version, sasProtocol, ipRange); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { + return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, + startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, + contentLanguage, contentType); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(OffsetDateTime expiryTime, BlobSASPermission permissions) { + return this.blobAsyncClient.generateSAS(permissions, expiryTime); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier) { + return this.blobAsyncClient.generateSAS(identifier); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + return this.blobAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, + ipRange); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + return this.blobAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, + ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + } + + /** + * Gets the snapshotId for a blob resource + * + * @return + * A string that represents the snapshotId of the snapshot blob + */ + public String getSnapshotId() { + return this.blobAsyncClient.getSnapshotId(); + } + + /** + * Determines if a blob is a snapshot + * + * @return + * A boolean that indicates if a blob is a snapshot + */ + public boolean isSnapshot() { + return this.blobAsyncClient.isSnapshot(); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/Constants.java b/storage/client/blob/src/main/java/com/azure/storage/blob/Constants.java index 653625b572c15..fa812df4b531b 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/Constants.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/Constants.java @@ -288,6 +288,21 @@ static final class UrlConstants { */ public static final String SAS_SIGNED_KEY_VERSION = "skv"; + /** + * The SAS blob constant. + */ + public static final String SAS_BLOB_CONSTANT = "b"; + + /** + * The SAS blob snapshot constant. + */ + public static final String SAS_BLOB_SNAPSHOT_CONSTANT = "bs"; + + /** + * The SAS blob snapshot constant. + */ + public static final String SAS_CONTAINER_CONSTANT = "c"; + private UrlConstants() { // Private to prevent construction. } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 406a7440b0c5b..f979f084ac151 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -24,12 +24,15 @@ import com.azure.storage.blob.models.PublicAccessType; import com.azure.storage.blob.models.SignedIdentifier; import com.azure.storage.blob.models.StorageAccountInfo; +import com.azure.storage.blob.models.UserDelegationKey; +import com.azure.storage.common.credentials.SharedKeyCredential; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; +import java.time.OffsetDateTime; import java.util.List; /** @@ -878,4 +881,232 @@ public Mono> getAccountInfo() { .getAccountInfo() .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } + + /** + * Generates a user delegation SAS with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime) { + return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null /* + startTime */, null /* version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null + /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { + return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, + version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /* + contentEncoding */, null /* contentLanguage */, null /* contentType */); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { + ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, + startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, null /* identifier*/, + cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + + ServiceSASSignatureValues values = configureServiceSASSignatureValues(serviceSASSignatureValues, accountName); + + SASQueryParameters sasQueryParameters = values.generateSASQueryParameters(userDelegationKey); + + return sasQueryParameters.encode(); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(ContainerSASPermission permissions, OffsetDateTime expiryTime) { + return this.generateSAS(null, permissions, /* identifier */ expiryTime, null /* startTime */, null /* version + */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /* contentDisposition */, + null /* contentEncoding */, null /* contentLanguage */, null /*contentType*/); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier) { + return this.generateSAS(identifier, null /* permissions*/, null /* expiryTime */, null /* startTime */, null + /* version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null /* + contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /*contentType*/); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, + String version, SASProtocol sasProtocol, IPRange ipRange) { + return this.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null + /* cacheControl */, null /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, + null /*contentType*/); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, + startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, identifier, + cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + + SharedKeyCredential sharedKeyCredential = + Utility.getSharedKeyCredential(this.containerAsyncRawClient.azureBlobStorage.httpPipeline()); + + Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); + + ServiceSASSignatureValues values = configureServiceSASSignatureValues(serviceSASSignatureValues, + sharedKeyCredential.accountName()); + + SASQueryParameters sasQueryParameters = values.generateSASQueryParameters(sharedKeyCredential); + + return sasQueryParameters.encode(); + } + + /** + * Sets serviceSASSignatureValues parameters dependent on the current blob type + */ + private ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignatureValues serviceSASSignatureValues, String accountName) { + // Set canonical name + serviceSASSignatureValues.canonicalName(this.containerAsyncRawClient.azureBlobStorage.url(), accountName); + + // Set snapshotId to null + serviceSASSignatureValues.snapshotId(null); + + // Set resource + serviceSASSignatureValues.resource(Constants.UrlConstants.SAS_CONTAINER_CONSTANT); + return serviceSASSignatureValues; + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java index b8c1f9d8bd09e..c9733fd3a7f61 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java @@ -15,11 +15,13 @@ import com.azure.storage.blob.models.PublicAccessType; import com.azure.storage.blob.models.SignedIdentifier; import com.azure.storage.blob.models.StorageAccountInfo; +import com.azure.storage.blob.models.UserDelegationKey; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.net.URL; import java.time.Duration; +import java.time.OffsetDateTime; import java.util.List; /** @@ -738,4 +740,190 @@ public Response getAccountInfo(Duration timeout) { return Utility.blockWithOptionalTimeout(response, timeout); } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime) { + return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, + expiryTime); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { + return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, + expiryTime, startTime, version, sasProtocol, ipRange); + } + + /** + * Generates a user delegation SAS token with the specified parameters + * + * @param userDelegationKey + * The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName + * The {@code String} account name for the SAS + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { + return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, + expiryTime, startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, + contentLanguage, contentType); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(ContainerSASPermission permissions, OffsetDateTime expiryTime) { + return this.containerAsyncClient.generateSAS(permissions, expiryTime); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier) { + return this.containerAsyncClient.generateSAS(identifier); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + return this.containerAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, + sasProtocol, ipRange); + } + + /** + * Generates a SAS token with the specified parameters + * + * @param identifier + * The {@code String} name of the access policy on the container this SAS references if any + * @param permissions + * The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the SAS + * @param startTime + * An optional {@code OffsetDateTime} start time for the SAS + * @param version + * An optional {@code String} version for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param cacheControl + * An optional {@code String} cache-control header for the SAS. + * @param contentDisposition + * An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding + * An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage + * An optional {@code String} content-language header for the SAS. + * @param contentType + * An optional {@code String} content-type header for the SAS. + * + * @return + * A string that represents the SAS token + */ + public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + return this.containerAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, + sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/SASQueryParameters.java b/storage/client/blob/src/main/java/com/azure/storage/blob/SASQueryParameters.java index b6afd82addcab..cd918e636bbd4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/SASQueryParameters.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/SASQueryParameters.java @@ -333,9 +333,7 @@ UserDelegationKey userDelegationKey() { private void tryAppendQueryParameter(StringBuilder sb, String param, Object value) { if (value != null) { - if (sb.length() == 0) { - sb.append('?'); - } else { + if (sb.length() != 0) { sb.append('&'); } sb.append(safeURLEncode(param)).append('=').append(safeURLEncode(value.toString())); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java index 7450ae699f5a4..114c28eb71209 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java @@ -6,6 +6,8 @@ import com.azure.storage.blob.models.UserDelegationKey; import com.azure.storage.common.credentials.SharedKeyCredential; +import java.net.MalformedURLException; +import java.net.URL; import java.security.InvalidKeyException; import java.time.OffsetDateTime; @@ -40,9 +42,9 @@ final class ServiceSASSignatureValues { private IPRange ipRange; - private String containerName; + private String canonicalName; - private String blobName; + private String resource; private String snapshotId; @@ -64,6 +66,43 @@ final class ServiceSASSignatureValues { ServiceSASSignatureValues() { } + /** + * Creates an object with the specified expiry time and permissions + * @param expiryTime + * @param permissions + */ + ServiceSASSignatureValues(OffsetDateTime expiryTime, String permissions) { + this.expiryTime = expiryTime; + this.permissions = permissions; + } + + /** + * Creates an object with the specified identifier + * @param identifier + */ + ServiceSASSignatureValues(String identifier) { + this.identifier = identifier; + } + + ServiceSASSignatureValues(String version, SASProtocol sasProtocol, OffsetDateTime startTime, + OffsetDateTime expiryTime, String permission, IPRange ipRange, String identifier, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + if (version != null) { + this.version = version; + } + this.protocol = sasProtocol; + this.startTime = startTime; + this.expiryTime = expiryTime; + this.permissions = permission; + this.ipRange = ipRange; + this.identifier = identifier; + this.cacheControl = cacheControl; + this.contentDisposition = contentDisposition; + this.contentEncoding = contentEncoding; + this.contentLanguage = contentLanguage; + this.contentType = contentType; + } + /** * The version of the service this SAS will target. If not specified, it will default to the version targeted by the * library. @@ -159,32 +198,51 @@ public ServiceSASSignatureValues ipRange(IPRange ipRange) { } /** - * The name of the container the SAS user may access. + * The resource the SAS user may access. */ - public String containerName() { - return containerName; + public String resource() { + return resource; } /** - * The name of the container the SAS user may access. + * The resource the SAS user may access. */ - public ServiceSASSignatureValues containerName(String containerName) { - this.containerName = containerName; + public ServiceSASSignatureValues resource(String resource) { + this.resource = resource; return this; } /** - * The name of the blob the SAS user may access. + * The canonical name of the object the SAS user may access. */ - public String blobName() { - return blobName; + public String canonicalName() { + return canonicalName; } /** - * The name of the blob the SAS user may access. + * The canonical name of the object the SAS user may access. */ - public ServiceSASSignatureValues blobName(String blobName) { - this.blobName = blobName; + public ServiceSASSignatureValues canonicalName(String canonicalName) { + this.canonicalName = canonicalName; + return this; + } + + /** + * The canonical name of the object the SAS user may access. + * @throws RuntimeException If urlString is a malformed URL. + */ + public ServiceSASSignatureValues canonicalName(String urlString, String accountName) { + URL url = null; + try { + url = new URL(urlString); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + + StringBuilder canonicalName = new StringBuilder("/blob"); + canonicalName.append('/').append(accountName).append(url.getPath()); + this.canonicalName = canonicalName.toString(); + return this; } @@ -192,7 +250,7 @@ public ServiceSASSignatureValues blobName(String blobName) { * The specific snapshot the SAS user may access. */ public String snapshotId() { - return snapshotId; + return this.snapshotId; } /** @@ -309,13 +367,10 @@ public ServiceSASSignatureValues contentType(String contentType) { */ public SASQueryParameters generateSASQueryParameters(SharedKeyCredential sharedKeyCredentials) { Utility.assertNotNull("sharedKeyCredentials", sharedKeyCredentials); - assertGenerateOK(); - - String resource = getResource(); - String verifiedPermissions = getVerifiedPermissions(); + assertGenerateOK(false); // Signature is generated on the un-url-encoded values. - final String stringToSign = stringToSign(verifiedPermissions, resource, sharedKeyCredentials); + final String stringToSign = stringToSign(); String signature = null; try { @@ -336,22 +391,15 @@ public SASQueryParameters generateSASQueryParameters(SharedKeyCredential sharedK * @param delegationKey * A {@link UserDelegationKey} object used to sign the SAS values. * - * @param accountName - * Name of the account holding the resource this SAS is authorizing. - * * @return {@link SASQueryParameters} * @throws Error If the accountKey is not a valid Base64-encoded string. */ - public SASQueryParameters generateSASQueryParameters(UserDelegationKey delegationKey, String accountName) { + public SASQueryParameters generateSASQueryParameters(UserDelegationKey delegationKey) { Utility.assertNotNull("delegationKey", delegationKey); - Utility.assertNotNull("accountName", accountName); - assertGenerateOK(); - - String resource = getResource(); - String verifiedPermissions = getVerifiedPermissions(); + assertGenerateOK(true); // Signature is generated on the un-url-encoded values. - final String stringToSign = stringToSign(verifiedPermissions, resource, delegationKey, accountName); + final String stringToSign = stringToSign(delegationKey); String signature = null; try { @@ -369,70 +417,39 @@ public SASQueryParameters generateSASQueryParameters(UserDelegationKey delegatio /** * Common assertions for generateSASQueryParameters overloads. */ - private void assertGenerateOK() { + private void assertGenerateOK(boolean usingUserDelegation) { Utility.assertNotNull("version", this.version); - Utility.assertNotNull("containerName", this.containerName); - if (blobName == null && snapshotId != null) { - throw new IllegalArgumentException("Cannot set a snapshotId without a blobName."); - } - } + Utility.assertNotNull("canonicalName", this.canonicalName); - /** - * Gets the resource string for SAS tokens based on object state. - */ - private String getResource() { - String resource = "c"; - if (!Utility.isNullOrEmpty(this.blobName)) { - resource = snapshotId != null && !snapshotId.isEmpty() ? "bs" : "b"; - } - - return resource; - } - - /** - * Gets the verified permissions string for SAS tokens based on object state. - */ - private String getVerifiedPermissions() { - String verifiedPermissions = null; - // Calling parse and toString guarantees the proper ordering and throws on invalid characters. - if (Utility.isNullOrEmpty(this.blobName)) { - if (this.permissions != null) { - verifiedPermissions = ContainerSASPermission.parse(this.permissions).toString(); + // Ensure either (expiryTime and permissions) or (identifier) is set + if (this.expiryTime == null || this.permissions == null) { + // Identifier is not required if user delegation is being used + if (!usingUserDelegation) { + Utility.assertNotNull("identifier", this.identifier); } } else { - if (this.permissions != null) { - verifiedPermissions = BlobSASPermission.parse(this.permissions).toString(); - } + Utility.assertNotNull("expiryTime", this.expiryTime); + Utility.assertNotNull("permissions", this.permissions); } - return verifiedPermissions; - } - - private String getCanonicalName(String accountName) { - // Container: "/blob/account/containername" - // Blob: "/blob/account/containername/blobname" - StringBuilder canonicalName = new StringBuilder("/blob"); - canonicalName.append('/').append(accountName).append('/').append(this.containerName); - - if (!Utility.isNullOrEmpty(this.blobName)) { - canonicalName.append("/").append(this.blobName); + if (this.resource != null && this.resource.equals(Constants.UrlConstants.SAS_CONTAINER_CONSTANT)) { + if (this.snapshotId != null) { + throw new IllegalArgumentException("Cannot set a snapshotId without resource being a blob."); + } } - - return canonicalName.toString(); } - private String stringToSign(final String verifiedPermissions, final String resource, - final SharedKeyCredential sharedKeyCredentials) { + private String stringToSign() { return String.join("\n", - verifiedPermissions == null ? "" : verifiedPermissions, + this.permissions == null ? "" : this.permissions, this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), - getCanonicalName(sharedKeyCredentials.accountName()), + this.canonicalName == null ? "" : this.canonicalName, this.identifier == null ? "" : this.identifier, this.ipRange == null ? (new IPRange()).toString() : this.ipRange.toString(), this.protocol == null ? "" : protocol.toString(), this.version == null ? "" : this.version, - resource == null ? "" : resource, + this.resource == null ? "" : this.resource, this.snapshotId == null ? "" : this.snapshotId, this.cacheControl == null ? "" : this.cacheControl, this.contentDisposition == null ? "" : this.contentDisposition, @@ -442,13 +459,12 @@ private String stringToSign(final String verifiedPermissions, final String resou ); } - private String stringToSign(final String verifiedPermissions, final String resource, - final UserDelegationKey key, final String accountName) { + private String stringToSign(final UserDelegationKey key) { return String.join("\n", - verifiedPermissions == null ? "" : verifiedPermissions, + this.permissions == null ? "" : this.permissions, this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), - getCanonicalName(accountName), + this.canonicalName == null ? "" : this.canonicalName, key.signedOid() == null ? "" : key.signedOid(), key.signedTid() == null ? "" : key.signedTid(), key.signedStart() == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(key.signedStart()), @@ -458,7 +474,7 @@ private String stringToSign(final String verifiedPermissions, final String resou this.ipRange == null ? new IPRange().toString() : this.ipRange.toString(), this.protocol == null ? "" : this.protocol.toString(), this.version == null ? "" : this.version, - resource == null ? "" : resource, + this.resource == null ? "" : this.resource, this.snapshotId == null ? "" : this.snapshotId, this.cacheControl == null ? "" : this.cacheControl, this.contentDisposition == null ? "" : this.contentDisposition, diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index d5b0aecc3a3f1..c6c48d7e5770d 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -18,6 +18,7 @@ import com.azure.storage.blob.models.StorageServiceProperties; import com.azure.storage.blob.models.StorageServiceStats; import com.azure.storage.blob.models.UserDelegationKey; +import com.azure.storage.common.credentials.SharedKeyCredential; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -233,4 +234,73 @@ public Mono> getAccountInfo() { .getAccountInfo() .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } + + /** + * Generates an account SAS token with the specified parameters + * + * @param accountSASService + * The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType + * An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission + * The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the account SAS + * + * @return + * A string that represents the SAS token + */ + public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { + return this.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime, + null /* startTime */, null /* version */, null /* ipRange */, null /* sasProtocol */); + } + + /** + * Generates an account SAS token with the specified parameters + * + * @param accountSASService + * The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType + * An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission + * The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the account SAS + * @param startTime + * The {@code OffsetDateTime} start time for the account SAS + * @param version + * The {@code String} version for the account SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, + SASProtocol sasProtocol) { + + AccountSASSignatureValues accountSASSignatureValues = new AccountSASSignatureValues(); + accountSASSignatureValues.services(accountSASService == null ? null : accountSASService.toString()); + accountSASSignatureValues.resourceTypes(accountSASResourceType == null ? null : accountSASResourceType.toString()); + accountSASSignatureValues.permissions(accountSASPermission == null ? null : accountSASPermission.toString()); + accountSASSignatureValues.expiryTime(expiryTime); + accountSASSignatureValues.startTime(startTime); + + if (version != null) { + accountSASSignatureValues.version(version); + } + + accountSASSignatureValues.ipRange(ipRange); + accountSASSignatureValues.protocol(sasProtocol); + + SharedKeyCredential sharedKeyCredential = Utility.getSharedKeyCredential(this.storageAsyncRawClient.azureBlobStorage.httpPipeline()); + + SASQueryParameters sasQueryParameters = accountSASSignatureValues.generateSASQueryParameters(sharedKeyCredential); + + return sasQueryParameters.encode(); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java index f18cf0640fbd9..c895cdda58bbc 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java @@ -290,4 +290,53 @@ public Response getAccountInfo(Duration timeout) { return Utility.blockWithOptionalTimeout(response, timeout); } + + /** + * Generates an account SAS token with the specified parameters + * + * @param accountSASService + * The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType + * An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission + * The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the account SAS + * + * @return + * A string that represents the SAS token + */ + public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { + return this.storageAsyncClient.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime); + } + + /** + * Generates an account SAS token with the specified parameters + * + * @param accountSASService + * The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType + * An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission + * The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime + * The {@code OffsetDateTime} expiry time for the account SAS + * @param startTime + * The {@code OffsetDateTime} start time for the account SAS + * @param version + * The {@code String} version for the account SAS + * @param ipRange + * An optional {@code IPRange} ip address range for the SAS + * @param sasProtocol + * An optional {@code SASProtocol} protocol for the SAS + * + * @return + * A string that represents the SAS token + */ + public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, + SASProtocol sasProtocol) { + return this.storageAsyncClient.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime, startTime, version, ipRange, sasProtocol); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java b/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java index 3b5d073c4023e..252a5e83bbaf2 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java @@ -5,9 +5,13 @@ import com.azure.core.http.HttpHeader; import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.implementation.http.UrlBuilder; import com.azure.storage.blob.models.StorageErrorException; import com.azure.storage.blob.models.UserDelegationKey; +import com.azure.storage.common.credentials.SharedKeyCredential; +import com.azure.storage.common.policy.SharedKeyCredentialPolicy; import reactor.core.publisher.Mono; import reactor.util.annotation.Nullable; @@ -387,4 +391,23 @@ static T blockWithOptionalTimeout(Mono response, @Nullable Duration timeo return response.block(timeout); } } + + /** + * Gets the SharedKeyCredential from the HttpPipeline + * + * @param httpPipeline + * The {@code HttpPipeline} httpPipeline from which a sharedKeyCredential will be extracted + * + * @return The {@code SharedKeyCredential} sharedKeyCredential in the httpPipeline + */ + static SharedKeyCredential getSharedKeyCredential(HttpPipeline httpPipeline) { + for (int i = 0; i < httpPipeline.getPolicyCount(); i++) { + HttpPipelinePolicy httpPipelinePolicy = httpPipeline.getPolicy(i); + if (httpPipelinePolicy instanceof SharedKeyCredentialPolicy) { + SharedKeyCredentialPolicy sharedKeyCredentialPolicy = (SharedKeyCredentialPolicy) httpPipelinePolicy; + return sharedKeyCredentialPolicy.sharedKeyCredential(); + } + } + return null; + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java b/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java index fe93273e3f64e..4dce1c831ce21 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java +++ b/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java @@ -18,12 +18,27 @@ public final class SASTokenCredential { private static final String SIGNED_PERMISSIONS = "sp"; private static final String SIGNED_EXPIRY = "se"; private static final String SIGNATURE = "sig"; + private static final String SIGNED_RESOURCE = "sr"; // Optional SAS token pieces private static final String SIGNED_START = "st"; private static final String SIGNED_PROTOCOL = "spr"; private static final String SIGNED_IP = "sip"; + private static final String CACHE_CONTROL = "rscc"; + private static final String CONTENT_DISPOSITION = "rscd"; + private static final String CONTENT_ENCODING = "rsce"; + private static final String CONTENT_LANGUAGE = "rscl"; + private static final String CONTENT_TYPE = "rsct"; + + // Possible User Delegation Key pieces + private static final String SIGNED_KEY_O_ID = "skoid"; + private static final String SIGNED_KEY_T_ID = "sktid"; + private static final String SIGNED_KEY_START = "skt"; + private static final String SIGNED_KEY_EXPIRY = "ske"; + private static final String SIGNED_KEY_SERVICE = "sks"; + private static final String SIGNED_KEY_VERSION = "skv"; + private final String sasToken; /** @@ -57,20 +72,34 @@ public static SASTokenCredential fromQuery(String query) { queryParams.put(key, queryParam); } - if (queryParams.size() < 6 - || !queryParams.containsKey(SIGNED_VERSION) - || !queryParams.containsKey(SIGNED_SERVICES) - || !queryParams.containsKey(SIGNED_RESOURCE_TYPES) - || !queryParams.containsKey(SIGNED_PERMISSIONS) - || !queryParams.containsKey(SIGNED_EXPIRY) - || !queryParams.containsKey(SIGNATURE)) { + /* Because ServiceSAS only requires expiry and permissions, both of which could be on the container + acl, the only guaranteed indication of a SAS is the signature. We'll let the service validate + the other query parameters. */ + if (!queryParams.containsKey(SIGNATURE)) { return null; } - StringBuilder sasTokenBuilder = new StringBuilder(queryParams.get(SIGNED_VERSION)) - .append("&").append(queryParams.get(SIGNED_SERVICES)) - .append("&").append(queryParams.get(SIGNED_RESOURCE_TYPES)) - .append("&").append(queryParams.get(SIGNED_PERMISSIONS)); + StringBuilder sasTokenBuilder = new StringBuilder(); + + if (queryParams.containsKey(SIGNED_VERSION)) { + sasTokenBuilder.append(queryParams.get(SIGNED_VERSION)); + } + + if (queryParams.containsKey(SIGNED_SERVICES)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_SERVICES)); + } + + if (queryParams.containsKey(SIGNED_RESOURCE_TYPES)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_RESOURCE_TYPES)); + } + + if (queryParams.containsKey(SIGNED_PERMISSIONS)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_PERMISSIONS)); + } + + if (queryParams.containsKey(SIGNED_RESOURCE)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_RESOURCE)); + } // SIGNED_START is optional if (queryParams.containsKey(SIGNED_START)) { @@ -89,6 +118,51 @@ public static SASTokenCredential fromQuery(String query) { sasTokenBuilder.append("&").append(queryParams.get(SIGNED_PROTOCOL)); } + if (queryParams.containsKey(CACHE_CONTROL)) { + sasTokenBuilder.append("&").append(queryParams.get(CACHE_CONTROL)); + } + + if (queryParams.containsKey(CONTENT_DISPOSITION)) { + sasTokenBuilder.append("&").append(queryParams.get(CONTENT_DISPOSITION)); + } + + if (queryParams.containsKey(CONTENT_ENCODING)) { + sasTokenBuilder.append("&").append(queryParams.get(CONTENT_ENCODING)); + } + + if (queryParams.containsKey(CONTENT_LANGUAGE)) { + sasTokenBuilder.append("&").append(queryParams.get(CONTENT_LANGUAGE)); + } + + if (queryParams.containsKey(CONTENT_TYPE)) { + sasTokenBuilder.append("&").append(queryParams.get(CONTENT_TYPE)); + } + + // User Delegation Key Parameters + if (queryParams.containsKey(SIGNED_KEY_O_ID)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_O_ID)); + } + + if (queryParams.containsKey(SIGNED_KEY_T_ID)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_T_ID)); + } + + if (queryParams.containsKey(SIGNED_KEY_START)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_START)); + } + + if (queryParams.containsKey(SIGNED_KEY_EXPIRY)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_EXPIRY)); + } + + if (queryParams.containsKey(SIGNED_KEY_SERVICE)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_SERVICE)); + } + + if (queryParams.containsKey(SIGNED_KEY_VERSION)) { + sasTokenBuilder.append("&").append(queryParams.get(SIGNED_KEY_VERSION)); + } + sasTokenBuilder.append("&").append(queryParams.get(SIGNATURE)); return new SASTokenCredential(sasTokenBuilder.toString()); diff --git a/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java b/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java index 8ee1284591dd2..743eae8f262e4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java +++ b/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java @@ -24,6 +24,15 @@ public SharedKeyCredentialPolicy(SharedKeyCredential credential) { this.credential = credential; } + /** + * Gets the shared key credential linked to the policy. + * @return + * The {@link SharedKeyCredential} linked to the policy. + */ + public SharedKeyCredential sharedKeyCredential() { + return this.credential; + } + @Override public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { String authorizationValue = credential.generateAuthorizationHeader(context.httpRequest().url(), diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy new file mode 100644 index 0000000000000..1ebf9860f2ac3 --- /dev/null +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy @@ -0,0 +1,1079 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.storage.blob + +import com.azure.storage.blob.models.AccessPolicy +import com.azure.storage.blob.models.BlobRange +import com.azure.storage.blob.models.SignedIdentifier +import com.azure.storage.blob.models.StorageErrorCode +import com.azure.storage.blob.models.UserDelegationKey +import com.azure.storage.common.credentials.SASTokenCredential +import com.azure.storage.common.credentials.SharedKeyCredential +import spock.lang.Unroll + +import java.time.LocalDateTime +import java.time.OffsetDateTime +import java.time.ZoneOffset + +class SASTest extends APISpec { + + def "responseError"() { + when: + cu.listBlobsFlat() + + then: + def e = thrown(StorageException) + e.errorCode() == StorageErrorCode.INVALID_QUERY_PARAMETER_VALUE + e.statusCode() == 400 + e.message().contains("Value for one of the query parameters specified in the request URI is invalid.") + e.getMessage().contains(" Date: Tue, 16 Jul 2019 10:48:17 -0700 Subject: [PATCH 5/9] Remove RawClients from Blobs (#4375) Removes RawClients from Storage Blobs --- .../storage/blob/AppendBlobAsyncClient.java | 47 +- .../blob/AppendBlobAsyncRawClient.java | 192 ---- .../azure/storage/blob/AppendBlobClient.java | 17 +- .../azure/storage/blob/BlobAsyncClient.java | 830 +++++++-------- .../storage/blob/BlobAsyncRawClient.java | 766 -------------- .../com/azure/storage/blob/BlobClient.java | 680 +++++-------- .../azure/storage/blob/BlobInputStream.java | 2 +- .../azure/storage/blob/BlobOutputStream.java | 4 +- .../com/azure/storage/blob/BlobURLParts.java | 8 +- .../storage/blob/BlockBlobAsyncClient.java | 50 +- .../storage/blob/BlockBlobAsyncRawClient.java | 364 ------- .../azure/storage/blob/BlockBlobClient.java | 14 +- .../storage/blob/ContainerAsyncClient.java | 955 +++++++++--------- .../storage/blob/ContainerAsyncRawClient.java | 708 ------------- .../azure/storage/blob/ContainerClient.java | 660 +++++------- .../storage/blob/ContainerRawClient.java | 652 ------------ .../storage/blob/PageBlobAsyncClient.java | 210 +++- .../storage/blob/PageBlobAsyncRawClient.java | 620 ------------ .../azure/storage/blob/PageBlobClient.java | 12 +- .../blob/ServiceSASSignatureValues.java | 111 +- .../storage/blob/StorageAsyncClient.java | 222 ++-- .../storage/blob/StorageAsyncRawClient.java | 172 ---- .../com/azure/storage/blob/StorageClient.java | 197 ++-- .../azure/storage/blob/StorageRawClient.java | 259 ----- .../credentials/SASTokenCredential.java | 2 + .../policy/SharedKeyCredentialPolicy.java | 5 +- .../java/com/azure/storage/blob/Sample.java | 6 +- 27 files changed, 1885 insertions(+), 5880 deletions(-) delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java delete mode 100644 storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index 7b4585580e16f..60376a3d990ab 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -5,6 +5,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.AppendBlobAccessConditions; import com.azure.storage.blob.models.AppendBlobItem; @@ -13,12 +14,13 @@ import com.azure.storage.blob.models.BlobRange; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.Unpooled; +import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.net.URL; -import java.nio.ByteBuffer; + +import static com.azure.storage.blob.Utility.postProcessResponse; /** @@ -45,8 +47,6 @@ * object through {@link Mono#toFuture()}. */ public final class AppendBlobAsyncClient extends BlobAsyncClient { - final AppendBlobAsyncRawClient appendBlobAsyncRawClient; - /** * Indicates the maximum number of bytes that can be sent in a call to appendBlock. */ @@ -63,7 +63,6 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient { */ AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - appendBlobAsyncRawClient = new AppendBlobAsyncRawClient(azureBlobStorageBuilder.build()); } /** @@ -90,8 +89,13 @@ public Mono> create() { * A reactive response containing the information of the created appended blob. */ public Mono> create(BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return appendBlobAsyncRawClient - .create(headers, metadata, accessConditions) + metadata = (metadata == null) ? new Metadata() : metadata; + accessConditions = (accessConditions == null) ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.appendBlobs().createWithRestResponseAsync(null, + null, 0, null, metadata, null, null, + null, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } @@ -111,7 +115,7 @@ public Mono> create(BlobHTTPHeaders headers, Metadata m * @return * A reactive response containing the information of the append blob operation. */ - public Mono> appendBlock(Flux data, long length) { + public Mono> appendBlock(Flux data, long length) { return this.appendBlock(data, length, null); } @@ -133,10 +137,17 @@ public Mono> appendBlock(Flux data, long le * @return * A reactive response containing the information of the append blob operation. */ - public Mono> appendBlock(Flux data, long length, - AppendBlobAccessConditions appendBlobAccessConditions) { - return appendBlobAsyncRawClient - .appendBlock(data.map(Unpooled::wrappedBuffer), length, appendBlobAccessConditions) + public Mono> appendBlock(Flux data, long length, + AppendBlobAccessConditions appendBlobAccessConditions) { + appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() + : appendBlobAccessConditions; + + return postProcessResponse(this.azureBlobStorage.appendBlobs().appendBlockWithRestResponseAsync( + null, null, data, length, null, null, + null, null, null, null, + appendBlobAccessConditions.leaseAccessConditions(), + appendBlobAccessConditions.appendPositionAccessConditions(), + appendBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } @@ -183,8 +194,16 @@ public Mono> appendBlockFromUrl(URL sourceURL, BlobRang public Mono> appendBlockFromUrl(URL sourceURL, BlobRange sourceRange, byte[] sourceContentMD5, AppendBlobAccessConditions destAccessConditions, SourceModifiedAccessConditions sourceAccessConditions) { - return appendBlobAsyncRawClient - .appendBlockFromUrl(sourceURL, sourceRange, sourceContentMD5, destAccessConditions, sourceAccessConditions) + sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; + destAccessConditions = destAccessConditions == null + ? new AppendBlobAccessConditions() : destAccessConditions; + + return postProcessResponse( + this.azureBlobStorage.appendBlobs().appendBlockFromUrlWithRestResponseAsync(null, null, + sourceURL, 0, sourceRange.toString(), sourceContentMD5, null, null, + destAccessConditions.leaseAccessConditions(), + destAccessConditions.appendPositionAccessConditions(), + destAccessConditions.modifiedAccessConditions(), sourceAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java deleted file mode 100644 index 15bf8e09e4d1f..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncRawClient.java +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.AppendBlobAccessConditions; -import com.azure.storage.blob.models.AppendBlobsAppendBlockFromUrlResponse; -import com.azure.storage.blob.models.AppendBlobsAppendBlockResponse; -import com.azure.storage.blob.models.AppendBlobsCreateResponse; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - - -/** - * Represents a URL to an append blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular append blob but is instead a - * convenient way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - */ -final class AppendBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the maximum number of bytes that can be sent in a call to appendBlock. - */ - public static final int MAX_APPEND_BLOCK_BYTES = 4 * Constants.MB; - - /** - * Indicates the maximum number of blocks allowed in an append blob. - */ - public static final int MAX_BLOCKS = 50000; - - /** - * Creates a {@code AppendBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - AppendBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - super(azureBlobStorage, null); - } - - /** - * Creates a 0-length append blob. Call AppendBlock to append data to an append blob. For more information, see - * the Azure Docs. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create() { - return this.create(null, null, null); - } - - /** - * Creates a 0-length append blob. Call AppendBlock to append data to an append blob. For more information, see - * the Azure Docs. - * - * @param headers {@link BlobHTTPHeaders} - * @param metadata {@link Metadata} - * @param accessConditions {@link BlobAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(BlobHTTPHeaders headers, Metadata metadata, - BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.appendBlobs().createWithRestResponseAsync(null, - null, 0, null, metadata, null, null, - null, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Commits a new block of data to the end of the existing append blob. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.appendBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlock(Flux data, long length) { - return this.appendBlock(data, length, null); - } - - /** - * Commits a new block of data to the end of the existing append blob. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param data The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param appendBlobAccessConditions {@link AppendBlobAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_blob "Sample code for AppendBlobAsyncRawClient.appendBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlock(Flux data, long length, - AppendBlobAccessConditions appendBlobAccessConditions) { - appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() - : appendBlobAccessConditions; - - return postProcessResponse(this.azureBlobStorage.appendBlobs().appendBlockWithRestResponseAsync( - null, null, data, length, null, null, - null, null, null, null, - appendBlobAccessConditions.leaseAccessConditions(), - appendBlobAccessConditions.appendPositionAccessConditions(), - appendBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Commits a new block of data from another blob to the end of this append blob. For more information, see the - * Azure Docs. - *

- * - * @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange The source {@link BlobRange} to copy. - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobAsyncRawClient.appendBlockFromUrl")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlockFromUrl(URL sourceURL, BlobRange sourceRange) { - return this.appendBlockFromUrl(sourceURL, sourceRange, null, null, - null); - } - - /** - * Commits a new block of data from another blob to the end of this append blob. For more information, see the - * Azure Docs. - *

- * - * @param sourceURL The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange {@link BlobRange} - * @param sourceContentMD5 An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param destAccessConditions {@link AppendBlobAccessConditions} - * @param sourceAccessConditions {@link SourceModifiedAccessConditions} - * @return Emits the successful response. - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=append_from_url "Sample code for AppendBlobAsyncRawClient.appendBlockFromUrl")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono appendBlockFromUrl(URL sourceURL, BlobRange sourceRange, - byte[] sourceContentMD5, AppendBlobAccessConditions destAccessConditions, - SourceModifiedAccessConditions sourceAccessConditions) { - - sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; - destAccessConditions = destAccessConditions == null - ? new AppendBlobAccessConditions() : destAccessConditions; - - return postProcessResponse( - this.azureBlobStorage.appendBlobs().appendBlockFromUrlWithRestResponseAsync(null, null, - sourceURL, 0, sourceRange.toString(), sourceContentMD5, null, null, - destAccessConditions.leaseAccessConditions(), - destAccessConditions.appendPositionAccessConditions(), - destAccessConditions.modifiedAccessConditions(), sourceAccessConditions, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java index 47a379649659f..6be2bf7f4e5aa 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobClient.java @@ -11,13 +11,14 @@ import com.azure.storage.blob.models.BlobRange; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import java.io.InputStream; import java.net.URL; -import java.nio.ByteBuffer; import java.time.Duration; @@ -37,18 +38,17 @@ * for more information. */ public final class AppendBlobClient extends BlobClient { - - AppendBlobAsyncClient appendBlobAsyncClient; + private AppendBlobAsyncClient appendBlobAsyncClient; /** * Indicates the maximum number of bytes that can be sent in a call to appendBlock. */ - public static final int MAX_APPEND_BLOCK_BYTES = 4 * Constants.MB; + public static final int MAX_APPEND_BLOCK_BYTES = AppendBlobAsyncClient.MAX_APPEND_BLOCK_BYTES; /** * Indicates the maximum number of blocks allowed in an append blob. */ - public static final int MAX_BLOCKS = 50000; + public static final int MAX_BLOCKS = AppendBlobAsyncClient.MAX_BLOCKS; /** * Package-private constructor for use by {@link AppendBlobClientBuilder}. @@ -58,7 +58,7 @@ public final class AppendBlobClient extends BlobClient { super(appendBlobAsyncClient); this.appendBlobAsyncClient = appendBlobAsyncClient; } - + /** * Creates and opens an output stream to write data to the append blob. If the blob already exists on the service, * it will be overwritten. @@ -160,7 +160,7 @@ public Response appendBlock(InputStream data, long length) { */ public Response appendBlock(InputStream data, long length, AppendBlobAccessConditions appendBlobAccessConditions, Duration timeout) { - Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) MAX_APPEND_BLOCK_BYTES)) + Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) MAX_APPEND_BLOCK_BYTES)) .map(i -> i * MAX_APPEND_BLOCK_BYTES) .concatMap(pos -> Mono.fromCallable(() -> { long count = pos + MAX_APPEND_BLOCK_BYTES > length ? length - pos : MAX_APPEND_BLOCK_BYTES; @@ -169,7 +169,8 @@ public Response appendBlock(InputStream data, long length, while (read < count) { read += data.read(cache, read, (int) count - read); } - return ByteBuffer.wrap(cache); + + return ByteBufAllocator.DEFAULT.buffer((int) count).writeBytes(cache); })); Mono> response = appendBlobAsyncClient.appendBlock(fbb.subscribeOn(Schedulers.elastic()), length, appendBlobAccessConditions); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index 5042f9e782af5..2601107aaa0b6 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -9,7 +9,9 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.http.UrlBuilder; import com.azure.core.implementation.util.FluxUtil; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -20,6 +22,7 @@ import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.ModifiedAccessConditions; import com.azure.storage.blob.models.ReliableDownloadOptions; +import com.azure.storage.blob.models.SourceModifiedAccessConditions; import com.azure.storage.blob.models.StorageAccountInfo; import com.azure.storage.blob.models.UserDelegationKey; import com.azure.storage.common.credentials.SharedKeyCredential; @@ -41,82 +44,89 @@ import java.util.ArrayList; import java.util.List; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** - * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} or via - * the method {@link ContainerAsyncClient#getBlobAsyncClient(String)}. This class does not hold any state about a particular - * blob, but is instead a convenient way of sending appropriate requests to the resource on the service. + * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} + * or via the method {@link ContainerAsyncClient#getBlobAsyncClient(String)}. This class does not hold any state about a + * particular blob, but is instead a convenient way of sending appropriate requests to the resource on the service. * *

* This client offers the ability to download blobs. Note that uploading data is specific to each type of blob. Please * refer to the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient} for upload options. This - * client can be converted into one of these clients easily through the methods {@link #asBlockBlobAsyncClient}, - * {@link #asPageBlobAsyncClient}, and {@link #asAppendBlobAsyncClient()}. + * client can be converted into one of these clients easily through the methods {@link #asBlockBlobAsyncClient}, {@link + * #asPageBlobAsyncClient}, and {@link #asAppendBlobAsyncClient()}. * *

* This client contains operations on a blob. Operations on a container are available on {@link ContainerAsyncClient}, * and operations on the service are available on {@link StorageAsyncClient}. * *

- * Please refer to the Azure Docs - * for more information. + * Please refer to the Azure + * Docs for more information. * *

- * Note this client is an async client that returns reactive responses from Spring Reactor Core - * project (https://projectreactor.io/). Calling the methods in this client will NOT - * start the actual network operation, until {@code .subscribe()} is called on the reactive response. - * You can simply convert one of these responses to a {@link java.util.concurrent.CompletableFuture} - * object through {@link Mono#toFuture()}. + * Note this client is an async client that returns reactive responses from Spring Reactor Core project + * (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network + * operation, until {@code .subscribe()} is called on the reactive response. You can simply convert one of these + * responses to a {@link java.util.concurrent.CompletableFuture} object through {@link Mono#toFuture()}. */ public class BlobAsyncClient { private static final int BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB; private static final int BLOB_MAX_DOWNLOAD_BLOCK_SIZE = 100 * Constants.MB; - final BlobAsyncRawClient blobAsyncRawClient; + protected final AzureBlobStorageImpl azureBlobStorage; + protected final String snapshot; /** * Package-private constructor for use by {@link BlobClientBuilder}. + * * @param azureBlobStorageBuilder the API client builder for blob storage API */ BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - this.blobAsyncRawClient = new BlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); + this.azureBlobStorage = azureBlobStorageBuilder.build(); + this.snapshot = snapshot; } /** * Creates a new {@link BlockBlobAsyncClient} to this resource, maintaining configurations. Only do this for blobs * that are known to be block blobs. * - * @return - * A {@link BlockBlobAsyncClient} to this resource. + * @return A {@link BlockBlobAsyncClient} to this resource. */ public BlockBlobAsyncClient asBlockBlobAsyncClient() { - return new BlockBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** * Creates a new {@link AppendBlobAsyncClient} to this resource, maintaining configurations. Only do this for blobs * that are known to be append blobs. * - * @return - * A {@link AppendBlobAsyncClient} to this resource. + * @return A {@link AppendBlobAsyncClient} to this resource. */ public AppendBlobAsyncClient asAppendBlobAsyncClient() { - return new AppendBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** * Creates a new {@link PageBlobAsyncClient} to this resource, maintaining configurations. Only do this for blobs * that are known to be page blobs. * - * @return - * A {@link PageBlobAsyncClient} to this resource. + * @return A {@link PageBlobAsyncClient} to this resource. */ public PageBlobAsyncClient asPageBlobAsyncClient() { - return new PageBlobAsyncClient(new AzureBlobStorageBuilder().url(getBlobUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), blobAsyncRawClient.snapshot); + return new PageBlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** - * Initializes a {@link ContainerAsyncClient} object pointing to the container this blob is in. This method does - * not create a container. It simply constructs the URL to the container and offers access to methods relevant to + * Initializes a {@link ContainerAsyncClient} object pointing to the container this blob is in. This method does not + * create a container. It simply constructs the URL to the container and offers access to methods relevant to * containers. * * @return A {@link ContainerAsyncClient} object pointing to the container containing the blob @@ -125,31 +135,31 @@ public ContainerAsyncClient getContainerAsyncClient() { BlobURLParts parts = URLParser.parse(getBlobUrl()); return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s://%s/%s", parts.scheme(), parts.host(), parts.containerName())) - .pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** * Gets the URL of the blob represented by this client. + * * @return the URL. * @throws RuntimeException If the blob is using a malformed URL. */ public URL getBlobUrl() { try { - UrlBuilder urlBuilder = UrlBuilder.parse(blobAsyncRawClient.azureBlobStorage.url()); - if (blobAsyncRawClient.snapshot != null) { - urlBuilder.query("snapshot=" + blobAsyncRawClient.snapshot); + UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.url()); + if (snapshot != null) { + urlBuilder.query("snapshot=" + snapshot); } return urlBuilder.toURL(); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), blobAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } /** * Gets if the blob this client represents exists in the cloud. * - * @return - * true if the blob exists, false if it doesn't + * @return true if the blob exists, false if it doesn't */ public Mono> exists() { return this.getProperties() @@ -164,11 +174,8 @@ public Mono> exists() { * Copies the data at the source URL to a blob. For more information, see the * Azure Docs * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * - * @return - * A reactive response containing the copy ID for the long running operation. + * @param sourceURL The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @return A reactive response containing the copy ID for the long running operation. */ public Mono> startCopyFromURL(URL sourceURL) { return this.startCopyFromURL(sourceURL, null, null, null); @@ -178,37 +185,41 @@ public Mono> startCopyFromURL(URL sourceURL) { * Copies the data at the source URL to a blob. For more information, see the * Azure Docs * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return - * A reactive response containing the copy ID for the long running operation. + * @param sourceURL The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @param metadata {@link Metadata} + * @param sourceModifiedAccessConditions {@link ModifiedAccessConditions} against the source. Standard HTTP Access + * conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions + * related to when the blob was changed relative to the given request. The request will fail if the specified + * condition is not satisfied. + * @param destAccessConditions {@link BlobAccessConditions} against the destination. + * @return A reactive response containing the copy ID for the long running operation. */ public Mono> startCopyFromURL(URL sourceURL, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - return blobAsyncRawClient - .startCopyFromURL(sourceURL, metadata, sourceModifiedAccessConditions, destAccessConditions) + ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { + metadata = metadata == null ? new Metadata() : metadata; + sourceModifiedAccessConditions = sourceModifiedAccessConditions == null + ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; + destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; + + // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. + SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() + .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) + .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) + .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) + .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); + + return postProcessResponse(this.azureBlobStorage.blobs().startCopyFromURLWithRestResponseAsync( + null, null, sourceURL, null, metadata, null, sourceConditions, + destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyId())); } /** * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * - * @return - * A reactive response signalling completion. + * @param copyId The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link + * BlobStartCopyFromURLHeaders} object. + * @return A reactive response signalling completion. */ public Mono abortCopyFromURL(String copyId) { return this.abortCopyFromURL(copyId, null); @@ -217,30 +228,23 @@ public Mono abortCopyFromURL(String copyId) { /** * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return - * A reactive response signalling completion. + * @param copyId The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link + * BlobStartCopyFromURLHeaders} object. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @return A reactive response signalling completion. */ public Mono abortCopyFromURL(String copyId, LeaseAccessConditions leaseAccessConditions) { - return blobAsyncRawClient - .abortCopyFromURL(copyId, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().abortCopyFromURLWithRestResponseAsync( + null, null, copyId, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } /** * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. * - * @param copySource - * The source URL to copy from. - * - * @return - * A reactive response containing the copy ID for the long running operation. + * @param copySource The source URL to copy from. + * @return A reactive response containing the copy ID for the long running operation. */ public Mono> copyFromURL(URL copySource) { return this.copyFromURL(copySource, null, null, null); @@ -249,63 +253,110 @@ public Mono> copyFromURL(URL copySource) { /** * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. * - * @param copySource - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return - * A reactive response containing the copy ID for the long running operation. + * @param copySource The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @param metadata {@link Metadata} + * @param sourceModifiedAccessConditions {@link ModifiedAccessConditions} against the source. Standard HTTP Access + * conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions + * related to when the blob was changed relative to the given request. The request will fail if the specified + * condition is not satisfied. + * @param destAccessConditions {@link BlobAccessConditions} against the destination. + * @return A reactive response containing the copy ID for the long running operation. */ public Mono> copyFromURL(URL copySource, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - return blobAsyncRawClient - .syncCopyFromURL(copySource, metadata, sourceModifiedAccessConditions, destAccessConditions) + ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { + metadata = metadata == null ? new Metadata() : metadata; + sourceModifiedAccessConditions = sourceModifiedAccessConditions == null + ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; + destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; + + // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. + SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() + .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) + .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) + .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) + .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); + + return postProcessResponse(this.azureBlobStorage.blobs().copyFromURLWithRestResponseAsync( + null, null, copySource, null, metadata, null, sourceConditions, + destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyId())); } /** - * Reads the entire blob. Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Reads the entire blob. Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or + * {@link AppendBlobClient}. * - * @return - * A reactive response containing the blob data. + * @return A reactive response containing the blob data. */ public Mono>> download() { return this.download(null, null, false, null); } /** - * Reads a range of bytes from a blob. Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Reads a range of bytes from a blob. Uploading data must be done from the {@link BlockBlobClient}, {@link + * PageBlobClient}, or {@link AppendBlobClient}. * - * @param range - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. + * @param range {@link BlobRange} + * @param accessConditions {@link BlobAccessConditions} + * @param rangeGetContentMD5 Whether the contentMD5 for the specified blob range should be returned. * @param options {@link ReliableDownloadOptions} - * * @return A reactive response containing the blob data. */ public Mono>> download(BlobRange range, BlobAccessConditions accessConditions, - boolean rangeGetContentMD5, ReliableDownloadOptions options) { - return blobAsyncRawClient - .download(range, accessConditions, rangeGetContentMD5) + boolean rangeGetContentMD5, ReliableDownloadOptions options) { + return this.download(range, accessConditions, rangeGetContentMD5) .map(response -> new SimpleResponse<>( response.rawResponse(), response.body(options).map(ByteBuf::nioBuffer).switchIfEmpty(Flux.just(ByteBuffer.allocate(0))))); } + /** + * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more + * information, see the Azure Docs. + *

+ * Note that the response body has reliable download functionality built in, meaning that a failed download stream + * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. + * + * @param range {@link BlobRange} + * @param accessConditions {@link BlobAccessConditions} + * @param rangeGetContentMD5 Whether the contentMD5 for the specified blob range should be returned. + * @return Emits the successful response. + * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download + * "Sample code for BlobAsyncClient.download")] \n For more samples, please see the [Samples + * file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + */ + Mono download(BlobRange range, BlobAccessConditions accessConditions, boolean rangeGetContentMD5) { + range = range == null ? new BlobRange(0) : range; + Boolean getMD5 = rangeGetContentMD5 ? rangeGetContentMD5 : null; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + HTTPGetterInfo info = new HTTPGetterInfo() + .offset(range.offset()) + .count(range.count()) + .eTag(accessConditions.modifiedAccessConditions().ifMatch()); + + // TODO: range is BlobRange but expected as String + // TODO: figure out correct response + return postProcessResponse(this.azureBlobStorage.blobs().downloadWithRestResponseAsync( + null, null, snapshot, null, null, range.toHeaderValue(), getMD5, + null, null, null, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) + // Convert the autorest response to a DownloadAsyncResponse, which enable reliable download. + .map(response -> { + // If there wasn't an etag originally specified, lock on the one returned. + info.eTag(response.deserializedHeaders().eTag()); + return new DownloadAsyncResponse(response, info, + // In the event of a stream failure, make a new request to pick up where we left off. + newInfo -> + this.download(new BlobRange(newInfo.offset(), newInfo.count()), + new BlobAccessConditions().modifiedAccessConditions( + new ModifiedAccessConditions().ifMatch(info.eTag())), false)); + }); + } + /** * Downloads the entire blob into a file specified by the path. The file will be created if it doesn't exist. - * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link + * AppendBlobClient}. *

* This method makes an extra HTTP call to get the length of the blob in the beginning. To avoid this extra call, * use the other overload providing the {@link BlobRange} parameter. @@ -319,21 +370,17 @@ public Mono downloadToFile(String filePath) { /** * Downloads a range of bytes blob into a file specified by the path. The file will be created if it doesn't exist. - * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link + * AppendBlobClient}. *

* This method makes an extra HTTP call to get the length of the blob in the beginning. To avoid this extra call, * provide the {@link BlobRange} parameter. * - * @param filePath - * A non-null {@link OutputStream} instance where the downloaded data will be written. - * @param range - * {@link BlobRange} - * @param blockSize - * the size of a chunk to download at a time, in bytes - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. + * @param filePath A non-null {@link OutputStream} instance where the downloaded data will be written. + * @param range {@link BlobRange} + * @param blockSize the size of a chunk to download at a time, in bytes + * @param accessConditions {@link BlobAccessConditions} + * @param rangeGetContentMD5 Whether the contentMD5 for the specified blob range should be returned. * @param options {@link ReliableDownloadOptions} * @return An empty response * @throws IllegalArgumentException If {@code blockSize} is less than 0 or greater than 100MB. @@ -349,8 +396,7 @@ public Mono downloadToFile(String filePath, BlobRange range, Integer block channel -> Mono.justOrEmpty(range) .switchIfEmpty(getFullBlobRange(accessConditions)) .flatMapMany(rg -> Flux.fromIterable(sliceBlobRange(rg, blockSize))) - .flatMap(chunk -> blobAsyncRawClient - .download(chunk, accessConditions, rangeGetContentMD5) + .flatMap(chunk -> this.download(chunk, accessConditions, rangeGetContentMD5) .subscribeOn(Schedulers.elastic()) .flatMap(dar -> FluxUtil.bytebufStreamToFile(dar.body(options), channel, chunk.offset() - (range == null ? 0 : range.offset())))) .then(), this::downloadToFileCleanup); @@ -396,8 +442,7 @@ private List sliceBlobRange(BlobRange blobRange, Integer blockSize) { /** * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. */ public Mono delete() { return this.delete(null, null); @@ -406,28 +451,27 @@ public Mono delete() { /** * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. * - * @param deleteBlobSnapshotOptions - * Specifies the behavior for deleting the snapshots on this blob. {@code Include} will delete the base blob - * and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being deleted, you must - * pass null. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param deleteBlobSnapshotOptions Specifies the behavior for deleting the snapshots on this blob. {@code Include} + * will delete the base blob and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being + * deleted, you must pass null. + * @param accessConditions {@link BlobAccessConditions} + * @return A reactive response signalling completion. */ public Mono delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, - BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .delete(deleteBlobSnapshotOptions, accessConditions) + BlobAccessConditions accessConditions) { + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().deleteWithRestResponseAsync( + null, null, snapshot, null, null, deleteBlobSnapshotOptions, + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .map(VoidResponse::new); } /** * Returns the blob's metadata and properties. * - * @return - * A reactive response containing the blob properties and metadata. + * @return A reactive response containing the blob properties and metadata. */ public Mono> getProperties() { return this.getProperties(null); @@ -436,93 +480,87 @@ public Mono> getProperties() { /** * Returns the blob's metadata and properties. * - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return - * A reactive response containing the blob properties and metadata. + * @param accessConditions {@link BlobAccessConditions} + * @return A reactive response containing the blob properties and metadata. */ public Mono> getProperties(BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .getProperties(accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().getPropertiesWithRestResponseAsync( + null, null, snapshot, null, null, null, + null, null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlobProperties(rb.deserializedHeaders()))); } /** - * Changes a blob's HTTP header properties. if only one HTTP header is updated, the - * others will all be erased. In order to preserve existing values, they must be - * passed alongside the header being changed. For more information, see the + * Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In + * order to preserve existing values, they must be passed alongside the header being changed. For more information, + * see the * Azure Docs. * - * @param headers - * {@link BlobHTTPHeaders} - * - * @return - * A reactive response signalling completion. + * @param headers {@link BlobHTTPHeaders} + * @return A reactive response signalling completion. */ public Mono setHTTPHeaders(BlobHTTPHeaders headers) { return this.setHTTPHeaders(headers, null); } /** - * Changes a blob's HTTP header properties. if only one HTTP header is updated, the - * others will all be erased. In order to preserve existing values, they must be - * passed alongside the header being changed. For more information, see the + * Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In + * order to preserve existing values, they must be passed alongside the header being changed. For more information, + * see the * Azure Docs. * - * @param headers - * {@link BlobHTTPHeaders} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param headers {@link BlobHTTPHeaders} + * @param accessConditions {@link BlobAccessConditions} + * @return A reactive response signalling completion. */ public Mono setHTTPHeaders(BlobHTTPHeaders headers, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .setHTTPHeaders(headers, accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().setHTTPHeadersWithRestResponseAsync( + null, null, null, null, headers, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } /** - * Changes a blob's metadata. The specified metadata in this method will replace existing - * metadata. If old values must be preserved, they must be downloaded and included in the - * call to this method. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} + * Changes a blob's metadata. The specified metadata in this method will replace existing metadata. If old values + * must be preserved, they must be downloaded and included in the call to this method. For more information, see the + * Azure Docs. * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @return A reactive response signalling completion. */ public Mono setMetadata(Metadata metadata) { return this.setMetadata(metadata, null); } /** - * Changes a blob's metadata. The specified metadata in this method will replace existing - * metadata. If old values must be preserved, they must be downloaded and included in the - * call to this method. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} + * Changes a blob's metadata. The specified metadata in this method will replace existing metadata. If old values + * must be preserved, they must be downloaded and included in the call to this method. For more information, see the + * Azure Docs. * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @param accessConditions {@link BlobAccessConditions} + * @return A reactive response signalling completion. */ public Mono setMetadata(Metadata metadata, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .setMetadata(metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().setMetadataWithRestResponseAsync( + null, null, null, metadata, null, null, + null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } /** * Creates a read-only snapshot of a blob. * - * @return - * A reactive response containing the ID of the new snapshot. + * @return A reactive response containing the ID of the new snapshot. */ public Mono> createSnapshot() { return this.createSnapshot(null, null); @@ -531,30 +569,29 @@ public Mono> createSnapshot() { /** * Creates a read-only snapshot of a blob. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return - * A reactive response containing the ID of the new snapshot. + * @param metadata {@link Metadata} + * @param accessConditions {@link BlobAccessConditions} + * @return A reactive response containing the ID of the new snapshot. */ public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { - return blobAsyncRawClient - .createSnapshot(metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blobs().createSnapshotWithRestResponseAsync( + null, null, null, metadata, null, null, + null, null, accessConditions.modifiedAccessConditions(), + accessConditions.leaseAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().snapshot())); } /** * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - * - * @param tier - * The new tier for the blob. + * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's + * etag. * - * @return - * A reactive response signalling completion. + * @param tier The new tier for the blob. + * @return A reactive response signalling completion. */ public Mono setTier(AccessTier tier) { return this.setTier(tier, null); @@ -563,32 +600,30 @@ public Mono setTier(AccessTier tier) { /** * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. + * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's + * etag. * - * @param tier - * The new tier for the blob. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return - * A reactive response signalling completion. + * @param tier The new tier for the blob. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @return A reactive response signalling completion. */ public Mono setTier(AccessTier tier, LeaseAccessConditions leaseAccessConditions) { - return blobAsyncRawClient - .setTier(tier, leaseAccessConditions) + Utility.assertNotNull("tier", tier); + + return postProcessResponse(this.azureBlobStorage.blobs().setTierWithRestResponseAsync( + null, null, tier, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } /** * Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots. * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. */ public Mono undelete() { - return blobAsyncRawClient - .undelete() + return postProcessResponse(this.azureBlobStorage.blobs().undeleteWithRestResponseAsync(null, + null, Context.NONE)) .map(VoidResponse::new); } @@ -596,14 +631,10 @@ public Mono undelete() { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return - * A reactive response containing the lease ID. + * @param proposedId A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @return A reactive response containing the lease ID. */ public Mono> acquireLease(String proposedId, int duration) { return this.acquireLease(proposedId, duration, null); @@ -613,33 +644,33 @@ public Mono> acquireLease(String proposedId, int duration) { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the lease ID. + * @param proposedID A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the lease ID. + * @throws IllegalArgumentException If {@code duration} is outside the bounds of 15 to 60 or isn't -1. */ public Mono> acquireLease(String proposedID, int duration, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .acquireLease(proposedID, duration, modifiedAccessConditions) + if (!(duration == -1 || (duration >= 15 && duration <= 60))) { + // Throwing is preferred to Mono.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("Duration must be -1 or between 15 and 60."); + } + + return postProcessResponse(this.azureBlobStorage.blobs().acquireLeaseWithRestResponseAsync( + null, null, null, duration, proposedID, null, + modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * A reactive response containing the renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @return A reactive response containing the renewed lease ID. */ public Mono> renewLease(String leaseID) { return this.renewLease(leaseID, null); @@ -648,30 +679,23 @@ public Mono> renewLease(String leaseID) { /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the renewed lease ID. */ public Mono> renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .renewLease(leaseID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().renewLeaseWithRestResponseAsync(null, + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * A reactive response signalling completion. + * @param leaseID The leaseId of the active lease on the blob. + * @return A reactive response signalling completion. */ public Mono releaseLease(String leaseID) { return this.releaseLease(leaseID, null); @@ -680,19 +704,15 @@ public Mono releaseLease(String leaseID) { /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response signalling completion. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response signalling completion. */ public Mono releaseLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .releaseLease(leaseID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().releaseLeaseWithRestResponseAsync(null, + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -700,8 +720,7 @@ public Mono releaseLease(String leaseID, ModifiedAccessConditions * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @return - * A reactive response containing the remaining time in the broken lease in seconds. + * @return A reactive response containing the remaining time in the broken lease in seconds. */ public Mono> breakLease() { return this.breakLease(null, null); @@ -711,90 +730,74 @@ public Mono> breakLease() { * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the remaining time in the broken lease in seconds. + * @param breakPeriodInSeconds An optional {@code Integer} representing the proposed duration of seconds that the + * lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is + * shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease + * will not be available before the break period has expired, but the lease may be held for longer than the break + * period. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the remaining time in the broken lease in seconds. */ public Mono> breakLease(Integer breakPeriodInSeconds, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .breakLease(breakPeriodInSeconds, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().breakLeaseWithRestResponseAsync(null, + null, null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseTime())); } /** * ChangeLease changes the blob's lease ID. * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return - * A reactive response containing the new lease ID. + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @return A reactive response containing the new lease ID. */ public Mono> changeLease(String leaseId, String proposedID) { return this.changeLease(leaseId, proposedID, null); } /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. + * ChangeLease changes the blob's lease ID. For more information, see the Azure + * Docs. * + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. * @return A reactive response containing the new lease ID. */ public Mono> changeLease(String leaseId, String proposedID, ModifiedAccessConditions modifiedAccessConditions) { - return blobAsyncRawClient - .changeLease(leaseId, proposedID, modifiedAccessConditions) + return postProcessResponse(this.azureBlobStorage.blobs().changeLeaseWithRestResponseAsync(null, + null, leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } /** - * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. + * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. * * @return a reactor response containing the sku name and account kind. */ // TODO (unknown): determine this return type public Mono> getAccountInfo() { - return blobAsyncRawClient - .getAccountInfo() + return postProcessResponse( + this.azureBlobStorage.blobs().getAccountInfoWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } /** * Generates a user delegation SAS with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime) { + BlobSASPermission permissions, OffsetDateTime expiryTime) { return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null /* startTime */, null /* version */, null /*sasProtocol */, null /* ipRange */, null /* cacheControl */, null /*contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); @@ -803,29 +806,19 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange) { + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); @@ -834,40 +827,25 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, - String contentEncoding, String contentLanguage, String contentType) { + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, null /* identifier*/, @@ -883,13 +861,9 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a SAS token with the specified parameters * - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateSAS(BlobSASPermission permissions, OffsetDateTime expiryTime) { return this.generateSAS(null, permissions, expiryTime, null /* startTime */, /* identifier */ null /* @@ -900,11 +874,8 @@ public String generateSAS(BlobSASPermission permissions, OffsetDateTime expiryTi /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @return A string that represents the SAS token */ public String generateSAS(String identifier) { return this.generateSAS(identifier, null /* permissions */, null /* expiryTime */, null /* startTime */, @@ -915,26 +886,17 @@ public String generateSAS(String identifier) { /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { return this.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null /* cacheControl */, null /* contentLanguage*/, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); @@ -943,44 +905,30 @@ public String generateSAS(String identifier, BlobSASPermission permissions, Offs /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, - String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, identifier, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); SharedKeyCredential sharedKeyCredential = - Utility.getSharedKeyCredential(this.blobAsyncRawClient.azureBlobStorage.httpPipeline()); + Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); @@ -996,10 +944,10 @@ public String generateSAS(String identifier, BlobSASPermission permissions, Offs * Sets serviceSASSignatureValues parameters dependent on the current blob type */ ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignatureValues serviceSASSignatureValues, - String accountName) { + String accountName) { // Set canonical name - serviceSASSignatureValues.canonicalName(this.blobAsyncRawClient.azureBlobStorage.url(), accountName); + serviceSASSignatureValues.canonicalName(this.azureBlobStorage.url(), accountName); // Set snapshotId serviceSASSignatureValues.snapshotId(getSnapshotId()); @@ -1017,20 +965,18 @@ ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignature /** * Gets the snapshotId for a blob resource * - * @return - * A string that represents the snapshotId of the snapshot blob + * @return A string that represents the snapshotId of the snapshot blob */ public String getSnapshotId() { - return this.blobAsyncRawClient.snapshot; + return this.snapshot; } /** * Determines if a blob is a snapshot * - * @return - * A boolean that indicates if a blob is a snapshot + * @return A boolean that indicates if a blob is a snapshot */ public boolean isSnapshot() { - return this.blobAsyncRawClient.snapshot != null; + return this.snapshot != null; } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java deleted file mode 100644 index 002ba761a3bf8..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncRawClient.java +++ /dev/null @@ -1,766 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.AccessTier; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.BlobStartCopyFromURLHeaders; -import com.azure.storage.blob.models.BlobsAbortCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsAcquireLeaseResponse; -import com.azure.storage.blob.models.BlobsBreakLeaseResponse; -import com.azure.storage.blob.models.BlobsChangeLeaseResponse; -import com.azure.storage.blob.models.BlobsCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsCreateSnapshotResponse; -import com.azure.storage.blob.models.BlobsDeleteResponse; -import com.azure.storage.blob.models.BlobsGetAccountInfoResponse; -import com.azure.storage.blob.models.BlobsGetPropertiesResponse; -import com.azure.storage.blob.models.BlobsReleaseLeaseResponse; -import com.azure.storage.blob.models.BlobsRenewLeaseResponse; -import com.azure.storage.blob.models.BlobsSetHTTPHeadersResponse; -import com.azure.storage.blob.models.BlobsSetMetadataResponse; -import com.azure.storage.blob.models.BlobsSetTierResponse; -import com.azure.storage.blob.models.BlobsStartCopyFromURLResponse; -import com.azure.storage.blob.models.BlobsUndeleteResponse; -import com.azure.storage.blob.models.DeleteSnapshotsOptionType; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.ReliableDownloadOptions; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import reactor.core.publisher.Mono; - -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a blob of any type: block, append, or page. It may be obtained by direct construction or via the - * create method on a {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is - * instead a convenient way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs for more information. - */ -class BlobAsyncRawClient { - - protected AzureBlobStorageImpl azureBlobStorage; - - final String snapshot; - - /** - * Creates a {@code BlobAsyncRawClient} object pointing to the account specified by the URL and using the provided pipeline to - * make HTTP requests.. - */ - BlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - this.azureBlobStorage = azureBlobStorage; - this.snapshot = snapshot; - } - - /** - * Copies the data at the source URL to a blob. For more information, see the Azure Docs - * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy "Sample code for BlobAsyncRawClient.startCopyFromURL")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy_helper "Helper for start_copy sample.")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono startCopyFromURL(URL sourceURL) { - return this.startCopyFromURL(sourceURL, null, null, null); - } - - /** - * Copies the data at the source URL to a blob. For more information, see the Azure Docs - * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy "Sample code for BlobAsyncRawClient.startCopyFromURL")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=start_copy_helper "Helper for start_copy sample.")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono startCopyFromURL(URL sourceURL, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - sourceModifiedAccessConditions = sourceModifiedAccessConditions == null - ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; - destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; - - // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. - SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() - .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) - .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) - .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) - .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); - - return postProcessResponse(this.azureBlobStorage.blobs().startCopyFromURLWithRestResponseAsync( - null, null, sourceURL, null, metadata, null, sourceConditions, - destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For - * more information, see the Azure Docs. - * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=abort_copy "Sample code for BlobAsyncRawClient.abortCopyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono abortCopyFromURL(String copyId) { - return this.abortCopyFromURL(copyId, null); - } - - /** - * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For - * more information, see the Azure Docs. - * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=abort_copy "Sample code for BlobAsyncRawClient.abortCopyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono abortCopyFromURL(String copyId, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().abortCopyFromURLWithRestResponseAsync( - null, null, copyId, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. - * For more information, see the Azure Docs - * - * @param copySource - * The source URL to copy from. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=sync_copy "Sample code for BlobAsyncRawClient.copyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono syncCopyFromURL(URL copySource) { - return this.syncCopyFromURL(copySource, null, null, null); - } - - /** - * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. - * For more information, see the Azure Docs - * - * @param copySource - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=sync_copy "Sample code for BlobAsyncRawClient.copyFromURL")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono syncCopyFromURL(URL copySource, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - sourceModifiedAccessConditions = sourceModifiedAccessConditions == null - ? new ModifiedAccessConditions() : sourceModifiedAccessConditions; - destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions; - - // We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here. - SourceModifiedAccessConditions sourceConditions = new SourceModifiedAccessConditions() - .sourceIfModifiedSince(sourceModifiedAccessConditions.ifModifiedSince()) - .sourceIfUnmodifiedSince(sourceModifiedAccessConditions.ifUnmodifiedSince()) - .sourceIfMatch(sourceModifiedAccessConditions.ifMatch()) - .sourceIfNoneMatch(sourceModifiedAccessConditions.ifNoneMatch()); - - return postProcessResponse(this.azureBlobStorage.blobs().copyFromURLWithRestResponseAsync( - null, null, copySource, null, metadata, null, sourceConditions, - destAccessConditions.modifiedAccessConditions(), destAccessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more - * information, see the Azure Docs. - *

- * Note that the response body has reliable download functionality built in, meaning that a failed download stream - * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download - * "Sample code for BlobAsyncRawClient.download")] \n For more samples, please see the [Samples - * file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono download() { - return this.download(null, null, false); - } - - /** - * Reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more - * information, see the Azure Docs. - *

- * Note that the response body has reliable download functionality built in, meaning that a failed download stream - * will be automatically retried. This behavior may be configured with {@link ReliableDownloadOptions}. - * - * @param range - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlobAsyncRawClient.download")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono download(BlobRange range, BlobAccessConditions accessConditions, - boolean rangeGetContentMD5) { - range = range == null ? new BlobRange(0) : range; - Boolean getMD5 = rangeGetContentMD5 ? rangeGetContentMD5 : null; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - HTTPGetterInfo info = new HTTPGetterInfo() - .offset(range.offset()) - .count(range.count()) - .eTag(accessConditions.modifiedAccessConditions().ifMatch()); - - // TODO: range is BlobRange but expected as String - // TODO: figure out correct response - return postProcessResponse(this.azureBlobStorage.blobs().downloadWithRestResponseAsync( - null, null, snapshot, null, null, range.toHeaderValue(), getMD5, - null, null, null, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) - // Convert the autorest response to a DownloadAsyncResponse, which enable reliable download. - .map(response -> { - // If there wasn't an etag originally specified, lock on the one returned. - info.eTag(response.deserializedHeaders().eTag()); - return new DownloadAsyncResponse(response, info, - // In the event of a stream failure, make a new request to pick up where we left off. - newInfo -> - this.download(new BlobRange(newInfo.offset(), newInfo.count()), - new BlobAccessConditions().modifiedAccessConditions( - new ModifiedAccessConditions().ifMatch(info.eTag())), false)); - }); - } - - /** - * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. For more - * information, see the Azure Docs. - * - * @return Emits the successful response. - * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_delete - * "Sample code for BlobAsyncRawClient.delete")] \n For more samples, please see the [Samples - * file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete() { - return this.delete(null, null); - } - - /** - * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. For more - * information, see the Azure Docs. - * - * @param deleteBlobSnapshotOptions - * Specifies the behavior for deleting the snapshots on this blob. {@code Include} will delete the base blob - * and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being deleted, you must - * pass null. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_delete "Sample code for BlobAsyncRawClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, - BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().deleteWithRestResponseAsync( - null, null, snapshot, null, null, deleteBlobSnapshotOptions, - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - } - - /** - * Returns the blob's metadata and properties. For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return this.getProperties(null); - } - - /** - * Returns the blob's metadata and properties. For more information, see the Azure Docs. - * - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties(BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().getPropertiesWithRestResponseAsync( - null, null, snapshot, null, null, null, - null, null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Changes a blob's HTTP header properties. For more information, see the Azure - * Docs. - * - * @param headers - * {@link BlobHTTPHeaders} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setHTTPHeaders")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setHTTPHeaders(BlobHTTPHeaders headers) { - return this.setHTTPHeaders(headers, null); - } - - /** - * Changes a blob's HTTP header properties. For more information, see the Azure Docs. - * - * @param headers - * {@link BlobHTTPHeaders} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setHTTPHeaders")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setHTTPHeaders(BlobHTTPHeaders headers, - BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().setHTTPHeadersWithRestResponseAsync( - null, null, null, null, headers, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Changes a blob's metadata. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null); - } - - /** - * Changes a blob's metadata. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=properties_metadata "Sample code for BlobAsyncRawClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().setMetadataWithRestResponseAsync( - null, null, null, metadata, null, null, - null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Creates a read-only snapshot of a blob. For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=snapshot "Sample code for BlobAsyncRawClient.createSnapshot")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono createSnapshot() { - return this.createSnapshot(null, null); - } - - /** - * Creates a read-only snapshot of a blob. For more information, see the Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=snapshot "Sample code for BlobAsyncRawClient.createSnapshot")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blobs().createSnapshotWithRestResponseAsync( - null, null, null, metadata, null, null, - null, null, accessConditions.modifiedAccessConditions(), - accessConditions.leaseAccessConditions(), Context.NONE)); - } - - /** - * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in - * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - *

- * For detailed information about block blob level tiering see the Azure Docs. - * - * @param tier - * The new tier for the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=tier "Sample code for BlobAsyncRawClient.setTier")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setTier(AccessTier tier) { - return this.setTier(tier, null); - } - - /** - * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in - * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - *

- * For detailed information about block blob level tiering see the Azure Docs. - * - * @param tier - * The new tier for the blob. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=tier "Sample code for BlobAsyncRawClient.setTier")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setTier(AccessTier tier, LeaseAccessConditions leaseAccessConditions) { - Utility.assertNotNull("tier", tier); - - return postProcessResponse(this.azureBlobStorage.blobs().setTierWithRestResponseAsync( - null, null, tier, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots. - * For more information, see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=undelete "Sample code for BlobAsyncRawClient.undelete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono undelete() { - return postProcessResponse(this.azureBlobStorage.blobs().undeleteWithRestResponseAsync(null, - null, Context.NONE)); - } - - /** - * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 - * seconds, or infinite (-1). For more information, see the Azure Docs. - * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null); - } - - /** - * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 - * seconds, or infinite (-1). For more information, see the Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code duration} is outside the bounds of 15 to 60 or isn't -1. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions) { - if (!(duration == -1 || (duration >= 15 && duration <= 60))) { - // Throwing is preferred to Mono.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("Duration must be -1 or between 15 and 60."); - } - - return postProcessResponse(this.azureBlobStorage.blobs().acquireLeaseWithRestResponseAsync( - null, null, null, duration, proposedID, null, - modifiedAccessConditions, Context.NONE)); - } - - /** - * Renews the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID) { - return this.renewLease(leaseID, null); - } - - /** - * Renews the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().renewLeaseWithRestResponseAsync(null, - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Releases the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID) { - return this.releaseLease(leaseID, null); - } - - /** - * Releases the blob's previously-acquired lease. For more information, see the Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().releaseLeaseWithRestResponseAsync(null, - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant - * to break a fixed-duration lease when it expires or an infinite lease immediately. For more information, see the - * Azure Docs. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return - * Emits the successful response. - */ - public Mono breakLease() { - return this.breakLease(null, null); - } - - /** - * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant - * to break a fixed-duration lease when it expires or an infinite lease immediately. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().breakLeaseWithRestResponseAsync(null, - null, null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseId, String proposedID) { - return this.changeLease(leaseId, proposedID, null); - } - - /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blob_lease "Sample code for BlobAsyncRawClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseId, String proposedID, - ModifiedAccessConditions modifiedAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blobs().changeLeaseWithRestResponseAsync(null, - null, leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for BlobAsyncRawClient.getAccountInfo")] \n - * For more samples, please see the [Samples file](https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.blobs().getAccountInfoWithRestResponseAsync(null, null, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java index 21a2212713f5c..a937b8ca47613 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java @@ -27,30 +27,30 @@ import java.time.OffsetDateTime; /** - * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} or via - * the method {@link ContainerClient#getBlobClient(String)}. This class does not hold any state about a particular - * blob, but is instead a convenient way of sending appropriate requests to the resource on the service. + * Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder} + * or via the method {@link ContainerClient#getBlobClient(String)}. This class does not hold any state about a + * particular blob, but is instead a convenient way of sending appropriate requests to the resource on the service. * *

* This client offers the ability to download blobs. Note that uploading data is specific to each type of blob. Please * refer to the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient} for upload options. This - * client can be converted into one of these clients easily through the methods {@link #asBlockBlobClient}, {@link #asPageBlobClient}, - * and {@link #asAppendBlobClient}. + * client can be converted into one of these clients easily through the methods {@link #asBlockBlobClient}, {@link + * #asPageBlobClient}, and {@link #asAppendBlobClient}. * *

- * This client contains operations on a blob. Operations on a container are available on {@link ContainerClient}, - * and operations on the service are available on {@link StorageClient}. + * This client contains operations on a blob. Operations on a container are available on {@link ContainerClient}, and + * operations on the service are available on {@link StorageClient}. * *

- * Please refer to the Azure Docs - * for more information. + * Please refer to the Azure + * Docs for more information. */ public class BlobClient { - private static final int BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB; private final BlobAsyncClient blobAsyncClient; /** * Package-private constructor for use by {@link BlobClientBuilder}. + * * @param blobAsyncClient the async blob client */ BlobClient(BlobAsyncClient blobAsyncClient) { @@ -58,45 +58,41 @@ public class BlobClient { } /** - * Creates a new {@link BlockBlobClient} to this resource, maintaining configurations. Only do this for blobs - * that are known to be block blobs. + * Creates a new {@link BlockBlobClient} to this resource, maintaining configurations. Only do this for blobs that + * are known to be block blobs. * - * @return - * A {@link BlockBlobClient} to this resource. + * @return A {@link BlockBlobClient} to this resource. */ public BlockBlobClient asBlockBlobClient() { return new BlockBlobClient(blobAsyncClient.asBlockBlobAsyncClient()); } /** - * Creates a new {@link AppendBlobClient} to this resource, maintaining configurations. Only do this for blobs - * that are known to be append blobs. + * Creates a new {@link AppendBlobClient} to this resource, maintaining configurations. Only do this for blobs that + * are known to be append blobs. * - * @return - * A {@link AppendBlobClient} to this resource. + * @return A {@link AppendBlobClient} to this resource. */ public AppendBlobClient asAppendBlobClient() { return new AppendBlobClient(blobAsyncClient.asAppendBlobAsyncClient()); } /** - * Creates a new {@link PageBlobClient} to this resource, maintaining configurations. Only do this for blobs - * that are known to be page blobs. + * Creates a new {@link PageBlobClient} to this resource, maintaining configurations. Only do this for blobs that + * are known to be page blobs. * - * @return - * A {@link PageBlobClient} to this resource. + * @return A {@link PageBlobClient} to this resource. */ public PageBlobClient asPageBlobClient() { return new PageBlobClient(blobAsyncClient.asPageBlobAsyncClient()); } /** - * Initializes a {@link ContainerClient} object pointing to the container this blob is in. This method does - * not create a container. It simply constructs the URL to the container and offers access to methods relevant to + * Initializes a {@link ContainerClient} object pointing to the container this blob is in. This method does not + * create a container. It simply constructs the URL to the container and offers access to methods relevant to * containers. * - * @return - * A {@link ContainerClient} object pointing to the container containing the blob + * @return A {@link ContainerClient} object pointing to the container containing the blob */ public ContainerClient getContainerClient() { return new ContainerClient(blobAsyncClient.getContainerAsyncClient()); @@ -104,6 +100,7 @@ public ContainerClient getContainerClient() { /** * Gets the URL of the blob represented by this client. + * * @return the URL. */ public URL getBlobUrl() { @@ -115,9 +112,7 @@ public URL getBlobUrl() { *

* * @return An InputStream object that represents the stream to use for reading from the blob. - * - * @throws StorageException - * If a storage service error occurred. + * @throws StorageException If a storage service error occurred. */ public final BlobInputStream openInputStream() { return openInputStream(new BlobRange(0), null); @@ -127,15 +122,11 @@ public final BlobInputStream openInputStream() { * Opens a blob input stream to download the specified range of the blob. *

* - * @param range - * {@link BlobRange} - * @param accessConditions - * An {@link BlobAccessConditions} object that represents the access conditions for the blob. - * + * @param range {@link BlobRange} + * @param accessConditions An {@link BlobAccessConditions} object that represents the access conditions for the + * blob. * @return An InputStream object that represents the stream to use for reading from the blob. - * - * @throws StorageException - * If a storage service error occurred. + * @throws StorageException If a storage service error occurred. */ public final BlobInputStream openInputStream(BlobRange range, BlobAccessConditions accessConditions) { return new BlobInputStream(blobAsyncClient, range.offset(), range.count(), accessConditions); @@ -153,10 +144,8 @@ public Response exists() { /** * Gets if the container this client represents exists in the cloud. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * @return - * true if the container exists, false if it doesn't + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return true if the container exists, false if it doesn't */ public Response exists(Duration timeout) { Mono> response = blobAsyncClient.exists(); @@ -168,11 +157,8 @@ public Response exists(Duration timeout) { * Copies the data at the source URL to a blob. For more information, see the * Azure Docs * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * - * @return - * The copy ID for the long running operation. + * @param sourceURL The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @return The copy ID for the long running operation. */ public Response startCopyFromURL(URL sourceURL) { return this.startCopyFromURL(sourceURL, null, null, null, null); @@ -182,26 +168,19 @@ public Response startCopyFromURL(URL sourceURL) { * Copies the data at the source URL to a blob. For more information, see the * Azure Docs * - * @param sourceURL - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The copy ID for the long running operation. + * @param sourceURL The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @param metadata {@link Metadata} + * @param sourceModifiedAccessConditions {@link ModifiedAccessConditions} against the source. Standard HTTP Access + * conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions + * related to when the blob was changed relative to the given request. The request will fail if the specified + * condition is not satisfied. + * @param destAccessConditions {@link BlobAccessConditions} against the destination. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The copy ID for the long running operation. */ public Response startCopyFromURL(URL sourceURL, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions, - Duration timeout) { + ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions, + Duration timeout) { Mono> response = blobAsyncClient .startCopyFromURL(sourceURL, metadata, sourceModifiedAccessConditions, destAccessConditions); @@ -211,9 +190,8 @@ public Response startCopyFromURL(URL sourceURL, Metadata metadata, /** * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. + * @param copyId The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link + * BlobStartCopyFromURLHeaders} object. * @return A response containing status code and HTTP headers. */ public VoidResponse abortCopyFromURL(String copyId) { @@ -223,14 +201,11 @@ public VoidResponse abortCopyFromURL(String copyId) { /** * Stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. * - * @param copyId - * The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link - * BlobStartCopyFromURLHeaders} object. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param copyId The id of the copy operation to abort. Returned as the {@code copyId} field on the {@link + * BlobStartCopyFromURLHeaders} object. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse abortCopyFromURL(String copyId, LeaseAccessConditions leaseAccessConditions, Duration timeout) { @@ -243,11 +218,8 @@ public VoidResponse abortCopyFromURL(String copyId, LeaseAccessConditions leaseA /** * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. * - * @param copySource - * The source URL to copy from. - * - * @return - * The copy ID for the long running operation. + * @param copySource The source URL to copy from. + * @return The copy ID for the long running operation. */ public Response copyFromURL(URL copySource) { return this.copyFromURL(copySource, null, null, null, null); @@ -256,26 +228,19 @@ public Response copyFromURL(URL copySource) { /** * Copies the data at the source URL to a blob and waits for the copy to complete before returning a response. * - * @param copySource - * The source URL to copy from. URLs outside of Azure may only be copied to block blobs. - * @param metadata - * {@link Metadata} - * @param sourceModifiedAccessConditions - * {@link ModifiedAccessConditions} against the source. Standard HTTP Access conditions related to the - * modification of data. ETag and LastModifiedTime are used to construct conditions related to when the blob - * was changed relative to the given request. The request will fail if the specified condition is not - * satisfied. - * @param destAccessConditions - * {@link BlobAccessConditions} against the destination. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The copy ID for the long running operation. + * @param copySource The source URL to copy from. URLs outside of Azure may only be copied to block blobs. + * @param metadata {@link Metadata} + * @param sourceModifiedAccessConditions {@link ModifiedAccessConditions} against the source. Standard HTTP Access + * conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions + * related to when the blob was changed relative to the given request. The request will fail if the specified + * condition is not satisfied. + * @param destAccessConditions {@link BlobAccessConditions} against the destination. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The copy ID for the long running operation. */ public Response copyFromURL(URL copySource, Metadata metadata, - ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions, - Duration timeout) { + ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions, + Duration timeout) { Mono> response = blobAsyncClient .copyFromURL(copySource, metadata, sourceModifiedAccessConditions, destAccessConditions); @@ -286,8 +251,7 @@ public Response copyFromURL(URL copySource, Metadata metadata, * Downloads the entire blob into an output stream. Uploading data must be done from the {@link BlockBlobClient}, * {@link PageBlobClient}, or {@link AppendBlobClient}. * - * @param stream - * A non-null {@link OutputStream} instance where the downloaded data will be written. + * @param stream A non-null {@link OutputStream} instance where the downloaded data will be written. * @return A response containing status code and HTTP headers. * @throws UncheckedIOException If an I/O error occurs. */ @@ -296,23 +260,17 @@ public VoidResponse download(OutputStream stream) { } /** - * Downloads a range of bytes from a blob into an output stream. Uploading data must be done from the {@link BlockBlobClient}, - * {@link PageBlobClient}, or {@link AppendBlobClient}. + * Downloads a range of bytes from a blob into an output stream. Uploading data must be done from the {@link + * BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. * - * @param stream - * A non-null {@link OutputStream} instance where the downloaded data will be written. + * @param stream A non-null {@link OutputStream} instance where the downloaded data will be written. * @param options {@link ReliableDownloadOptions} - * @param range - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param range {@link BlobRange} + * @param accessConditions {@link BlobAccessConditions} + * @param rangeGetContentMD5 Whether the contentMD5 for the specified blob range should be returned. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. * @throws UncheckedIOException If an I/O error occurs. - * */ public VoidResponse download(OutputStream stream, ReliableDownloadOptions options, BlobRange range, BlobAccessConditions accessConditions, boolean rangeGetContentMD5, Duration timeout) { @@ -334,37 +292,32 @@ public VoidResponse download(OutputStream stream, ReliableDownloadOptions option /** * Downloads the entire blob into a file specified by the path. The file will be created if it doesn't exist. - * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link + * AppendBlobClient}. * - * @param filePath - * A non-null {@link OutputStream} instance where the downloaded data will be written. + * @param filePath A non-null {@link OutputStream} instance where the downloaded data will be written. * @throws IOException If an I/O error occurs */ public void downloadToFile(String filePath) throws IOException { - this.downloadToFile(filePath, null, null, BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE, null, false, null); + blobAsyncClient.downloadToFile(filePath); } /** * Downloads a range of bytes blob into a file specified by the path. The file will be created if it doesn't exist. - * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link AppendBlobClient}. + * Uploading data must be done from the {@link BlockBlobClient}, {@link PageBlobClient}, or {@link + * AppendBlobClient}. * - * @param filePath - * A non-null {@link OutputStream} instance where the downloaded data will be written. + * @param filePath A non-null {@link OutputStream} instance where the downloaded data will be written. * @param options {@link ReliableDownloadOptions} - * @param range - * {@link BlobRange} - * @param blockSize - * the size of a chunk to download at a time, in bytes - * @param accessConditions - * {@link BlobAccessConditions} - * @param rangeGetContentMD5 - * Whether the contentMD5 for the specified blob range should be returned. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param range {@link BlobRange} + * @param blockSize the size of a chunk to download at a time, in bytes + * @param accessConditions {@link BlobAccessConditions} + * @param rangeGetContentMD5 Whether the contentMD5 for the specified blob range should be returned. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @throws IOException If an I/O error occurs */ public void downloadToFile(String filePath, ReliableDownloadOptions options, BlobRange range, Integer blockSize, - BlobAccessConditions accessConditions, boolean rangeGetContentMD5, Duration timeout) throws IOException { + BlobAccessConditions accessConditions, boolean rangeGetContentMD5, Duration timeout) throws IOException { Mono download = blobAsyncClient.downloadToFile(filePath, range, blockSize, accessConditions, rangeGetContentMD5, options); try { @@ -386,19 +339,15 @@ public VoidResponse delete() { /** * Deletes the specified blob or snapshot. Note that deleting a blob also deletes all its snapshots. * - * @param deleteBlobSnapshotOptions - * Specifies the behavior for deleting the snapshots on this blob. {@code Include} will delete the base blob - * and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being deleted, you must - * pass null. - * @param accessConditions - * {@link BlobAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * + * @param deleteBlobSnapshotOptions Specifies the behavior for deleting the snapshots on this blob. {@code Include} + * will delete the base blob and all snapshots. {@code Only} will delete only the snapshots. If a snapshot is being + * deleted, you must pass null. + * @param accessConditions {@link BlobAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, - BlobAccessConditions accessConditions, Duration timeout) { + BlobAccessConditions accessConditions, Duration timeout) { Mono response = blobAsyncClient .delete(deleteBlobSnapshotOptions, accessConditions); @@ -408,8 +357,7 @@ public VoidResponse delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions, /** * Returns the blob's metadata and properties. * - * @return - * The blob properties and metadata. + * @return The blob properties and metadata. */ public Response getProperties() { return this.getProperties(null, null); @@ -418,13 +366,9 @@ public Response getProperties() { /** * Returns the blob's metadata and properties. * - * @param accessConditions - * {@link BlobAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The blob properties and metadata. + * @param accessConditions {@link BlobAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The blob properties and metadata. */ public Response getProperties(BlobAccessConditions accessConditions, Duration timeout) { Mono> response = blobAsyncClient @@ -434,13 +378,12 @@ public Response getProperties(BlobAccessConditions accessConditi } /** - * Changes a blob's HTTP header properties. if only one HTTP header is updated, the - * others will all be erased. In order to preserve existing values, they must be - * passed alongside the header being changed. For more information, see the + * Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In + * order to preserve existing values, they must be passed alongside the header being changed. For more information, + * see the * Azure Docs. * - * @param headers - * {@link BlobHTTPHeaders} + * @param headers {@link BlobHTTPHeaders} * @return A response containing status code and HTTP headers. */ public VoidResponse setHTTPHeaders(BlobHTTPHeaders headers) { @@ -448,21 +391,18 @@ public VoidResponse setHTTPHeaders(BlobHTTPHeaders headers) { } /** - * Changes a blob's HTTP header properties. if only one HTTP header is updated, the - * others will all be erased. In order to preserve existing values, they must be - * passed alongside the header being changed. For more information, see the + * Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In + * order to preserve existing values, they must be passed alongside the header being changed. For more information, + * see the * Azure Docs. * - * @param headers - * {@link BlobHTTPHeaders} - * @param accessConditions - * {@link BlobAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param headers {@link BlobHTTPHeaders} + * @param accessConditions {@link BlobAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse setHTTPHeaders(BlobHTTPHeaders headers, BlobAccessConditions accessConditions, - Duration timeout) { + Duration timeout) { Mono response = blobAsyncClient .setHTTPHeaders(headers, accessConditions); @@ -470,12 +410,11 @@ public VoidResponse setHTTPHeaders(BlobHTTPHeaders headers, BlobAccessConditions } /** - * Changes a blob's metadata. The specified metadata in this method will replace existing - * metadata. If old values must be preserved, they must be downloaded and included in the - * call to this method. For more information, see the Azure Docs. + * Changes a blob's metadata. The specified metadata in this method will replace existing metadata. If old values + * must be preserved, they must be downloaded and included in the call to this method. For more information, see the + * Azure Docs. * - * @param metadata - * {@link Metadata} + * @param metadata {@link Metadata} * @return A response containing status code and HTTP headers. */ public VoidResponse setMetadata(Metadata metadata) { @@ -483,16 +422,13 @@ public VoidResponse setMetadata(Metadata metadata) { } /** - * Changes a blob's metadata. The specified metadata in this method will replace existing - * metadata. If old values must be preserved, they must be downloaded and included in the - * call to this method. For more information, see the Azure Docs. + * Changes a blob's metadata. The specified metadata in this method will replace existing metadata. If old values + * must be preserved, they must be downloaded and included in the call to this method. For more information, see the + * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param metadata {@link Metadata} + * @param accessConditions {@link BlobAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { @@ -505,8 +441,7 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo /** * Creates a read-only snapshot of a blob. * - * @return - * The ID of the new snapshot. + * @return The ID of the new snapshot. */ public Response createSnapshot() { return this.createSnapshot(null, null, null); @@ -515,15 +450,10 @@ public Response createSnapshot() { /** * Creates a read-only snapshot of a blob. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The ID of the new snapshot. + * @param metadata {@link Metadata} + * @param accessConditions {@link BlobAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The ID of the new snapshot. */ public Response createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { Mono> response = blobAsyncClient @@ -535,10 +465,10 @@ public Response createSnapshot(Metadata metadata, BlobAccessConditions a /** * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. + * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's + * etag. * - * @param tier - * The new tier for the blob. + * @param tier The new tier for the blob. * @return A response containing status code and HTTP headers. */ public VoidResponse setTier(AccessTier tier) { @@ -548,15 +478,13 @@ public VoidResponse setTier(AccessTier tier) { /** * Sets the tier on a blob. The operation is allowed on a page blob in a premium storage account or a block blob in * a blob storage or GPV2 account. A premium page blob's tier determines the allowed size, IOPS, and bandwidth of - * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's etag. - * - * @param tier - * The new tier for the blob. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * the blob. A block blob's tier determines the Hot/Cool/Archive storage type. This does not update the blob's + * etag. + * + * @param tier The new tier for the blob. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse setTier(AccessTier tier, LeaseAccessConditions leaseAccessConditions, Duration timeout) { @@ -578,8 +506,7 @@ public VoidResponse undelete() { /** * Undelete restores the content and metadata of a soft-deleted blob and/or any associated soft-deleted snapshots. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse undelete(Duration timeout) { @@ -593,14 +520,10 @@ public VoidResponse undelete(Duration timeout) { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return - * The lease ID. + * @param proposedId A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @return The lease ID. */ public Response acquireLease(String proposedId, int duration) { return this.acquireLease(proposedId, duration, null, null); @@ -610,23 +533,17 @@ public Response acquireLease(String proposedId, int duration) { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The lease ID. + * @param proposedID A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The lease ID. */ public Response acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = blobAsyncClient .acquireLease(proposedID, duration, modifiedAccessConditions); @@ -636,11 +553,8 @@ public Response acquireLease(String proposedID, int duration, /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * The renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @return The renewed lease ID. */ public Response renewLease(String leaseID) { return this.renewLease(leaseID, null, null); @@ -649,20 +563,15 @@ public Response renewLease(String leaseID) { /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The renewed lease ID. */ public Response renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions, - Duration timeout) { + Duration timeout) { Mono> response = blobAsyncClient .renewLease(leaseID, modifiedAccessConditions); @@ -672,8 +581,7 @@ public Response renewLease(String leaseID, ModifiedAccessConditions modi /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. + * @param leaseID The leaseId of the active lease on the blob. * @return A response containing status code and HTTP headers. */ public VoidResponse releaseLease(String leaseID) { @@ -683,18 +591,15 @@ public VoidResponse releaseLease(String leaseID) { /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono response = blobAsyncClient .releaseLease(leaseID, modifiedAccessConditions); @@ -705,8 +610,7 @@ public VoidResponse releaseLease(String leaseID, * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @return - * The remaining time in the broken lease in seconds. + * @return The remaining time in the broken lease in seconds. */ public Response breakLease() { return this.breakLease(null, null, null); @@ -716,24 +620,19 @@ public Response breakLease() { * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The remaining time in the broken lease in seconds. + * @param breakPeriodInSeconds An optional {@code Integer} representing the proposed duration of seconds that the + * lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is + * shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease + * will not be available before the break period has expired, but the lease may be held for longer than the break + * period. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The remaining time in the broken lease in seconds. */ public Response breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = blobAsyncClient .breakLease(breakPeriodInSeconds, modifiedAccessConditions); @@ -743,36 +642,28 @@ public Response breakLease(Integer breakPeriodInSeconds, /** * ChangeLease changes the blob's lease ID. * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return - * The new lease ID. + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @return The new lease ID. */ public Response changeLease(String leaseId, String proposedID) { return this.changeLease(leaseId, proposedID, null, null); } /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * ChangeLease changes the blob's lease ID. For more information, see the Azure + * Docs. * + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return The new lease ID. */ public Response changeLease(String leaseId, String proposedID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = blobAsyncClient .changeLease(leaseId, proposedID, modifiedAccessConditions); @@ -780,7 +671,8 @@ public Response changeLease(String leaseId, String proposedID, } /** - * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. + * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. * * @return The sku name and account kind. */ @@ -789,11 +681,10 @@ public Response getAccountInfo() { } /** - * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. - * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * Returns the sku name and account kind for the account. For more information, please see the Azure Docs. * + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return The sku name and account kind. */ public Response getAccountInfo(Duration timeout) { @@ -806,49 +697,33 @@ public Response getAccountInfo(Duration timeout) { /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime) { + BlobSASPermission permissions, OffsetDateTime expiryTime) { return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime); } /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange) { + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange); } @@ -856,40 +731,25 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, - String contentEncoding, String contentLanguage, String contentType) { + BlobSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { return this.blobAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); @@ -898,13 +758,9 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a SAS token with the specified parameters * - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * - * @return - * A string that represents the SAS token + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @return A string that represents the SAS token */ public String generateSAS(OffsetDateTime expiryTime, BlobSASPermission permissions) { return this.blobAsyncClient.generateSAS(permissions, expiryTime); @@ -913,11 +769,8 @@ public String generateSAS(OffsetDateTime expiryTime, BlobSASPermission permissio /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @return A string that represents the SAS token */ public String generateSAS(String identifier) { return this.blobAsyncClient.generateSAS(identifier); @@ -926,26 +779,17 @@ public String generateSAS(String identifier) { /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { return this.blobAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange); } @@ -953,37 +797,23 @@ public String generateSAS(String identifier, BlobSASPermission permissions, Offs /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateSAS(String identifier, BlobSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, - String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { return this.blobAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); } @@ -991,8 +821,7 @@ public String generateSAS(String identifier, BlobSASPermission permissions, Offs /** * Gets the snapshotId for a blob resource * - * @return - * A string that represents the snapshotId of the snapshot blob + * @return A string that represents the snapshotId of the snapshot blob */ public String getSnapshotId() { return this.blobAsyncClient.getSnapshotId(); @@ -1001,8 +830,7 @@ public String getSnapshotId() { /** * Determines if a blob is a snapshot * - * @return - * A boolean that indicates if a blob is a snapshot + * @return A boolean that indicates if a blob is a snapshot */ public boolean isSnapshot() { return this.blobAsyncClient.isSnapshot(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java index 2e093f50738f2..1a990e179688b 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobInputStream.java @@ -189,7 +189,7 @@ public synchronized void close() throws IOException { */ private synchronized void dispatchRead(final int readLength) throws IOException { try { - this.currentBuffer = this.blobClient.blobAsyncRawClient.download(new BlobRange(this.currentAbsoluteReadPosition, (long) readLength), this.accessCondition, false) + this.currentBuffer = this.blobClient.download(new BlobRange(this.currentAbsoluteReadPosition, (long) readLength), this.accessCondition, false) .flatMap(res -> ByteBufFlux.fromInbound(res.body(null)).aggregate().asByteBuffer()) .block(); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java index 176fe06c321d1..c733a580f2500 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobOutputStream.java @@ -295,7 +295,7 @@ private Mono writePages(Flux pageData, long offset, long writeLen PageBlobAccessConditions pageBlobAccessConditions = accessCondition == null ? null : new PageBlobAccessConditions().leaseAccessConditions(accessCondition.leaseAccessConditions()).modifiedAccessConditions(accessCondition.modifiedAccessConditions()); - return blobRef.pageBlobAsyncRawClient.uploadPages(new PageRange().start(offset).end(offset + writeLength - 1), pageData, pageBlobAccessConditions) + return blobRef.uploadPages(new PageRange().start(offset).end(offset + writeLength - 1), pageData, pageBlobAccessConditions) .then() .onErrorResume(t -> t instanceof StorageException, e -> { this.lastError = new IOException(e); @@ -312,7 +312,7 @@ private Mono appendBlock(Flux blockData, long offset, long writeL this.appendPositionAccessConditions.appendPosition(offset); AppendBlobAccessConditions appendBlobAccessConditions = accessCondition == null ? null : new AppendBlobAccessConditions().leaseAccessConditions(accessCondition.leaseAccessConditions()).modifiedAccessConditions(accessCondition.modifiedAccessConditions()); - return blobRef.appendBlobAsyncRawClient.appendBlock(blockData, writeLength, appendBlobAccessConditions) + return blobRef.appendBlock(blockData, writeLength, appendBlobAccessConditions) .then() .onErrorResume(t -> t instanceof IOException || t instanceof StorageException, e -> { this.lastError = new IOException(e); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java index 473d998c446b2..1200e960f7501 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobURLParts.java @@ -76,14 +76,14 @@ public BlobURLParts host(String host) { } /** - * The container name or {@code null} if a {@link StorageAsyncRawClient} was parsed. + * The container name or {@code null} if a {@link StorageAsyncClient} was parsed. */ public String containerName() { return containerName; } /** - * The container name or {@code null} if a {@link StorageAsyncRawClient} was parsed. + * The container name or {@code null} if a {@link StorageAsyncClient} was parsed. */ public BlobURLParts containerName(String containerName) { this.containerName = containerName; @@ -91,14 +91,14 @@ public BlobURLParts containerName(String containerName) { } /** - * The blob name or {@code null} if a {@link StorageAsyncRawClient} or {@link ContainerAsyncClient} was parsed. + * The blob name or {@code null} if a {@link StorageAsyncClient} or {@link ContainerAsyncClient} was parsed. */ public String blobName() { return blobName; } /** - * The blob name or {@code null} if a {@link StorageAsyncRawClient} or {@link ContainerAsyncClient} was parsed. + * The blob name or {@code null} if a {@link StorageAsyncClient} or {@link ContainerAsyncClient} was parsed. */ public BlobURLParts blobName(String blobName) { this.blobName = blobName; diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java index ada7a125d4ef1..e7d8aa9b0c03d 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java @@ -8,6 +8,7 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.util.FluxUtil; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -15,11 +16,11 @@ import com.azure.storage.blob.models.BlockBlobItem; import com.azure.storage.blob.models.BlockItem; import com.azure.storage.blob.models.BlockListType; +import com.azure.storage.blob.models.BlockLookupList; import com.azure.storage.blob.models.LeaseAccessConditions; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.SourceModifiedAccessConditions; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -27,7 +28,6 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.net.URL; -import java.nio.ByteBuffer; import java.nio.channels.AsynchronousFileChannel; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; @@ -39,6 +39,8 @@ import java.util.TreeMap; import java.util.UUID; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** * Client to a block blob. It may only be instantiated through a {@link BlockBlobClientBuilder}, via * the method {@link BlobAsyncClient#asBlockBlobAsyncClient()}, or via the method @@ -66,8 +68,6 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { static final int BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = 4 * Constants.MB; static final int BLOB_MAX_UPLOAD_BLOCK_SIZE = 100 * Constants.MB; - final BlockBlobAsyncRawClient blockBlobAsyncRawClient; - /** * Indicates the maximum number of bytes that can be sent in a call to upload. */ @@ -89,7 +89,6 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { */ BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - this.blockBlobAsyncRawClient = new BlockBlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); } /** @@ -114,7 +113,7 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { * @return * A reactive response containing the information of the uploaded block blob. */ - public Mono> upload(Flux data, long length) { + public Mono> upload(Flux data, long length) { return this.upload(data, length, null, null, null); } @@ -146,10 +145,15 @@ public Mono> upload(Flux data, long length) * @return * A reactive response containing the information of the uploaded block blob. */ - public Mono> upload(Flux data, long length, BlobHTTPHeaders headers, + public Mono> upload(Flux data, long length, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return blockBlobAsyncRawClient - .upload(data.map(Unpooled::wrappedBuffer), length, headers, metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blockBlobs().uploadWithRestResponseAsync(null, + null, data, length, null, metadata, null, null, + null, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); } @@ -291,8 +295,9 @@ public Mono stageBlock(String base64BlockID, Flux data, */ public Mono stageBlock(String base64BlockID, Flux data, long length, LeaseAccessConditions leaseAccessConditions) { - return blockBlobAsyncRawClient - .stageBlock(base64BlockID, data, length, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blockBlobs().stageBlockWithRestResponseAsync(null, + null, base64BlockID, length, data, null, null, null, + null, null, null, leaseAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -349,8 +354,13 @@ public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions, SourceModifiedAccessConditions sourceModifiedAccessConditions) { - return blockBlobAsyncRawClient - .stageBlockFromURL(base64BlockID, sourceURL, sourceRange, sourceContentMD5, leaseAccessConditions, sourceModifiedAccessConditions) + sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; + + return postProcessResponse( + this.azureBlobStorage.blockBlobs().stageBlockFromURLWithRestResponseAsync(null, null, + base64BlockID, 0, sourceURL, sourceRange.toHeaderValue(), sourceContentMD5, null, + null, null, null, null, + leaseAccessConditions, sourceModifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -386,8 +396,9 @@ public Flux listBlocks(BlockListType listType) { */ public Flux listBlocks(BlockListType listType, LeaseAccessConditions leaseAccessConditions) { - return blockBlobAsyncRawClient - .listBlocks(listType, leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync( + null, null, listType, snapshot, null, null, null, + leaseAccessConditions, Context.NONE)) .map(ResponseBase::value) .flatMapMany(bl -> { Flux committed = Flux.fromIterable(bl.committedBlocks()) @@ -440,8 +451,13 @@ public Mono> commitBlockList(List base64BlockIDs */ public Mono> commitBlockList(List base64BlockIDs, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return blockBlobAsyncRawClient - .commitBlockList(base64BlockIDs, headers, metadata, accessConditions) + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.blockBlobs().commitBlockListWithRestResponseAsync( + null, null, new BlockLookupList().latest(base64BlockIDs), null, metadata, + null, null, null, null, headers, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java deleted file mode 100644 index 03b7e650167b6..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncRawClient.java +++ /dev/null @@ -1,364 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.BlockBlobsCommitBlockListResponse; -import com.azure.storage.blob.models.BlockBlobsGetBlockListResponse; -import com.azure.storage.blob.models.BlockBlobsStageBlockFromURLResponse; -import com.azure.storage.blob.models.BlockBlobsStageBlockResponse; -import com.azure.storage.blob.models.BlockBlobsUploadResponse; -import com.azure.storage.blob.models.BlockListType; -import com.azure.storage.blob.models.BlockLookupList; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.URL; -import java.util.List; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a block blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is instead a convenient - * way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - * for more information on block blobs. - */ -final class BlockBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the maximum number of bytes that can be sent in a call to upload. - */ - public static final int MAX_UPLOAD_BLOB_BYTES = 256 * Constants.MB; - - /** - * Indicates the maximum number of bytes that can be sent in a call to stageBlock. - */ - public static final int MAX_STAGE_BLOCK_BYTES = 100 * Constants.MB; - - /** - * Indicates the maximum number of blocks allowed in a block blob. - */ - public static final int MAX_BLOCKS = 50000; - - /** - * Creates a {@code BlockBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - */ - BlockBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - super(azureBlobStorage, snapshot); - } - - - /** - * Creates a new block blob, or updates the content of an existing block blob. - * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not - * supported with PutBlob; the content of the existing blob is overwritten with the new content. To - * perform a partial update of a block blob's, use PutBlock and PutBlockList. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - *

- * - * @param data - * The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobAsyncRawClient.upload")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono upload(Flux data, long length) { - return this.upload(data, length, null, null, null); - } - - /** - * Creates a new block blob, or updates the content of an existing block blob. - * Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not - * supported with PutBlob; the content of the existing blob is overwritten with the new content. To - * perform a partial update of a block blob's, use PutBlock and PutBlockList. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - *

- * - * @param data - * The data to write to the blob. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=upload_download "Sample code for BlockBlobAsyncRawClient.upload")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono upload(Flux data, long length, BlobHTTPHeaders headers, - Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blockBlobs().uploadWithRestResponseAsync(null, - null, data, length, null, metadata, null, null, - null, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Uploads the specified block to the block blob's "staging area" to be later committed by a call to - * commitBlockList. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param data - * The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.stageBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlock(String base64BlockID, Flux data, - long length) { - return this.stageBlock(base64BlockID, data, length, null); - } - - /** - * Uploads the specified block to the block blob's "staging area" to be later committed by a call to - * commitBlockList. For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param data - * The data to write to the block. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param length - * The exact length of the data. It is important that this value match precisely the length of the data - * emitted by the {@code Flux}. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.stageBlock")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlock(String base64BlockID, Flux data, long length, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blockBlobs().stageBlockWithRestResponseAsync(null, - null, base64BlockID, length, data, null, null, null, - null, null, null, leaseAccessConditions, Context.NONE)); - } - - /** - * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more - * information, see the Azure Docs. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceRange - * {@link BlobRange} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobAsyncRawClient.stageBlockFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, - BlobRange sourceRange) { - return this.stageBlockFromURL(base64BlockID, sourceURL, sourceRange, null, - null, null); - } - - /** - * Creates a new block to be committed as part of a blob where the contents are read from a URL. For more - * information, see the Azure Docs. - * - * @param base64BlockID - * A Base64 encoded {@code String} that specifies the ID for this block. Note that all block ids for a given - * blob must be the same length. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can - * be authenticated via Shared Key. However, if the source is a blob in another account, the source blob - * must either be public or must be authenticated via a shared access signature. If the source blob is - * public, no authentication is required to perform the operation. - * @param sourceRange - * {@link BlobRange} - * @param sourceContentMD5 - * An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param sourceModifiedAccessConditions - * {@link SourceModifiedAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=block_from_url "Sample code for BlockBlobAsyncRawClient.stageBlockFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono stageBlockFromURL(String base64BlockID, URL sourceURL, - BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions, - SourceModifiedAccessConditions sourceModifiedAccessConditions) { - sourceRange = sourceRange == null ? new BlobRange(0) : sourceRange; - - return postProcessResponse( - this.azureBlobStorage.blockBlobs().stageBlockFromURLWithRestResponseAsync(null, null, - base64BlockID, 0, sourceURL, sourceRange.toHeaderValue(), sourceContentMD5, null, - null, null, null, null, - leaseAccessConditions, sourceModifiedAccessConditions, Context.NONE)); - } - - /** - * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. - * For more information, see the - * Azure Docs. - * - * @param listType - * Specifies which type of blocks to return. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlocks(BlockListType listType) { - return this.listBlocks(listType, null); - } - - /** - * Returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter. - * For more information, see the - * Azure Docs. - * - * @param listType - * Specifies which type of blocks to return. - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlocks(BlockListType listType, - LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync( - null, null, listType, snapshot, null, null, null, - leaseAccessConditions, Context.NONE)); - } - - /** - * Writes a blob by specifying the list of block IDs that are to make up the blob. - * In order to be written as part of a blob, a block must have been successfully written - * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob - * by uploading only those blocks that have changed, then committing the new and existing - * blocks together. Any blocks not specified in the block list and permanently deleted. - * For more information, see the - * Azure Docs. - *

- * - * @param base64BlockIDs - * A list of base64 encode {@code String}s that specifies the block IDs to be committed. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.commitBlockList")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono commitBlockList(List base64BlockIDs) { - return this.commitBlockList(base64BlockIDs, null, null, null); - } - - /** - * Writes a blob by specifying the list of block IDs that are to make up the blob. - * In order to be written as part of a blob, a block must have been successfully written - * to the server in a prior stageBlock operation. You can call commitBlockList to update a blob - * by uploading only those blocks that have changed, then committing the new and existing - * blocks together. Any blocks not specified in the block list and permanently deleted. - * For more information, see the - * Azure Docs. - *

- * - * @param base64BlockIDs - * A list of base64 encode {@code String}s that specifies the block IDs to be committed. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.commitBlockList")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono commitBlockList(List base64BlockIDs, - BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.blockBlobs().commitBlockListWithRestResponseAsync( - null, null, new BlockLookupList().latest(base64BlockIDs), null, metadata, - null, null, null, null, headers, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java index 9dced1f87022b..ec76f684c1bb4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobClient.java @@ -4,7 +4,6 @@ package com.azure.storage.blob; import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -44,22 +43,22 @@ * for more information. */ public final class BlockBlobClient extends BlobClient { + private final BlockBlobAsyncClient blockBlobAsyncClient; - private BlockBlobAsyncClient blockBlobAsyncClient; /** * Indicates the maximum number of bytes that can be sent in a call to upload. */ - public static final int MAX_UPLOAD_BLOB_BYTES = 256 * Constants.MB; + public static final int MAX_UPLOAD_BLOB_BYTES = BlockBlobAsyncClient.MAX_UPLOAD_BLOB_BYTES; /** * Indicates the maximum number of bytes that can be sent in a call to stageBlock. */ - public static final int MAX_STAGE_BLOCK_BYTES = 100 * Constants.MB; + public static final int MAX_STAGE_BLOCK_BYTES = BlockBlobAsyncClient.MAX_STAGE_BLOCK_BYTES; /** * Indicates the maximum number of blocks allowed in a block blob. */ - public static final int MAX_BLOCKS = 50000; + public static final int MAX_BLOCKS = BlockBlobAsyncClient.MAX_BLOCKS; /** * Package-private constructor for use by {@link BlockBlobClientBuilder}. @@ -161,9 +160,8 @@ public Response upload(InputStream data, long length, BlobHTTPHea return ByteBufAllocator.DEFAULT.buffer((int) count).writeBytes(cache); })); - Mono> upload = blockBlobAsyncClient.blockBlobAsyncRawClient - .upload(fbb.subscribeOn(Schedulers.elastic()), length, headers, metadata, accessConditions) - .map(rb -> new SimpleResponse<>(rb, new BlockBlobItem(rb.deserializedHeaders()))); + Mono> upload = blockBlobAsyncClient + .upload(fbb.subscribeOn(Schedulers.elastic()), length, headers, metadata, accessConditions); try { return Utility.blockWithOptionalTimeout(upload, timeout); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index f979f084ac151..6d9e64f16a924 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -9,6 +9,7 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobFlatListSegment; import com.azure.storage.blob.models.BlobHierarchyListSegment; import com.azure.storage.blob.models.BlobItem; @@ -33,57 +34,59 @@ import java.net.URL; import java.time.Duration; import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.List; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** - * Client to a container. It may only be instantiated through a {@link ContainerClientBuilder} or via the method - * {@link StorageAsyncClient#getContainerAsyncClient(String)}. This class does not hold any - * state about a particular blob but is instead a convenient way of sending off appropriate requests to - * the resource on the service. It may also be used to construct URLs to blobs. + * Client to a container. It may only be instantiated through a {@link ContainerClientBuilder} or via the method {@link + * StorageAsyncClient#getContainerAsyncClient(String)}. This class does not hold any state about a particular blob but + * is instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used + * to construct URLs to blobs. * *

* This client contains operations on a container. Operations on a blob are available on {@link BlobAsyncClient} through * {@link #getBlobAsyncClient(String)}, and operations on the service are available on {@link StorageAsyncClient}. * *

- * Please refer to the Azure Docs - * for more information on containers. + * Please refer to the Azure + * Docs for more information on containers. * *

- * Note this client is an async client that returns reactive responses from Spring Reactor Core - * project (https://projectreactor.io/). Calling the methods in this client will NOT - * start the actual network operation, until {@code .subscribe()} is called on the reactive response. - * You can simply convert one of these responses to a {@link java.util.concurrent.CompletableFuture} - * object through {@link Mono#toFuture()}. + * Note this client is an async client that returns reactive responses from Spring Reactor Core project + * (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network + * operation, until {@code .subscribe()} is called on the reactive response. You can simply convert one of these + * responses to a {@link java.util.concurrent.CompletableFuture} object through {@link Mono#toFuture()}. */ public final class ContainerAsyncClient { - ContainerAsyncRawClient containerAsyncRawClient; - public static final String ROOT_CONTAINER_NAME = "$root"; public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; public static final String LOG_CONTAINER_NAME = "$logs"; + private final AzureBlobStorageImpl azureBlobStorage; + /** * Package-private constructor for use by {@link ContainerClientBuilder}. + * * @param azureBlobStorageBuilder the API client builder for blob storage API */ ContainerAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.containerAsyncRawClient = new ContainerAsyncRawClient(azureBlobStorageBuilder.build()); + this.azureBlobStorage = azureBlobStorageBuilder.build(); } /** * Creates a new {@link BlockBlobAsyncClient} object by concatenating the blobName to the end of - * ContainerAsyncClient's URL. The new BlockBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlockBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's - * NewBlockBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * - * @return A new {@link BlockBlobAsyncClient} object which references the blob with the specified name in this container. + * ContainerAsyncClient's URL. The new BlockBlobAsyncClient uses the same request policy pipeline as the + * ContainerAsyncClient. To change the pipeline, create the BlockBlobAsyncClient and then call its WithPipeline + * method passing in the desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling + * this object's NewBlockBlobAsyncClient method. + * + * @param blobName A {@code String} representing the name of the blob. + * @return A new {@link BlockBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { return getBlockBlobAsyncClient(blobName, null); @@ -91,106 +94,95 @@ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { /** * Creates a new {@link BlockBlobAsyncClient} object by concatenating the blobName to the end of - * ContainerAsyncClient's URL. The new BlockBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlockBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's - * NewBlockBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. - * - * @return A new {@link BlockBlobAsyncClient} object which references the blob with the specified name in this container. + * ContainerAsyncClient's URL. The new BlockBlobAsyncClient uses the same request policy pipeline as the + * ContainerAsyncClient. To change the pipeline, create the BlockBlobAsyncClient and then call its WithPipeline + * method passing in the desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling + * this object's NewBlockBlobAsyncClient method. + * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. + * @return A new {@link BlockBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName, String snapshot) { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** - * Creates creates a new PageBlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new PageBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the PageBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's - * NewPageBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * - * @return A new {@link PageBlobAsyncClient} object which references the blob with the specified name in this container. + * Creates creates a new PageBlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's + * URL. The new PageBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the PageBlobAsyncClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's NewPageBlobAsyncClient + * method. + * + * @param blobName A {@code String} representing the name of the blob. + * @return A new {@link PageBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName) { return getPageBlobAsyncClient(blobName, null); } /** - * Creates creates a new PageBlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new PageBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the PageBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's - * NewPageBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. - * - * @return A new {@link PageBlobAsyncClient} object which references the blob with the specified name in this container. + * Creates creates a new PageBlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's + * URL. The new PageBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the PageBlobAsyncClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's NewPageBlobAsyncClient + * method. + * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. + * @return A new {@link PageBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName, String snapshot) { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** - * Creates creates a new AppendBlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new AppendBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the AppendBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's + * Creates creates a new AppendBlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's + * URL. The new AppendBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change + * the pipeline, create the AppendBlobAsyncClient and then call its WithPipeline method passing in the desired + * pipeline object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's * NewAppendBlobAsyncClient method. * - * @param blobName - * A {@code String} representing the name of the blob. - * - * @return A new {@link AppendBlobAsyncClient} object which references the blob with the specified name in this container. + * @param blobName A {@code String} representing the name of the blob. + * @return A new {@link AppendBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName) { return getAppendBlobAsyncClient(blobName, null); } /** - * Creates creates a new AppendBlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new AppendBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the AppendBlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's + * Creates creates a new AppendBlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's + * URL. The new AppendBlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change + * the pipeline, create the AppendBlobAsyncClient and then call its WithPipeline method passing in the desired + * pipeline object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's * NewAppendBlobAsyncClient method. * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. - * - * @return A new {@link AppendBlobAsyncClient} object which references the blob with the specified name in this container. + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. + * @return A new {@link AppendBlobAsyncClient} object which references the blob with the specified name in this + * container. */ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName, String snapshot) { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** - * Creates a new BlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's getBlobAsyncClient instead of calling this object's - * getBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. + * Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new + * BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, create + * the BlobAsyncClient and then call its WithPipeline method passing in the desired pipeline object. Or, call this + * package's getBlobAsyncClient instead of calling this object's getBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. * @return A new {@link BlobAsyncClient} object which references the blob with the specified name in this container. */ public BlobAsyncClient getBlobAsyncClient(String blobName) { @@ -198,55 +190,50 @@ public BlobAsyncClient getBlobAsyncClient(String blobName) { } /** - * Creates a new BlobAsyncClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlobAsyncClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's getBlobAsyncClient instead of calling this object's - * getBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. + * Creates a new BlobAsyncClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new + * BlobAsyncClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, create + * the BlobAsyncClient and then call its WithPipeline method passing in the desired pipeline object. Or, call this + * package's getBlobAsyncClient instead of calling this object's getBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. * @return A new {@link BlobAsyncClient} object which references the blob with the specified name in this container. */ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { return new BlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()), snapshot); } /** * Initializes a {@link StorageAsyncClient} object pointing to the storage account this container is in. * - * @return - * A {@link StorageAsyncClient} object pointing to the specified storage account + * @return A {@link StorageAsyncClient} object pointing to the specified storage account */ public StorageAsyncClient getStorageAsyncClient() { return new StorageAsyncClient(new AzureBlobStorageBuilder() .url(Utility.stripLastPathSegment(getContainerUrl()).toString()) - .pipeline(containerAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** * Gets the URL of the container represented by this client. + * * @return the URL. * @throws RuntimeException If the container has a malformed URL. */ public URL getContainerUrl() { try { - return new URL(containerAsyncRawClient.azureBlobStorage.url()); + return new URL(azureBlobStorage.url()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), containerAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } /** * Gets if the container this client represents exists in the cloud. * - * @return - * true if the container exists, false if it doesn't + * @return true if the container exists, false if it doesn't */ public Mono> exists() { return this.getProperties(null) @@ -262,8 +249,7 @@ public Mono> exists() { * fails. For more information, see the * Azure Docs. * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. */ public Mono create() { return this.create(null, null); @@ -274,47 +260,52 @@ public Mono create() { * fails. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @return A reactive response signalling completion. */ public Mono create(Metadata metadata, PublicAccessType accessType) { - return containerAsyncRawClient - .create(metadata, accessType) + metadata = metadata == null ? new Metadata() : metadata; + + return postProcessResponse(this.azureBlobStorage.containers().createWithRestResponseAsync( + null, null, metadata, accessType, null, Context.NONE)) .map(VoidResponse::new); } /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the + * Marks the specified container for deletion. The container and any blobs contained within it are later deleted + * during garbage collection. For more information, see the * Azure Docs. * - * @return - * A reactive response signalling completion. + * @return A reactive response signalling completion. */ public Mono delete() { return this.delete(null); } /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the + * Marks the specified container for deletion. The container and any blobs contained within it are later deleted + * during garbage collection. For more information, see the * Azure Docs. * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param accessConditions {@link ContainerAccessConditions} + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either + * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. */ public Mono delete(ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .delete(accessConditions) + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + + if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .deleteWithRestResponseAsync(null, null, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -322,8 +313,7 @@ public Mono delete(ContainerAccessConditions accessConditions) { * Returns the container's metadata and system properties. For more information, see the * Azure Docs. * - * @return - * A reactive response containing the container properties. + * @return A reactive response containing the container properties. */ public Mono> getProperties() { return this.getProperties(null); @@ -333,16 +323,14 @@ public Mono> getProperties() { * Returns the container's metadata and system properties. For more information, see the * Azure Docs. * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return - * A reactive response containing the container properties. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @return A reactive response containing the container properties. */ public Mono> getProperties(LeaseAccessConditions leaseAccessConditions) { - return containerAsyncRawClient - .getProperties(leaseAccessConditions) + return postProcessResponse(this.azureBlobStorage.containers() + .getPropertiesWithRestResponseAsync(null, null, null, + leaseAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new ContainerProperties(rb.deserializedHeaders()))); } @@ -350,11 +338,8 @@ public Mono> getProperties(LeaseAccessConditions l * Sets the container's metadata. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @return A reactive response signalling completion. */ public Mono setMetadata(Metadata metadata) { return this.setMetadata(metadata, null); @@ -364,18 +349,27 @@ public Mono setMetadata(Metadata metadata) { * Sets the container's metadata. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param metadata {@link Metadata} + * @param accessConditions {@link ContainerAccessConditions} + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has + * anything set other than {@link ModifiedAccessConditions#ifModifiedSince()}. */ public Mono setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .setMetadata(metadata, accessConditions) + ContainerAccessConditions accessConditions) { + metadata = metadata == null ? new Metadata() : metadata; + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + if (!validateNoEtag(accessConditions.modifiedAccessConditions()) + || accessConditions.modifiedAccessConditions().ifUnmodifiedSince() != null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "If-Modified-Since is the only HTTP access condition supported for this API"); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .setMetadataWithRestResponseAsync(null, null, metadata, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(VoidResponse::new); } @@ -384,8 +378,7 @@ public Mono setMetadata(Metadata metadata, * For more information, see the * Azure Docs. * - * @return - * A reactive response containing the container access policy. + * @return A reactive response containing the container access policy. */ public Mono> getAccessPolicy() { return this.getAccessPolicy(null); @@ -396,15 +389,13 @@ public Mono> getAccessPolicy() { * For more information, see the * Azure Docs. * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return - * A reactive response containing the container access policy. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @return A reactive response containing the container access policy. */ public Mono> getAccessPolicy(LeaseAccessConditions leaseAccessConditions) { - return containerAsyncRawClient.getAccessPolicy(leaseAccessConditions); + return postProcessResponse(this.azureBlobStorage.containers().getAccessPolicyWithRestResponseAsync(null, null, null, leaseAccessConditions, Context.NONE) + .map(response -> new SimpleResponse<>(response, new ContainerAccessPolicies(response.deserializedHeaders().blobPublicAccess(), response.value())))); } /** @@ -413,19 +404,16 @@ public Mono> getAccessPolicy(LeaseAccessCondit * ensure the time formatting is compatible with the service. For more information, see the * Azure Docs. * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * - * @return - * A reactive response signalling completion. + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @param identifiers A list of {@link SignedIdentifier} objects that specify the permissions for the container. + * Please see + * here + * for more information. Passing null will clear all access policies. + * @return A reactive response signalling completion. */ public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers) { + List identifiers) { return this.setAccessPolicy(accessType, identifiers, null); } @@ -435,79 +423,129 @@ public Mono setAccessPolicy(PublicAccessType accessType, * ensure the time formatting is compatible with the service. For more information, see the * Azure Docs. * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return - * A reactive response signalling completion. + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @param identifiers A list of {@link SignedIdentifier} objects that specify the permissions for the container. + * Please see + * here + * for more information. Passing null will clear all access policies. + * @param accessConditions {@link ContainerAccessConditions} + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either + * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. */ public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions) { - return containerAsyncRawClient - .setAccessPolicy(accessType, identifiers, accessConditions) + List identifiers, ContainerAccessConditions accessConditions) { + accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; + + if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); + } + + /* + We truncate to seconds because the service only supports nanoseconds or seconds, but doing an + OffsetDateTime.now will only give back milliseconds (more precise fields are zeroed and not serialized). This + allows for proper serialization with no real detriment to users as sub-second precision on active time for + signed identifiers is not really necessary. + */ + if (identifiers != null) { + for (SignedIdentifier identifier : identifiers) { + if (identifier.accessPolicy() != null && identifier.accessPolicy().start() != null) { + identifier.accessPolicy().start( + identifier.accessPolicy().start().truncatedTo(ChronoUnit.SECONDS)); + } + if (identifier.accessPolicy() != null && identifier.accessPolicy().expiry() != null) { + identifier.accessPolicy().expiry( + identifier.accessPolicy().expiry().truncatedTo(ChronoUnit.SECONDS)); + } + } + } + + return postProcessResponse(this.azureBlobStorage.containers() + .setAccessPolicyWithRestResponseAsync(null, identifiers, null, accessType, + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .map(VoidResponse::new); } /** - * Returns a reactive Publisher emitting all the blobs in this container lazily as needed. - * The directories are flattened and only actual blobs and no directories are returned. + * Returns a reactive Publisher emitting all the blobs in this container lazily as needed. The directories are + * flattened and only actual blobs and no directories are returned. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return * *

    - *
  • foo/foo1 - *
  • foo/foo2 - *
  • bar + *
  • foo/foo1 + *
  • foo/foo2 + *
  • bar *
* - * @return - * A reactive response emitting the flattened blobs. + * @return A reactive response emitting the flattened blobs. */ public Flux listBlobsFlat() { return this.listBlobsFlat(new ListBlobsOptions()); } /** - * Returns a reactive Publisher emitting all the blobs in this container lazily as needed. - * The directories are flattened and only actual blobs and no directories are returned. + * Returns a reactive Publisher emitting all the blobs in this container lazily as needed. The directories are + * flattened and only actual blobs and no directories are returned. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return * *

    - *
  • foo/foo1 - *
  • foo/foo2 - *
  • bar + *
  • foo/foo1 + *
  • foo/foo2 + *
  • bar *
* + * @param options {@link ListBlobsOptions} + * @return A reactive response emitting the listed blobs, flattened. + */ + public Flux listBlobsFlat(ListBlobsOptions options) { + return listBlobsFlatSegment(null, options).flatMapMany(response -> listBlobsFlatHelper(options, response)); + } + + /* + * Returns a single segment of blobs starting from the specified Marker. Use an empty + * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. + * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned + * Marker) to get the next segment. For more information, see the + * Azure Docs. + * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. * @param options * {@link ListBlobsOptions} * - * @return - * A reactive response emitting the listed blobs, flattened. + * @return Emits the successful response. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) */ - public Flux listBlobsFlat(ListBlobsOptions options) { - return containerAsyncRawClient - .listBlobsFlatSegment(null, options) - .flatMapMany(response -> listBlobsFlatHelper(options, response)); + private Mono listBlobsFlatSegment(String marker, ListBlobsOptions options) { + options = options == null ? new ListBlobsOptions() : options; + + return postProcessResponse(this.azureBlobStorage.containers() + .listBlobFlatSegmentWithRestResponseAsync(null, options.prefix(), marker, + options.maxResults(), options.details().toList(), null, null, Context.NONE)); } private Flux listBlobsFlatHelper(ListBlobsOptions options, ContainersListBlobFlatSegmentResponse response) { @@ -521,7 +559,7 @@ private Flux listBlobsFlatHelper(ListBlobsOptions options, ContainersL if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(containerAsyncRawClient.listBlobsFlatSegment(response.value().nextMarker(), options) + result = result.concatWith(listBlobsFlatSegment(response.value().nextMarker(), options) .flatMapMany(r -> listBlobsFlatHelper(options, r))); } @@ -529,80 +567,109 @@ private Flux listBlobsFlatHelper(ListBlobsOptions options, ContainersL } /** - * Returns a reactive Publisher emitting all the blobs and directories (prefixes) under - * the given directory (prefix). Directories will have {@link BlobItem#isPrefix()} set to - * true. + * Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory + * (prefix). Directories will have {@link BlobItem#isPrefix()} set to true. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return the following results when prefix=null: + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return the following results when prefix=null: * *

    - *
  • foo/ (isPrefix = true) - *
  • bar (isPrefix = false) + *
  • foo/ (isPrefix = true) + *
  • bar (isPrefix = false) *
*

* will return the following results when prefix="foo/": * *

    - *
  • foo/foo1 (isPrefix = false) - *
  • foo/foo2 (isPrefix = false) + *
  • foo/foo1 (isPrefix = false) + *
  • foo/foo2 (isPrefix = false) *
* - * @param directory - * The directory to list blobs underneath - * - * @return - * A reactive response emitting the prefixes and blobs. + * @param directory The directory to list blobs underneath + * @return A reactive response emitting the prefixes and blobs. */ public Flux listBlobsHierarchy(String directory) { return this.listBlobsHierarchy("/", new ListBlobsOptions().prefix(directory)); } /** - * Returns a reactive Publisher emitting all the blobs and prefixes (directories) under - * the given prefix (directory). Directories will have {@link BlobItem#isPrefix()} set to - * true. + * Returns a reactive Publisher emitting all the blobs and prefixes (directories) under the given prefix + * (directory). Directories will have {@link BlobItem#isPrefix()} set to true. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return the following results when prefix=null: + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return the following results when prefix=null: * *

    - *
  • foo/ (isPrefix = true) - *
  • bar (isPrefix = false) + *
  • foo/ (isPrefix = true) + *
  • bar (isPrefix = false) *
*

* will return the following results when prefix="foo/": * *

    - *
  • foo/foo1 (isPrefix = false) - *
  • foo/foo2 (isPrefix = false) + *
  • foo/foo1 (isPrefix = false) + *
  • foo/foo2 (isPrefix = false) *
* + * @param delimiter The delimiter for blob hierarchy, "/" for hierarchy based on directories + * @param options {@link ListBlobsOptions} + * @return A reactive response emitting the prefixes and blobs. + */ + public Flux listBlobsHierarchy(String delimiter, ListBlobsOptions options) { + return listBlobsHierarchySegment(null, delimiter, options) + .flatMapMany(response -> listBlobsHierarchyHelper(delimiter, options, Context.NONE, response)); + } + + /* + * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty + * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. + * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned + * Marker) to get the next segment. For more information, see the + * Azure Docs. + * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. * @param delimiter - * The delimiter for blob hierarchy, "/" for hierarchy based on directories + * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs + * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may + * be a single character or a string. * @param options * {@link ListBlobsOptions} * - * @return - * A reactive response emitting the prefixes and blobs. + * @return Emits the successful response. + * @throws UnsupportedOperationException If {@link ListBlobsOptions#details()} has {@link BlobListDetails#snapshots()} + * set. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) */ - public Flux listBlobsHierarchy(String delimiter, ListBlobsOptions options) { - return containerAsyncRawClient.listBlobsHierarchySegment(null, delimiter, options) - .flatMapMany(response -> listBlobsHierarchyHelper(delimiter, options, Context.NONE, response)); + private Mono listBlobsHierarchySegment(String marker, String delimiter, ListBlobsOptions options) { + options = options == null ? new ListBlobsOptions() : options; + if (options.details().snapshots()) { + throw new UnsupportedOperationException("Including snapshots in a hierarchical listing is not supported."); + } + + return postProcessResponse(this.azureBlobStorage.containers() + .listBlobHierarchySegmentWithRestResponseAsync(null, delimiter, options.prefix(), marker, + options.maxResults(), options.details().toList(), null, null, Context.NONE)); } private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptions options, - Context context, ContainersListBlobHierarchySegmentResponse response) { + Context context, ContainersListBlobHierarchySegmentResponse response) { Flux blobs; Flux prefixes; BlobHierarchyListSegment segment = response.value().segment(); @@ -620,7 +687,7 @@ private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptio if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(containerAsyncRawClient.listBlobsHierarchySegment(response.value().nextMarker(), delimiter, options) + result = result.concatWith(listBlobsHierarchySegment(response.value().nextMarker(), delimiter, options) .flatMapMany(r -> listBlobsHierarchyHelper(delimiter, options, context, r))); } @@ -699,14 +766,10 @@ private Flux listBlobsHierarchyHelper(String delimiter, ListBlobsOptio * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return - * A reactive response containing the lease ID. + * @param proposedId A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @return A reactive response containing the lease ID. */ public Mono> acquireLease(String proposedId, int duration) { return this.acquireLease(proposedId, duration, null); @@ -716,33 +779,34 @@ public Mono> acquireLease(String proposedId, int duration) { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the lease ID. + * @param proposedID A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or {@link + * ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> acquireLease(String proposedID, int duration, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .acquireLease(proposedID, duration, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().acquireLeaseWithRestResponseAsync( + null, null, duration, proposedID, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * A reactive response containing the renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @return A reactive response containing the renewed lease ID. */ public Mono> renewLease(String leaseID) { return this.renewLease(leaseID, null); @@ -751,30 +815,32 @@ public Mono> renewLease(String leaseID) { /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the renewed lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or {@link + * ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .renewLease(leaseID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().renewLeaseWithRestResponseAsync(null, + leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * A reactive response signalling completion. + * @param leaseID The leaseId of the active lease on the blob. + * @return A reactive response signalling completion. */ public Mono releaseLease(String leaseID) { return this.releaseLease(leaseID, null); @@ -783,19 +849,24 @@ public Mono releaseLease(String leaseID) { /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response signalling completion. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response signalling completion. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or {@link + * ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono releaseLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .releaseLease(leaseID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().releaseLeaseWithRestResponseAsync( + null, leaseID, null, null, modifiedAccessConditions, Context.NONE)) .map(VoidResponse::new); } @@ -803,8 +874,7 @@ public Mono releaseLease(String leaseID, ModifiedAccessConditions * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @return - * A reactive response containing the remaining time in the broken lease. + * @return A reactive response containing the remaining time in the broken lease. */ public Mono> breakLease() { return this.breakLease(null, null); @@ -814,58 +884,65 @@ public Mono> breakLease() { * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return - * A reactive response containing the remaining time in the broken lease. + * @param breakPeriodInSeconds An optional {@code Integer} representing the proposed duration of seconds that the + * lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is + * shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease + * will not be available before the break period has expired, but the lease may be held for longer than the break + * period. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @return A reactive response containing the remaining time in the broken lease. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or {@link + * ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> breakLease(Integer breakPeriodInSeconds, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .breakLease(breakPeriodInSeconds, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().breakLeaseWithRestResponseAsync(null, + null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, Duration.ofSeconds(rb.deserializedHeaders().leaseTime()))); } /** * ChangeLease changes the blob's lease ID. * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return - * A reactive response containing the new lease ID. + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @return A reactive response containing the new lease ID. */ public Mono> changeLease(String leaseId, String proposedID) { return this.changeLease(leaseId, proposedID, null); } /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * + * ChangeLease changes the blob's lease ID. For more information, see the Azure + * Docs. + * + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. * @return A reactive response containing the new lease ID. + * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or {@link + * ModifiedAccessConditions#ifNoneMatch()} is set. */ public Mono> changeLease(String leaseId, String proposedID, ModifiedAccessConditions modifiedAccessConditions) { - return containerAsyncRawClient - .changeLease(leaseId, proposedID, modifiedAccessConditions) + if (!this.validateNoEtag(modifiedAccessConditions)) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new UnsupportedOperationException( + "ETag access conditions are not supported for this API."); + } + + return postProcessResponse(this.azureBlobStorage.containers().changeLeaseWithRestResponseAsync(null, + leaseId, proposedID, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().leaseId())); } @@ -873,63 +950,52 @@ public Mono> changeLease(String leaseId, String proposedID, Mod * Returns the sku name and account kind for the account. For more information, please see the * Azure Docs. * - * @return - * A reactive response containing the account info. + * @return A reactive response containing the account info. */ public Mono> getAccountInfo() { - return containerAsyncRawClient - .getAccountInfo() + return postProcessResponse( + this.azureBlobStorage.containers().getAccountInfoWithRestResponseAsync(null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } + private boolean validateNoEtag(ModifiedAccessConditions modifiedAccessConditions) { + if (modifiedAccessConditions == null) { + return true; + } + return modifiedAccessConditions.ifMatch() == null && modifiedAccessConditions.ifNoneMatch() == null; + } + /** * Generates a user delegation SAS with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime) { - return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null /* - startTime */, null /* version */, null /* sasProtocol */, null /* ipRange */, null /* cacheControl */, null - /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); + ContainerSASPermission permissions, OffsetDateTime expiryTime) { + return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, null, null, + null, null, null, null, null, null, null); } /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange) { + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { return this.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /* contentType */); @@ -938,40 +1004,25 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, - String contentEncoding, String contentLanguage, String contentType) { + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, null /* identifier*/, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); @@ -986,13 +1037,9 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a SAS token with the specified parameters * - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateSAS(ContainerSASPermission permissions, OffsetDateTime expiryTime) { return this.generateSAS(null, permissions, /* identifier */ expiryTime, null /* startTime */, null /* version @@ -1003,11 +1050,8 @@ public String generateSAS(ContainerSASPermission permissions, OffsetDateTime exp /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @return A string that represents the SAS token */ public String generateSAS(String identifier) { return this.generateSAS(identifier, null /* permissions*/, null /* expiryTime */, null /* startTime */, null @@ -1018,27 +1062,18 @@ public String generateSAS(String identifier) { /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, - String version, SASProtocol sasProtocol, IPRange ipRange) { + OffsetDateTime startTime, + String version, SASProtocol sasProtocol, IPRange ipRange) { return this.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, null /* cacheControl */, null /* contentDisposition */, null /* contentEncoding */, null /* contentLanguage */, null /*contentType*/); @@ -1047,43 +1082,29 @@ public String generateSAS(String identifier, ContainerSASPermission permissions, /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, - String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { ServiceSASSignatureValues serviceSASSignatureValues = new ServiceSASSignatureValues(version, sasProtocol, startTime, expiryTime, permissions == null ? null : permissions.toString(), ipRange, identifier, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); SharedKeyCredential sharedKeyCredential = - Utility.getSharedKeyCredential(this.containerAsyncRawClient.azureBlobStorage.httpPipeline()); + Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); Utility.assertNotNull("sharedKeyCredential", sharedKeyCredential); @@ -1100,7 +1121,7 @@ public String generateSAS(String identifier, ContainerSASPermission permissions, */ private ServiceSASSignatureValues configureServiceSASSignatureValues(ServiceSASSignatureValues serviceSASSignatureValues, String accountName) { // Set canonical name - serviceSASSignatureValues.canonicalName(this.containerAsyncRawClient.azureBlobStorage.url(), accountName); + serviceSASSignatureValues.canonicalName(this.azureBlobStorage.url(), accountName); // Set snapshotId to null serviceSASSignatureValues.snapshotId(null); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java deleted file mode 100644 index e4106549b208c..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncRawClient.java +++ /dev/null @@ -1,708 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.SimpleResponse; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobListDetails; -import com.azure.storage.blob.models.ContainerAccessConditions; -import com.azure.storage.blob.models.ContainerAccessPolicies; -import com.azure.storage.blob.models.ContainersAcquireLeaseResponse; -import com.azure.storage.blob.models.ContainersBreakLeaseResponse; -import com.azure.storage.blob.models.ContainersChangeLeaseResponse; -import com.azure.storage.blob.models.ContainersCreateResponse; -import com.azure.storage.blob.models.ContainersDeleteResponse; -import com.azure.storage.blob.models.ContainersGetAccountInfoResponse; -import com.azure.storage.blob.models.ContainersGetPropertiesResponse; -import com.azure.storage.blob.models.ContainersListBlobFlatSegmentResponse; -import com.azure.storage.blob.models.ContainersListBlobHierarchySegmentResponse; -import com.azure.storage.blob.models.ContainersReleaseLeaseResponse; -import com.azure.storage.blob.models.ContainersRenewLeaseResponse; -import com.azure.storage.blob.models.ContainersSetAccessPolicyResponse; -import com.azure.storage.blob.models.ContainersSetMetadataResponse; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.ListBlobsOptions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PublicAccessType; -import com.azure.storage.blob.models.SignedIdentifier; -import reactor.core.publisher.Mono; - -import java.time.temporal.ChronoUnit; -import java.util.List; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a container. It may be obtained by direct construction or via the create method on a - * {@link StorageAsyncRawClient} object. This class does not hold any state about a particular blob but is instead a convenient way - * of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs. - * Please refer to the - * Azure Docs - * for more information on containers. - */ -final class ContainerAsyncRawClient { - - public static final String ROOT_CONTAINER_NAME = "$root"; - - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; - - public static final String LOG_CONTAINER_NAME = "$logs"; - - AzureBlobStorageImpl azureBlobStorage; - - /** - * Creates a {@code ContainerAsyncClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - ContainerAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.azureBlobStorage = azureBlobStorage; - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create() { - return this.create(null, null); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(Metadata metadata, PublicAccessType accessType) { - metadata = metadata == null ? new Metadata() : metadata; - - return postProcessResponse(this.azureBlobStorage.containers().createWithRestResponseAsync( - null, null, metadata, accessType, null, Context.NONE)); - - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete() { - return this.delete(null); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either - * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono delete(ContainerAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - - if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .deleteWithRestResponseAsync(null, null, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return this.getProperties(null); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties(LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.containers() - .getPropertiesWithRestResponseAsync(null, null, null, - leaseAccessConditions, Context.NONE)); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has anything - * set other than {@link ModifiedAccessConditions#ifModifiedSince()}. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions) { - metadata = metadata == null ? new Metadata() : metadata; - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - if (!validateNoEtag(accessConditions.modifiedAccessConditions()) - || accessConditions.modifiedAccessConditions().ifUnmodifiedSince() != null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "If-Modified-Since is the only HTTP access condition supported for this API"); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .setMetadataWithRestResponseAsync(null, null, metadata, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono> getAccessPolicy() { - return this.getAccessPolicy(null); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono> getAccessPolicy(LeaseAccessConditions leaseAccessConditions) { - return postProcessResponse(this.azureBlobStorage.containers().getAccessPolicyWithRestResponseAsync(null, null, null, leaseAccessConditions, Context.NONE) - .map(response -> new SimpleResponse<>(response, new ContainerAccessPolicies(response.deserializedHeaders().blobPublicAccess(), response.value())))); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers) { - return this.setAccessPolicy(accessType, identifiers, null); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ContainerAccessConditions#modifiedAccessConditions()} has either - * {@link ModifiedAccessConditions#ifMatch()} or {@link ModifiedAccessConditions#ifNoneMatch()} set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions; - - if (!validateNoEtag(accessConditions.modifiedAccessConditions())) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException("ETag access conditions are not supported for this API."); - } - - /* - We truncate to seconds because the service only supports nanoseconds or seconds, but doing an - OffsetDateTime.now will only give back milliseconds (more precise fields are zeroed and not serialized). This - allows for proper serialization with no real detriment to users as sub-second precision on active time for - signed identifiers is not really necessary. - */ - if (identifiers != null) { - for (SignedIdentifier identifier : identifiers) { - if (identifier.accessPolicy() != null && identifier.accessPolicy().start() != null) { - identifier.accessPolicy().start( - identifier.accessPolicy().start().truncatedTo(ChronoUnit.SECONDS)); - } - if (identifier.accessPolicy() != null && identifier.accessPolicy().expiry() != null) { - identifier.accessPolicy().expiry( - identifier.accessPolicy().expiry().truncatedTo(ChronoUnit.SECONDS)); - } - } - } - - return postProcessResponse(this.azureBlobStorage.containers() - .setAccessPolicyWithRestResponseAsync(null, identifiers, null, accessType, - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - - } - - private boolean validateNoEtag(ModifiedAccessConditions modifiedAccessConditions) { - if (modifiedAccessConditions == null) { - return true; - } - return modifiedAccessConditions.ifMatch() == null && modifiedAccessConditions.ifNoneMatch() == null; - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @param proposedId - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().acquireLeaseWithRestResponseAsync( - null, null, duration, proposedID, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID) { - return this.renewLease(leaseID, null); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono renewLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().renewLeaseWithRestResponseAsync(null, - leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID) { - return this.releaseLease(leaseID, null); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().releaseLeaseWithRestResponseAsync( - null, leaseID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return Emits the successful response. - */ - public Mono breakLease() { - return this.breakLease(null, null); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time - * remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().breakLeaseWithRestResponseAsync(null, - null, breakPeriodInSeconds, null, modifiedAccessConditions, Context.NONE)); - - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseID, String proposedID) { - return this.changeLease(leaseID, proposedID, null); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If either {@link ModifiedAccessConditions#ifMatch()} or - * {@link ModifiedAccessConditions#ifNoneMatch()} is set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono changeLease(String leaseID, String proposedID, - ModifiedAccessConditions modifiedAccessConditions) { - if (!this.validateNoEtag(modifiedAccessConditions)) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new UnsupportedOperationException( - "ETag access conditions are not supported for this API."); - } - - return postProcessResponse(this.azureBlobStorage.containers().changeLeaseWithRestResponseAsync(null, - leaseID, proposedID, null, null, modifiedAccessConditions, Context.NONE)); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlobsFlatSegment(String marker, ListBlobsOptions options) { - options = options == null ? new ListBlobsOptions() : options; - - return postProcessResponse(this.azureBlobStorage.containers() - .listBlobFlatSegmentWithRestResponseAsync(null, options.prefix(), marker, - options.maxResults(), options.details().toList(), null, null, Context.NONE)); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * @throws UnsupportedOperationException If {@link ListBlobsOptions#details()} has {@link BlobListDetails#snapshots()} - * set. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options) { - options = options == null ? new ListBlobsOptions() : options; - if (options.details().snapshots()) { - throw new UnsupportedOperationException("Including snapshots in a hierarchical listing is not supported."); - } - - return postProcessResponse(this.azureBlobStorage.containers() - .listBlobHierarchySegmentWithRestResponseAsync(null, delimiter, options.prefix(), marker, - options.maxResults(), options.details().toList(), null, null, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.containers().getAccountInfoWithRestResponseAsync(null, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java index c9733fd3a7f61..de5d4f1431f39 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java @@ -25,47 +25,45 @@ import java.util.List; /** - * Client to a container. It may only be instantiated through a {@link ContainerClientBuilder} or via the method - * {@link StorageClient#getContainerClient(String)}. This class does not hold any - * state about a particular container but is instead a convenient way of sending off appropriate requests to - * the resource on the service. It may also be used to construct URLs to blobs. + * Client to a container. It may only be instantiated through a {@link ContainerClientBuilder} or via the method {@link + * StorageClient#getContainerClient(String)}. This class does not hold any state about a particular container but is + * instead a convenient way of sending off appropriate requests to the resource on the service. It may also be used to + * construct URLs to blobs. * *

* This client contains operations on a container. Operations on a blob are available on {@link BlobClient} through * {@link #getBlobClient(String)}, and operations on the service are available on {@link StorageClient}. * *

- * Please refer to the Azure Docs - * for more information on containers. + * Please refer to the Azure + * Docs for more information on containers. */ public final class ContainerClient { - private ContainerAsyncClient containerAsyncClient; - public static final String ROOT_CONTAINER_NAME = "$root"; + public static final String ROOT_CONTAINER_NAME = ContainerAsyncClient.ROOT_CONTAINER_NAME; - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; + public static final String STATIC_WEBSITE_CONTAINER_NAME = ContainerAsyncClient.STATIC_WEBSITE_CONTAINER_NAME; - public static final String LOG_CONTAINER_NAME = "$logs"; + public static final String LOG_CONTAINER_NAME = ContainerAsyncClient.LOG_CONTAINER_NAME; /** * Package-private constructor for use by {@link ContainerClientBuilder}. + * * @param containerAsyncClient the async container client */ ContainerClient(ContainerAsyncClient containerAsyncClient) { - this.containerAsyncClient = containerAsyncClient; + this.containerAsyncClient = containerAsyncClient; } /** - * Creates a new {@link BlockBlobClient} object by concatenating the blobName to the end of - * ContainerAsyncClient's URL. The new BlockBlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlockBlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's - * NewBlockBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. + * Creates a new {@link BlockBlobClient} object by concatenating the blobName to the end of ContainerAsyncClient's + * URL. The new BlockBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the BlockBlobClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's NewBlockBlobAsyncClient + * method. * + * @param blobName A {@code String} representing the name of the blob. * @return A new {@link BlockBlobClient} object which references the blob with the specified name in this container. */ public BlockBlobClient getBlockBlobClient(String blobName) { @@ -73,17 +71,14 @@ public BlockBlobClient getBlockBlobClient(String blobName) { } /** - * Creates a new {@link BlockBlobClient} object by concatenating the blobName to the end of - * ContainerAsyncClient's URL. The new BlockBlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlockBlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's - * NewBlockBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. + * Creates a new {@link BlockBlobClient} object by concatenating the blobName to the end of ContainerAsyncClient's + * URL. The new BlockBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the BlockBlobClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewBlockBlobAsyncClient instead of calling this object's NewBlockBlobAsyncClient + * method. * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. * @return A new {@link BlockBlobClient} object which references the blob with the specified name in this container. */ public BlockBlobClient getBlockBlobClient(String blobName, String snapshot) { @@ -91,15 +86,12 @@ public BlockBlobClient getBlockBlobClient(String blobName, String snapshot) { } /** - * Creates creates a new PageBlobClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new PageBlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the PageBlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's - * NewPageBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. + * Creates creates a new PageBlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. + * The new PageBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, + * create the PageBlobClient and then call its WithPipeline method passing in the desired pipeline object. Or, call + * this package's NewPageBlobAsyncClient instead of calling this object's NewPageBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. * @return A new {@link PageBlobClient} object which references the blob with the specified name in this container. */ public PageBlobClient getPageBlobClient(String blobName) { @@ -107,17 +99,13 @@ public PageBlobClient getPageBlobClient(String blobName) { } /** - * Creates creates a new PageBlobClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new PageBlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the PageBlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewPageBlobAsyncClient instead of calling this object's - * NewPageBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. + * Creates creates a new PageBlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. + * The new PageBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, + * create the PageBlobClient and then call its WithPipeline method passing in the desired pipeline object. Or, call + * this package's NewPageBlobAsyncClient instead of calling this object's NewPageBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. * @return A new {@link PageBlobClient} object which references the blob with the specified name in this container. */ public PageBlobClient getPageBlobClient(String blobName, String snapshot) { @@ -125,31 +113,27 @@ public PageBlobClient getPageBlobClient(String blobName, String snapshot) { } /** - * Creates creates a new AppendBlobClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new AppendBlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the AppendBlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's + * Creates creates a new AppendBlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. + * The new AppendBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the AppendBlobClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's * NewAppendBlobAsyncClient method. * - * @param blobName - * A {@code String} representing the name of the blob. - * - * @return A new {@link AppendBlobClient} object which references the blob with the specified name in this container. + * @param blobName A {@code String} representing the name of the blob. + * @return A new {@link AppendBlobClient} object which references the blob with the specified name in this + * container. */ public AppendBlobClient getAppendBlobClient(String blobName) { return new AppendBlobClient(containerAsyncClient.getAppendBlobAsyncClient(blobName)); } /** - * Initializes a new BlobClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new BlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's getBlobAsyncClient instead of calling this object's - * getBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. + * Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new + * BlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, create the + * BlobClient and then call its WithPipeline method passing in the desired pipeline object. Or, call this package's + * getBlobAsyncClient instead of calling this object's getBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. * @return A new {@link BlobClient} object which references the blob with the specified name in this container. */ public BlobClient getBlobClient(String blobName) { @@ -157,17 +141,13 @@ public BlobClient getBlobClient(String blobName) { } /** - * Initializes a new BlobClient object by concatenating blobName to the end of - * ContainerAsyncClient's URL. The new BlobClient uses the same request policy pipeline as the ContainerAsyncClient. - * To change the pipeline, create the BlobClient and then call its WithPipeline method passing in the - * desired pipeline object. Or, call this package's getBlobAsyncClient instead of calling this object's - * getBlobAsyncClient method. - * - * @param blobName - * A {@code String} representing the name of the blob. - * @param snapshot - * the snapshot identifier for the blob. + * Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new + * BlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, create the + * BlobClient and then call its WithPipeline method passing in the desired pipeline object. Or, call this package's + * getBlobAsyncClient instead of calling this object's getBlobAsyncClient method. * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. * @return A new {@link BlobClient} object which references the blob with the specified name in this container. */ public BlobClient getBlobClient(String blobName, String snapshot) { @@ -177,8 +157,7 @@ public BlobClient getBlobClient(String blobName, String snapshot) { /** * Initializes a {@link StorageClient} object pointing to the storage account this container is in. * - * @return - * A {@link StorageClient} object pointing to the specified storage account + * @return A {@link StorageClient} object pointing to the specified storage account */ public StorageClient getStorageClient() { return new StorageClient(containerAsyncClient.getStorageAsyncClient()); @@ -186,6 +165,7 @@ public StorageClient getStorageClient() { /** * Gets the URL of the container represented by this client. + * * @return the URL. */ public URL getContainerUrl() { @@ -204,10 +184,8 @@ public Response exists() { /** * Gets if the container this client represents exists in the cloud. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * @return - * true if the container exists, false if it doesn't + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return true if the container exists, false if it doesn't */ public Response exists(Duration timeout) { Mono> response = containerAsyncClient.exists(); @@ -219,6 +197,7 @@ public Response exists(Duration timeout) { * Creates a new container within a storage account. If a container with the same name already exists, the operation * fails. For more information, see the * Azure Docs. + * * @return A response containing status code and HTTP headers */ public VoidResponse create() { @@ -230,13 +209,10 @@ public VoidResponse create() { * fails. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param metadata {@link Metadata} + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers */ public VoidResponse create(Metadata metadata, PublicAccessType accessType, Duration timeout) { @@ -246,9 +222,10 @@ public VoidResponse create(Metadata metadata, PublicAccessType accessType, Durat } /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the + * Marks the specified container for deletion. The container and any blobs contained within it are later deleted + * during garbage collection. For more information, see the * Azure Docs. + * * @return A response containing status code and HTTP headers */ public VoidResponse delete() { @@ -256,14 +233,12 @@ public VoidResponse delete() { } /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the + * Marks the specified container for deletion. The container and any blobs contained within it are later deleted + * during garbage collection. For more information, see the * Azure Docs. * - * @param accessConditions - * {@link ContainerAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param accessConditions {@link ContainerAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers */ public VoidResponse delete(ContainerAccessConditions accessConditions, Duration timeout) { @@ -276,8 +251,7 @@ public VoidResponse delete(ContainerAccessConditions accessConditions, Duration * Returns the container's metadata and system properties. For more information, see the * Azure Docs. * - * @return - * The container properties. + * @return The container properties. */ public Response getProperties() { return this.getProperties(null, null); @@ -287,17 +261,13 @@ public Response getProperties() { * Returns the container's metadata and system properties. For more information, see the * Azure Docs. * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The container properties. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The container properties. */ public Response getProperties(LeaseAccessConditions leaseAccessConditions, - Duration timeout) { + Duration timeout) { Mono> response = containerAsyncClient.getProperties(leaseAccessConditions); return Utility.blockWithOptionalTimeout(response, timeout); @@ -307,8 +277,7 @@ public Response getProperties(LeaseAccessConditions leaseAc * Sets the container's metadata. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} + * @param metadata {@link Metadata} * @return A response containing status code and HTTP headers */ public VoidResponse setMetadata(Metadata metadata) { @@ -319,16 +288,13 @@ public VoidResponse setMetadata(Metadata metadata) { * Sets the container's metadata. For more information, see the * Azure Docs. * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param metadata {@link Metadata} + * @param accessConditions {@link ContainerAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers */ public VoidResponse setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions, Duration timeout) { + ContainerAccessConditions accessConditions, Duration timeout) { Mono response = containerAsyncClient.setMetadata(metadata, accessConditions); return Utility.blockWithOptionalTimeout(response, timeout); @@ -339,8 +305,7 @@ public VoidResponse setMetadata(Metadata metadata, * For more information, see the * Azure Docs. * - * @return - * The container access policy. + * @return The container access policy. */ public Response getAccessPolicy() { return this.getAccessPolicy(null, null); @@ -351,14 +316,10 @@ public Response getAccessPolicy() { * For more information, see the * Azure Docs. * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The container access policy. + * @param leaseAccessConditions By setting lease access conditions, requests will fail if the provided lease does + * not match the active lease on the blob. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The container access policy. */ public Response getAccessPolicy(LeaseAccessConditions leaseAccessConditions, Duration timeout) { @@ -373,17 +334,16 @@ public Response getAccessPolicy(LeaseAccessConditions l * ensure the time formatting is compatible with the service. For more information, see the * Azure Docs. * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @param identifiers A list of {@link SignedIdentifier} objects that specify the permissions for the container. + * Please see + * here + * for more information. Passing null will clear all access policies. * @return A response containing status code and HTTP headers */ public VoidResponse setAccessPolicy(PublicAccessType accessType, - List identifiers) { + List identifiers) { return this.setAccessPolicy(accessType, identifiers, null, null); } @@ -393,31 +353,27 @@ public VoidResponse setAccessPolicy(PublicAccessType accessType, * ensure the time formatting is compatible with the service. For more information, see the * Azure Docs. * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. + * @param identifiers A list of {@link SignedIdentifier} objects that specify the permissions for the container. + * Please see + * here + * for more information. Passing null will clear all access policies. + * @param accessConditions {@link ContainerAccessConditions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers */ public VoidResponse setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions, - Duration timeout) { + List identifiers, ContainerAccessConditions accessConditions, + Duration timeout) { Mono response = containerAsyncClient.setAccessPolicy(accessType, identifiers, accessConditions); return Utility.blockWithOptionalTimeout(response, timeout); } /** - * Returns a lazy loaded list of blobs in this container, with folder structures flattened. - * The returned {@link Iterable} can be iterated through while new items are automatically - * retrieved as needed. + * Returns a lazy loaded list of blobs in this container, with folder structures flattened. The returned {@link + * Iterable} can be iterated through while new items are automatically retrieved as needed. * *

* Blob names are returned in lexicographic order. @@ -426,17 +382,15 @@ public VoidResponse setAccessPolicy(PublicAccessType accessType, * For more information, see the * Azure Docs. * - * @return - * The listed blobs, flattened. + * @return The listed blobs, flattened. */ public Iterable listBlobsFlat() { return this.listBlobsFlat(new ListBlobsOptions(), null); } /** - * Returns a lazy loaded list of blobs in this container, with folder structures flattened. - * The returned {@link Iterable} can be iterated through while new items are automatically - * retrieved as needed. + * Returns a lazy loaded list of blobs in this container, with folder structures flattened. The returned {@link + * Iterable} can be iterated through while new items are automatically retrieved as needed. * *

* Blob names are returned in lexicographic order. @@ -445,13 +399,9 @@ public Iterable listBlobsFlat() { * For more information, see the * Azure Docs. * - * @param options - * {@link ListBlobsOptions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The listed blobs, flattened. + * @param options {@link ListBlobsOptions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The listed blobs, flattened. */ public Iterable listBlobsFlat(ListBlobsOptions options, Duration timeout) { Flux response = containerAsyncClient.listBlobsFlat(options); @@ -460,74 +410,64 @@ public Iterable listBlobsFlat(ListBlobsOptions options, Duration timeo } /** - * Returns a reactive Publisher emitting all the blobs and directories (prefixes) under - * the given directory (prefix). Directories will have {@link BlobItem#isPrefix()} set to - * true. + * Returns a reactive Publisher emitting all the blobs and directories (prefixes) under the given directory + * (prefix). Directories will have {@link BlobItem#isPrefix()} set to true. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return the following results when prefix=null: + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return the following results when prefix=null: * *

    - *
  • foo/ (isPrefix = true) - *
  • bar (isPrefix = false) + *
  • foo/ (isPrefix = true) + *
  • bar (isPrefix = false) *
*

* will return the following results when prefix="foo/": * *

    - *
  • foo/foo1 (isPrefix = false) - *
  • foo/foo2 (isPrefix = false) + *
  • foo/foo1 (isPrefix = false) + *
  • foo/foo2 (isPrefix = false) *
* - * @param directory - * The directory to list blobs underneath - * - * @return - * A reactive response emitting the prefixes and blobs. + * @param directory The directory to list blobs underneath + * @return A reactive response emitting the prefixes and blobs. */ public Iterable listBlobsHierarchy(String directory) { return this.listBlobsHierarchy("/", new ListBlobsOptions().prefix(directory), null); } /** - * Returns a reactive Publisher emitting all the blobs and prefixes (directories) under - * the given prefix (directory). Directories will have {@link BlobItem#isPrefix()} set to - * true. + * Returns a reactive Publisher emitting all the blobs and prefixes (directories) under the given prefix + * (directory). Directories will have {@link BlobItem#isPrefix()} set to true. * *

* Blob names are returned in lexicographic order. For more information, see the * Azure Docs. * *

- * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob - * on the root level 'bar', will return the following results when prefix=null: + * E.g. listing a container containing a 'foo' folder, which contains blobs 'foo1' and 'foo2', and a blob on the + * root level 'bar', will return the following results when prefix=null: * *

    - *
  • foo/ (isPrefix = true) - *
  • bar (isPrefix = false) + *
  • foo/ (isPrefix = true) + *
  • bar (isPrefix = false) *
*

* will return the following results when prefix="foo/": * *

    - *
  • foo/foo1 (isPrefix = false) - *
  • foo/foo2 (isPrefix = false) + *
  • foo/foo1 (isPrefix = false) + *
  • foo/foo2 (isPrefix = false) *
* - * @param delimiter - * The delimiter for blob hierarchy, "/" for hierarchy based on directories - * @param options - * {@link ListBlobsOptions} - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * A reactive response emitting the prefixes and blobs. + * @param delimiter The delimiter for blob hierarchy, "/" for hierarchy based on directories + * @param options {@link ListBlobsOptions} + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return A reactive response emitting the prefixes and blobs. */ public Iterable listBlobsHierarchy(String delimiter, ListBlobsOptions options, Duration timeout) { Flux response = containerAsyncClient.listBlobsHierarchy(delimiter, options); @@ -539,14 +479,10 @@ public Iterable listBlobsHierarchy(String delimiter, ListBlobsOptions * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedId - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * - * @return - * The lease ID. + * @param proposedId A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @return The lease ID. */ public Response acquireLease(String proposedId, int duration) { return this.acquireLease(proposedId, duration, null, null); @@ -556,23 +492,17 @@ public Response acquireLease(String proposedId, int duration) { * Acquires a lease on the blob for write and delete operations. The lease duration must be between 15 to 60 * seconds, or infinite (-1). * - * @param proposedID - * A {@code String} in any valid GUID format. May be null. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that - * never expires. A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The lease ID. + * @param proposedID A {@code String} in any valid GUID format. May be null. + * @param duration The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A + * non-infinite lease can be between 15 and 60 seconds. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The lease ID. */ public Response acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = containerAsyncClient .acquireLease(proposedID, duration, modifiedAccessConditions); @@ -582,11 +512,8 @@ public Response acquireLease(String proposedID, int duration, /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * - * @return - * The renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @return The renewed lease ID. */ public Response renewLease(String leaseID) { return this.renewLease(leaseID, null, null); @@ -595,20 +522,15 @@ public Response renewLease(String leaseID) { /** * Renews the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The renewed lease ID. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The renewed lease ID. */ public Response renewLease(String leaseID, ModifiedAccessConditions modifiedAccessConditions, - Duration timeout) { + Duration timeout) { Mono> response = containerAsyncClient .renewLease(leaseID, modifiedAccessConditions); @@ -618,8 +540,7 @@ public Response renewLease(String leaseID, ModifiedAccessConditions modi /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. + * @param leaseID The leaseId of the active lease on the blob. * @return A response containing status code and HTTP headers */ public VoidResponse releaseLease(String leaseID) { @@ -629,18 +550,15 @@ public VoidResponse releaseLease(String leaseID) { /** * Releases the blob's previously-acquired lease. * - * @param leaseID - * The leaseId of the active lease on the blob. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @param leaseID The leaseId of the active lease on the blob. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return A response containing status code and HTTP headers. */ public VoidResponse releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono response = containerAsyncClient .releaseLease(leaseID, modifiedAccessConditions); @@ -651,8 +569,7 @@ public VoidResponse releaseLease(String leaseID, * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @return - * The remaining time in the broken lease. + * @return The remaining time in the broken lease. */ public Response breakLease() { return this.breakLease(null, null, null); @@ -662,24 +579,19 @@ public Response breakLease() { * BreakLease breaks the blob's previously-acquired lease (if it exists). Pass the LeaseBreakDefault (-1) constant * to break a fixed-duration lease when it expires or an infinite lease immediately. * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the - * time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break - * period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The remaining time in the broken lease. + * @param breakPeriodInSeconds An optional {@code Integer} representing the proposed duration of seconds that the + * lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is + * shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease + * will not be available before the break period has expired, but the lease may be held for longer than the break + * period. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The remaining time in the broken lease. */ public Response breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = containerAsyncClient .breakLease(breakPeriodInSeconds, modifiedAccessConditions); @@ -689,36 +601,28 @@ public Response breakLease(Integer breakPeriodInSeconds, /** * ChangeLease changes the blob's lease ID. * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return - * The new lease ID. + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @return The new lease ID. */ public Response changeLease(String leaseId, String proposedID) { return this.changeLease(leaseId, proposedID, null, null); } /** - * ChangeLease changes the blob's lease ID. For more information, see the Azure Docs. - * - * @param leaseId - * The leaseId of the active lease on the blob. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * ChangeLease changes the blob's lease ID. For more information, see the Azure + * Docs. * + * @param leaseId The leaseId of the active lease on the blob. + * @param proposedID A {@code String} in any valid GUID format. + * @param modifiedAccessConditions Standard HTTP Access conditions related to the modification of data. ETag and + * LastModifiedTime are used to construct conditions related to when the blob was changed relative to the given + * request. The request will fail if the specified condition is not satisfied. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @return The new lease ID. */ public Response changeLease(String leaseId, String proposedID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { + ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { Mono> response = containerAsyncClient .changeLease(leaseId, proposedID, modifiedAccessConditions); @@ -729,11 +633,8 @@ public Response changeLease(String leaseId, String proposedID, * Returns the sku name and account kind for the account. For more information, please see the * Azure Docs. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The account info. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The account info. */ public Response getAccountInfo(Duration timeout) { Mono> response = containerAsyncClient.getAccountInfo(); @@ -744,20 +645,14 @@ public Response getAccountInfo(Duration timeout) { /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime) { + ContainerSASPermission permissions, OffsetDateTime expiryTime) { return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime); } @@ -765,29 +660,19 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange) { + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange) { return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange); } @@ -795,40 +680,25 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a user delegation SAS token with the specified parameters * - * @param userDelegationKey - * The {@code UserDelegationKey} user delegation key for the SAS - * @param accountName - * The {@code String} account name for the SAS - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param userDelegationKey The {@code UserDelegationKey} user delegation key for the SAS + * @param accountName The {@code String} account name for the SAS + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, String accountName, - ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, - SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, - String contentEncoding, String contentLanguage, String contentType) { + ContainerSASPermission permissions, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, + SASProtocol sasProtocol, IPRange ipRange, String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, String contentType) { return this.containerAsyncClient.generateUserDelegationSAS(userDelegationKey, accountName, permissions, expiryTime, startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); @@ -837,13 +707,9 @@ public String generateUserDelegationSAS(UserDelegationKey userDelegationKey, Str /** * Generates a SAS token with the specified parameters * - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * - * @return - * A string that represents the SAS token + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @return A string that represents the SAS token */ public String generateSAS(ContainerSASPermission permissions, OffsetDateTime expiryTime) { return this.containerAsyncClient.generateSAS(permissions, expiryTime); @@ -852,11 +718,8 @@ public String generateSAS(ContainerSASPermission permissions, OffsetDateTime exp /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @return A string that represents the SAS token */ public String generateSAS(String identifier) { return this.containerAsyncClient.generateSAS(identifier); @@ -865,26 +728,17 @@ public String generateSAS(String identifier) { /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @return A string that represents the SAS token */ public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange) { return this.containerAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange); } @@ -892,37 +746,23 @@ public String generateSAS(String identifier, ContainerSASPermission permissions, /** * Generates a SAS token with the specified parameters * - * @param identifier - * The {@code String} name of the access policy on the container this SAS references if any - * @param permissions - * The {@code ContainerSASPermissions} permission for the SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the SAS - * @param startTime - * An optional {@code OffsetDateTime} start time for the SAS - * @param version - * An optional {@code String} version for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param cacheControl - * An optional {@code String} cache-control header for the SAS. - * @param contentDisposition - * An optional {@code String} content-disposition header for the SAS. - * @param contentEncoding - * An optional {@code String} content-encoding header for the SAS. - * @param contentLanguage - * An optional {@code String} content-language header for the SAS. - * @param contentType - * An optional {@code String} content-type header for the SAS. - * - * @return - * A string that represents the SAS token + * @param identifier The {@code String} name of the access policy on the container this SAS references if any + * @param permissions The {@code ContainerSASPermissions} permission for the SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the SAS + * @param startTime An optional {@code OffsetDateTime} start time for the SAS + * @param version An optional {@code String} version for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param cacheControl An optional {@code String} cache-control header for the SAS. + * @param contentDisposition An optional {@code String} content-disposition header for the SAS. + * @param contentEncoding An optional {@code String} content-encoding header for the SAS. + * @param contentLanguage An optional {@code String} content-language header for the SAS. + * @param contentType An optional {@code String} content-type header for the SAS. + * @return A string that represents the SAS token */ public String generateSAS(String identifier, ContainerSASPermission permissions, OffsetDateTime expiryTime, - OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, - String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + OffsetDateTime startTime, String version, SASProtocol sasProtocol, IPRange ipRange, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { return this.containerAsyncClient.generateSAS(identifier, permissions, expiryTime, startTime, version, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType); } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java deleted file mode 100644 index 19d10f5444ee5..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerRawClient.java +++ /dev/null @@ -1,652 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.rest.Response; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.ContainerAccessConditions; -import com.azure.storage.blob.models.ContainerAccessPolicies; -import com.azure.storage.blob.models.ContainersAcquireLeaseResponse; -import com.azure.storage.blob.models.ContainersBreakLeaseResponse; -import com.azure.storage.blob.models.ContainersChangeLeaseResponse; -import com.azure.storage.blob.models.ContainersCreateResponse; -import com.azure.storage.blob.models.ContainersDeleteResponse; -import com.azure.storage.blob.models.ContainersGetAccountInfoResponse; -import com.azure.storage.blob.models.ContainersGetPropertiesResponse; -import com.azure.storage.blob.models.ContainersListBlobFlatSegmentResponse; -import com.azure.storage.blob.models.ContainersListBlobHierarchySegmentResponse; -import com.azure.storage.blob.models.ContainersReleaseLeaseResponse; -import com.azure.storage.blob.models.ContainersRenewLeaseResponse; -import com.azure.storage.blob.models.ContainersSetAccessPolicyResponse; -import com.azure.storage.blob.models.ContainersSetMetadataResponse; -import com.azure.storage.blob.models.LeaseAccessConditions; -import com.azure.storage.blob.models.ListBlobsOptions; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PublicAccessType; -import com.azure.storage.blob.models.SignedIdentifier; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.util.List; - -/** - * Represents a URL to a container. It may be obtained by direct construction or via the create method on a - * {@link StorageAsyncRawClient} object. This class does not hold any state about a particular blob but is instead a convenient way - * of sending off appropriate requests to the resource on the service. It may also be used to construct URLs to blobs. - * Please refer to the - * Azure Docs - * for more information on containers. - */ -final class ContainerRawClient { - - private ContainerAsyncRawClient containerAsyncRawClient; - - public static final String ROOT_CONTAINER_NAME = "$root"; - - public static final String STATIC_WEBSITE_CONTAINER_NAME = "$web"; - - public static final String LOG_CONTAINER_NAME = "$logs"; - - - /** - * Creates a {@code ContainerAsyncClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - */ - ContainerRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.containerAsyncRawClient = new ContainerAsyncRawClient(azureBlobStorage); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersCreateResponse create() { - return this.create(null, null, null); - } - - /** - * Creates a new container within a storage account. If a container with the same name already exists, the operation - * fails. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersCreateResponse create(Metadata metadata, PublicAccessType accessType, Duration timeout) { - Mono response = containerAsyncRawClient.create(metadata, accessType); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersDeleteResponse delete() { - return this.delete(null, null); - } - - /** - * Marks the specified container for deletion. The container and any blobs contained within it are later - * deleted during garbage collection. For more information, see the - * Azure Docs. - * - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.delete")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersDeleteResponse delete(ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.delete(accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetPropertiesResponse getProperties() { - return this.getProperties(null, null); - } - - /** - * Returns the container's metadata and system properties. For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetPropertiesResponse getProperties(LeaseAccessConditions leaseAccessConditions, - Duration timeout) { - Mono response = containerAsyncRawClient.getProperties(leaseAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetMetadataResponse setMetadata(Metadata metadata) { - return this.setMetadata(metadata, null, null); - } - - /** - * Sets the container's metadata. For more information, see the - * Azure Docs. - * - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_basic "Sample code for ContainerAsyncClient.setMetadata")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetMetadataResponse setMetadata(Metadata metadata, - ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.setMetadata(metadata, accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Response getAccessPolicy() { - return this.getAccessPolicy(null, null); - } - - /** - * Returns the container's permissions. The permissions indicate whether container's blobs may be accessed publicly. - * For more information, see the - * Azure Docs. - * - * @param leaseAccessConditions - * By setting lease access conditions, requests will fail if the provided lease does not match the active - * lease on the blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.getAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Response getAccessPolicy(LeaseAccessConditions leaseAccessConditions, - Duration timeout) { - Mono> response = containerAsyncRawClient.getAccessPolicy(leaseAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetAccessPolicyResponse setAccessPolicy(PublicAccessType accessType, - List identifiers) { - return this.setAccessPolicy(accessType, identifiers, null, null); - } - - /** - * Sets the container's permissions. The permissions indicate whether blobs in a container may be accessed publicly. - * Note that, for each signed identifier, we will truncate the start and expiry times to the nearest second to - * ensure the time formatting is compatible with the service. For more information, see the - * Azure Docs. - * - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. - * @param identifiers - * A list of {@link SignedIdentifier} objects that specify the permissions for the container. Please see - * here - * for more information. Passing null will clear all access policies. - * @param accessConditions - * {@link ContainerAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_policy "Sample code for ContainerAsyncClient.setAccessPolicy")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersSetAccessPolicyResponse setAccessPolicy(PublicAccessType accessType, - List identifiers, ContainerAccessConditions accessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.setAccessPolicy(accessType, identifiers, accessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @param proposedId - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersAcquireLeaseResponse acquireLease(String proposedId, int duration) { - return this.acquireLease(proposedId, duration, null, null); - } - - /** - * Acquires a lease on the container for delete operations. The lease duration must be between 15 to - * 60 seconds, or infinite (-1). For more information, see the - * Azure Docs. - * - * @param proposedID - * A {@code String} in any valid GUID format. - * @param duration - * The duration of the lease, in seconds, or negative one (-1) for a lease that never expires. - * A non-infinite lease can be between 15 and 60 seconds. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.acquireLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersAcquireLeaseResponse acquireLease(String proposedID, int duration, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.acquireLease(proposedID, duration, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersRenewLeaseResponse renewLease(String leaseID) { - return this.renewLease(leaseID, null, null); - } - - /** - * Renews the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.renewLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersRenewLeaseResponse renewLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.renewLease(leaseID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersReleaseLeaseResponse releaseLease(String leaseID) { - return this.releaseLease(leaseID, null, null); - } - - /** - * Releases the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.releaseLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersReleaseLeaseResponse releaseLease(String leaseID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.releaseLease(leaseID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @apiNote - * ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/New-Storage-SDK-V10-Preview/src/test/java/com/microsoft/azure/storage/Samples.java) - * - * @return Emits the successful response. - */ - public ContainersBreakLeaseResponse breakLease() { - return this.breakLease(null, null, null); - } - - /** - * Breaks the container's previously-acquired lease. For more information, see the - * Azure Docs. - * - * @param breakPeriodInSeconds - * An optional {@code Integer} representing the proposed duration of seconds that the lease should continue - * before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time - * remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be - * available before the break period has expired, but the lease may be held for longer than the break period. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.breakLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersBreakLeaseResponse breakLease(Integer breakPeriodInSeconds, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.breakLease(breakPeriodInSeconds, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersChangeLeaseResponse changeLease(String leaseID, String proposedID) { - return this.changeLease(leaseID, proposedID, null, null); - } - - /** - * Changes the container's leaseAccessConditions. For more information, see the - * Azure Docs. - * - * @param leaseID - * The leaseId of the active lease on the container. - * @param proposedID - * A {@code String} in any valid GUID format. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=container_lease "Sample code for ContainerAsyncClient.changeLease")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersChangeLeaseResponse changeLease(String leaseID, String proposedID, - ModifiedAccessConditions modifiedAccessConditions, Duration timeout) { - Mono response = containerAsyncRawClient.changeLease(leaseID, proposedID, modifiedAccessConditions); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobFlatSegmentResponse listBlobsFlatSegment(String marker, ListBlobsOptions options) { - return this.listBlobsFlatSegment(marker, options, null); - } - - /** - * Returns a single segment of blobs starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsFlatSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat "Sample code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_flat_helper "helper code for ContainerAsyncClient.listBlobsFlatSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobFlatSegmentResponse listBlobsFlatSegment(String marker, ListBlobsOptions options, - Duration timeout) { - Mono response = containerAsyncRawClient.listBlobsFlatSegment(marker, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobHierarchySegmentResponse listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options) { - return this.listBlobsHierarchySegment(marker, delimiter, options, null); - } - - /** - * Returns a single segment of blobs and blob prefixes starting from the specified Marker. Use an empty - * marker to start enumeration from the beginning. Blob names are returned in lexicographic order. - * After getting a segment, process it, and then call ListBlobs again (passing the the previously-returned - * Marker) to get the next segment. For more information, see the - * Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListBlobsHierarchySegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param delimiter - * The operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs - * whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may - * be a single character or a string. - * @param options - * {@link ListBlobsOptions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy "Sample code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=list_blobs_hierarchy_helper "helper code for ContainerAsyncClient.listBlobsHierarchySegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersListBlobHierarchySegmentResponse listBlobsHierarchySegment(String marker, String delimiter, - ListBlobsOptions options, Duration timeout) { - Mono response = containerAsyncRawClient.listBlobsHierarchySegment(marker, delimiter, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetAccountInfoResponse getAccountInfo() { - return this.getAccountInfo(null); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ContainerAsyncClient.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ContainersGetAccountInfoResponse getAccountInfo(Duration timeout) { - Mono response = containerAsyncRawClient.getAccountInfo(); - return Utility.blockWithOptionalTimeout(response, timeout); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index 073df29744582..72f052fd27573 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -5,6 +5,8 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.implementation.http.UrlBuilder; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; @@ -17,12 +19,14 @@ import com.azure.storage.blob.models.PageRange; import com.azure.storage.blob.models.SequenceNumberActionType; import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.Unpooled; +import io.netty.buffer.ByteBuf; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.net.MalformedURLException; import java.net.URL; -import java.nio.ByteBuffer; + +import static com.azure.storage.blob.Utility.postProcessResponse; /** * Client to a page blob. It may only be instantiated through a {@link PageBlobClientBuilder}, via @@ -48,9 +52,6 @@ * object through {@link Mono#toFuture()}. */ public final class PageBlobAsyncClient extends BlobAsyncClient { - - final PageBlobAsyncRawClient pageBlobAsyncRawClient; - /** * Indicates the number of bytes in a page. */ @@ -67,7 +68,6 @@ public final class PageBlobAsyncClient extends BlobAsyncClient { */ PageBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { super(azureBlobStorageBuilder, snapshot); - this.pageBlobAsyncRawClient = new PageBlobAsyncRawClient(azureBlobStorageBuilder.build(), snapshot); } /** @@ -104,13 +104,30 @@ public Mono> create(long size) { * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response containing the information of the created page blob. + * @return A reactive response containing the information of the created page blob. + * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncClient#PAGE_BYTES} + * or {@code sequenceNumber} isn't null and is less than 0. */ public Mono> create(long size, Long sequenceNumber, BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .create(size, sequenceNumber, headers, metadata, accessConditions) + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + if (size % PAGE_BYTES != 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncClient.PAGE_BYTES."); + } + if (sequenceNumber != null && sequenceNumber < 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); + } + metadata = metadata == null ? new Metadata() : metadata; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().createWithRestResponseAsync(null, + null, 0, size, null, metadata, null, null, + null, sequenceNumber, null, headers, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -133,7 +150,7 @@ public Mono> create(long size, Long sequenceNumber, BlobH * @return * A reactive response containing the information of the uploaded pages. */ - public Mono> uploadPages(PageRange pageRange, Flux body) { + public Mono> uploadPages(PageRange pageRange, Flux body) { return this.uploadPages(pageRange, body, null); } @@ -155,13 +172,25 @@ public Mono> uploadPages(PageRange pageRange, Flux> uploadPages(PageRange pageRange, Flux body, + public Mono> uploadPages(PageRange pageRange, Flux body, PageBlobAccessConditions pageBlobAccessConditions) { - return pageBlobAsyncRawClient - .uploadPages(pageRange, body.map(Unpooled::wrappedBuffer), pageBlobAccessConditions) + pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() : pageBlobAccessConditions; + + if (pageRange == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("pageRange cannot be null."); + } + String pageRangeStr = pageRangeToString(pageRange); + + return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesWithRestResponseAsync(null, + null, body, pageRange.end() - pageRange.start() + 1, null, + null, pageRangeStr, null, null, null, null, + pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), + pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -218,15 +247,33 @@ public Mono> uploadPagesFromURL(PageRange range, URL sour * @param sourceAccessConditions * {@link SourceModifiedAccessConditions} * - * @return - * A reactive response containing the information of the uploaded pages. + * @return A reactive response containing the information of the uploaded pages. + * @throws IllegalArgumentException If {@code range} is {@code null} */ public Mono> uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset, byte[] sourceContentMD5, PageBlobAccessConditions destAccessConditions, SourceModifiedAccessConditions sourceAccessConditions) { + if (range == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("range cannot be null."); + } + + String rangeString = pageRangeToString(range); - return pageBlobAsyncRawClient - .uploadPagesFromURL(range, sourceURL, sourceOffset, sourceContentMD5, destAccessConditions, sourceAccessConditions) + if (sourceOffset == null) { + sourceOffset = 0L; + } + + String sourceRangeString = pageRangeToString(new PageRange().start(sourceOffset).end(sourceOffset + (range.end() - range.start()))); + + destAccessConditions = destAccessConditions == null ? new PageBlobAccessConditions() : destAccessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesFromURLWithRestResponseAsync( + null, null, sourceURL, sourceRangeString, 0, rangeString, sourceContentMD5, + null, null, destAccessConditions.leaseAccessConditions(), + destAccessConditions.sequenceNumberAccessConditions(), destAccessConditions.modifiedAccessConditions(), + sourceAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -259,13 +306,23 @@ public Mono> clearPages(PageRange pageRange) { * @param pageBlobAccessConditions * {@link PageBlobAccessConditions} * - * @return - * A reactive response containing the information of the cleared pages. + * @return A reactive response containing the information of the cleared pages. + * @throws IllegalArgumentException If {@code pageRange} is {@code null} */ public Mono> clearPages(PageRange pageRange, PageBlobAccessConditions pageBlobAccessConditions) { - return pageBlobAsyncRawClient - .clearPages(pageRange, pageBlobAccessConditions) + pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() : pageBlobAccessConditions; + if (pageRange == null) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("pageRange cannot be null."); + } + String pageRangeStr = pageRangeToString(pageRange); + + return postProcessResponse(this.azureBlobStorage.pageBlobs().clearPagesWithRestResponseAsync(null, + null, 0, null, pageRangeStr, null, + pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), + pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -295,10 +352,14 @@ public Flux getPageRanges(BlobRange blobRange) { * @return * A reactive response emitting all the page ranges. */ - public Flux getPageRanges(BlobRange blobRange, - BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .getPageRanges(blobRange, accessConditions) + public Flux getPageRanges(BlobRange blobRange, BlobAccessConditions accessConditions) { + blobRange = blobRange == null ? new BlobRange(0) : blobRange; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesWithRestResponseAsync( + null, null, snapshot, null, null, blobRange.toHeaderValue(), + null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), + Context.NONE)) .flatMapMany(response -> Flux.fromIterable(response.value().pageRange())); } @@ -333,13 +394,21 @@ public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapsho * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting all the different page ranges. + * @return A reactive response emitting all the different page ranges. + * @throws IllegalArgumentException If {@code prevSnapshot} is {@code null} */ - public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapshot, - BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .getPageRangesDiff(blobRange, prevSnapshot, accessConditions) + public Flux getPageRangesDiff(BlobRange blobRange, String prevSnapshot, BlobAccessConditions accessConditions) { + blobRange = blobRange == null ? new BlobRange(0) : blobRange; + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + if (prevSnapshot == null) { + throw new IllegalArgumentException("prevSnapshot cannot be null"); + } + + return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesDiffWithRestResponseAsync( + null, null, snapshot, null, null, prevSnapshot, + blobRange.toHeaderValue(), null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .flatMapMany(response -> Flux.fromIterable(response.value().pageRange())); } @@ -368,12 +437,20 @@ public Mono> resize(long size) { * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting the resized page blob. + * @return A reactive response emitting the resized page blob. + * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncClient#PAGE_BYTES} */ public Mono> resize(long size, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .resize(size, accessConditions) + if (size % PAGE_BYTES != 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncClient.PAGE_BYTES."); + } + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + + return postProcessResponse(this.azureBlobStorage.pageBlobs().resizeWithRestResponseAsync(null, + null, size, null, null, accessConditions.leaseAccessConditions(), + accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -407,13 +484,22 @@ public Mono> updateSequenceNumber(SequenceNumberActionTyp * @param accessConditions * {@link BlobAccessConditions} * - * @return - * A reactive response emitting the updated page blob. + * @return A reactive response emitting the updated page blob. + * @throws IllegalArgumentException If {@code sequenceNumber} isn't null and is less than 0 */ - public Mono> updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber, BlobAccessConditions accessConditions) { - return pageBlobAsyncRawClient - .updateSequenceNumber(action, sequenceNumber, accessConditions) + public Mono> updateSequenceNumber(SequenceNumberActionType action, Long sequenceNumber, BlobAccessConditions accessConditions) { + if (sequenceNumber != null && sequenceNumber < 0) { + // Throwing is preferred to Single.error because this will error out immediately instead of waiting until + // subscription. + throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); + } + accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; + sequenceNumber = action == SequenceNumberActionType.INCREMENT ? null : sequenceNumber; + + return postProcessResponse( + this.azureBlobStorage.pageBlobs().updateSequenceNumberWithRestResponseAsync(null, + null, action, null, sequenceNumber, null, + accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.deserializedHeaders()))); } @@ -454,13 +540,37 @@ public Mono> copyIncremental(URL source, String snapsho * to construct conditions related to when the blob was changed relative to the given request. The request * will fail if the specified condition is not satisfied. * - * @return - * A reactive response emitting the copy status. + * @return A reactive response emitting the copy status. + * @throws Error If {@code source} and {@code snapshot} form a malformed URL. */ - public Mono> copyIncremental(URL source, String snapshot, - ModifiedAccessConditions modifiedAccessConditions) { - return pageBlobAsyncRawClient - .copyIncremental(source, snapshot, modifiedAccessConditions) + public Mono> copyIncremental(URL source, String snapshot, ModifiedAccessConditions modifiedAccessConditions) { + UrlBuilder builder = UrlBuilder.parse(source); + builder.setQueryParameter(Constants.SNAPSHOT_QUERY_PARAMETER, snapshot); + try { + source = builder.toURL(); + } catch (MalformedURLException e) { + // We are parsing a valid url and adding a query parameter. If this fails, we can't recover. + throw new Error(e); + } + return postProcessResponse(this.azureBlobStorage.pageBlobs().copyIncrementalWithRestResponseAsync( + null, null, source, null, null, modifiedAccessConditions, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().copyStatus())); } + + private static String pageRangeToString(PageRange pageRange) { + if (pageRange.start() < 0 || pageRange.end() <= 0) { + throw new IllegalArgumentException("PageRange's start and end values must be greater than or equal to " + + "0 if specified."); + } + if (pageRange.start() % PAGE_BYTES != 0) { + throw new IllegalArgumentException("PageRange's start value must be a multiple of 512."); + } + if (pageRange.end() % PAGE_BYTES != PAGE_BYTES - 1) { + throw new IllegalArgumentException("PageRange's end value must be 1 less than a multiple of 512."); + } + if (pageRange.end() <= pageRange.start()) { + throw new IllegalArgumentException("PageRange's End value must be after the start."); + } + return "bytes=" + pageRange.start() + '-' + pageRange.end(); + } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java deleted file mode 100644 index fba55bd8d7455..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncRawClient.java +++ /dev/null @@ -1,620 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.implementation.http.UrlBuilder; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.BlobAccessConditions; -import com.azure.storage.blob.models.BlobHTTPHeaders; -import com.azure.storage.blob.models.BlobRange; -import com.azure.storage.blob.models.Metadata; -import com.azure.storage.blob.models.ModifiedAccessConditions; -import com.azure.storage.blob.models.PageBlobAccessConditions; -import com.azure.storage.blob.models.PageBlobsClearPagesResponse; -import com.azure.storage.blob.models.PageBlobsCopyIncrementalResponse; -import com.azure.storage.blob.models.PageBlobsCreateResponse; -import com.azure.storage.blob.models.PageBlobsGetPageRangesDiffResponse; -import com.azure.storage.blob.models.PageBlobsGetPageRangesResponse; -import com.azure.storage.blob.models.PageBlobsResizeResponse; -import com.azure.storage.blob.models.PageBlobsUpdateSequenceNumberResponse; -import com.azure.storage.blob.models.PageBlobsUploadPagesFromURLResponse; -import com.azure.storage.blob.models.PageBlobsUploadPagesResponse; -import com.azure.storage.blob.models.PageRange; -import com.azure.storage.blob.models.SequenceNumberActionType; -import com.azure.storage.blob.models.SourceModifiedAccessConditions; -import io.netty.buffer.ByteBuf; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.net.MalformedURLException; -import java.net.URL; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a page blob. It may be obtained by direct construction or via the create method on a - * {@link ContainerAsyncClient} object. This class does not hold any state about a particular blob but is instead a convenient - * way of sending off appropriate requests to the resource on the service. Please refer to the - * Azure Docs - * for more information. - */ -final class PageBlobAsyncRawClient extends BlobAsyncRawClient { - - /** - * Indicates the number of bytes in a page. - */ - public static final int PAGE_BYTES = 512; - - /** - * Indicates the maximum number of bytes that may be sent in a call to putPage. - */ - public static final int MAX_PUT_PAGES_BYTES = 4 * Constants.MB; - - /** - * Creates a {@code PageBlobAsyncRawClient} object pointing to the account specified by the URL and using the provided - * pipeline to make HTTP requests. - * - */ - PageBlobAsyncRawClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { - super(azureBlobStorage, snapshot); - } - - private static String pageRangeToString(PageRange pageRange) { - if (pageRange.start() < 0 || pageRange.end() <= 0) { - throw new IllegalArgumentException("PageRange's start and end values must be greater than or equal to " - + "0 if specified."); - } - if (pageRange.start() % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - throw new IllegalArgumentException("PageRange's start value must be a multiple of 512."); - } - if (pageRange.end() % PageBlobAsyncRawClient.PAGE_BYTES != PageBlobAsyncRawClient.PAGE_BYTES - 1) { - throw new IllegalArgumentException("PageRange's end value must be 1 less than a multiple of 512."); - } - if (pageRange.end() <= pageRange.start()) { - throw new IllegalArgumentException("PageRange's End value must be after the start."); - } - return new StringBuilder("bytes=").append(pageRange.start()).append('-').append(pageRange.end()).toString(); - } - - /** - * Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. - * For more information, see the - * Azure Docs. - * - * @param size - * Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a - * 512-byte boundary. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(long size) { - return this.create(size, null, null, null, null); - } - - /** - * Creates a page blob of the specified length. Call PutPage to upload data data to a page blob. - * For more information, see the - * Azure Docs. - * - * @param size - * Specifies the maximum size for the page blob, up to 8 TB. The page blob size must be aligned to a - * 512-byte boundary. - * @param sequenceNumber - * A user-controlled value that you can use to track requests. The value of the sequence number must be - * between 0 and 2^63 - 1.The default value is 0. - * @param headers - * {@link BlobHTTPHeaders} - * @param metadata - * {@link Metadata} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncRawClient#PAGE_BYTES} - * or {@code sequenceNumber} isn't null and is less than 0. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.create")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono create(long size, Long sequenceNumber, BlobHTTPHeaders headers, - Metadata metadata, BlobAccessConditions accessConditions) { - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - if (size % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncRawClient.PAGE_BYTES."); - } - if (sequenceNumber != null && sequenceNumber < 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); - } - metadata = metadata == null ? new Metadata() : metadata; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().createWithRestResponseAsync(null, - null, 0, size, null, metadata, null, null, - null, sequenceNumber, null, headers, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset must - * be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges are - * 0-511, 512-1023, etc. - * @param body - * The data to upload. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.uploadPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPages(PageRange pageRange, Flux body) { - return this.uploadPages(pageRange, body, null); - } - - /** - * Writes 1 or more pages to the page blob. The start and end offsets must be a multiple of 512. - * For more information, see the - * Azure Docs. - *

- * Note that the data passed must be replayable if retries are enabled (the default). In other words, the - * {@code Flux} must produce the same data each time it is subscribed to. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param body - * The data to upload. Note that this {@code Flux} must be replayable if retries are enabled - * (the default). In other words, the Flowable must produce the same data each time it is subscribed to. - * @param pageBlobAccessConditions - * {@link PageBlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code pageRange} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.uploadPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPages(PageRange pageRange, Flux body, - PageBlobAccessConditions pageBlobAccessConditions) { - pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() - : pageBlobAccessConditions; - - if (pageRange == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("pageRange cannot be null."); - } - String pageRangeStr = pageRangeToString(pageRange); - - return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesWithRestResponseAsync(null, - null, body, pageRange.end() - pageRange.start() + 1, null, - null, pageRangeStr, null, null, null, null, - pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), - pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Writes 1 or more pages from the source page blob to this page blob. The start and end offsets must be a multiple - * of 512. - * For more information, see the - * Azure Docs. - *

- * - * @param range - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceOffset - * The source offset to copy from. Pass null or 0 to copy from the beginning of source page blob. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_from_url "Sample code for PageBlobAsyncRawClient.uploadPagesFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset) { - return this.uploadPagesFromURL(range, sourceURL, sourceOffset, null, null, - null); - } - - /** - * Writes 1 or more pages from the source page blob to this page blob. The start and end offsets must be a multiple - * of 512. - * For more information, see the - * Azure Docs. - *

- * - * @param range - * The destination {@link PageRange} range. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param sourceURL - * The url to the blob that will be the source of the copy. A source blob in the same storage account can be - * authenticated via Shared Key. However, if the source is a blob in another account, the source blob must - * either be public or must be authenticated via a shared access signature. If the source blob is public, no - * authentication is required to perform the operation. - * @param sourceOffset - * The source offset to copy from. Pass null or 0 to copy from the beginning of source blob. - * @param sourceContentMD5 - * An MD5 hash of the block content from the source blob. If specified, the service will calculate the MD5 - * of the received data and fail the request if it does not match the provided MD5. - * @param destAccessConditions - * {@link PageBlobAccessConditions} - * @param sourceAccessConditions - * {@link SourceModifiedAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code range} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_from_url "Sample code for PageBlobAsyncRawClient.uploadPagesFromURL")] - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono uploadPagesFromURL(PageRange range, URL sourceURL, Long sourceOffset, - byte[] sourceContentMD5, PageBlobAccessConditions destAccessConditions, - SourceModifiedAccessConditions sourceAccessConditions) { - - if (range == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("range cannot be null."); - } - - String rangeString = pageRangeToString(range); - - if (sourceOffset == null) { - sourceOffset = 0L; - } - - String sourceRangeString = pageRangeToString(new PageRange().start(sourceOffset).end(sourceOffset + (range.end() - range.start()))); - - destAccessConditions = destAccessConditions == null ? new PageBlobAccessConditions() : destAccessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().uploadPagesFromURLWithRestResponseAsync( - null, null, sourceURL, sourceRangeString, 0, rangeString, sourceContentMD5, - null, null, destAccessConditions.leaseAccessConditions(), - destAccessConditions.sequenceNumberAccessConditions(), destAccessConditions.modifiedAccessConditions(), - sourceAccessConditions, Context.NONE)); - } - - /** - * Frees the specified pages from the page blob. - * For more information, see the - * Azure Docs. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.clearPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono clearPages(PageRange pageRange) { - return this.clearPages(pageRange, null); - } - - /** - * Frees the specified pages from the page blob. - * For more information, see the - * Azure Docs. - * - * @param pageRange - * A {@link PageRange} object. Given that pages must be aligned with 512-byte boundaries, the start offset - * must be a modulus of 512 and the end offset must be a modulus of 512 - 1. Examples of valid byte ranges - * are 0-511, 512-1023, etc. - * @param pageBlobAccessConditions - * {@link PageBlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code pageRange} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.clearPages")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono clearPages(PageRange pageRange, - PageBlobAccessConditions pageBlobAccessConditions) { - pageBlobAccessConditions = pageBlobAccessConditions == null ? new PageBlobAccessConditions() - : pageBlobAccessConditions; - if (pageRange == null) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("pageRange cannot be null."); - } - String pageRangeStr = pageRangeToString(pageRange); - - return postProcessResponse(this.azureBlobStorage.pageBlobs().clearPagesWithRestResponseAsync(null, - null, 0, null, pageRangeStr, null, - pageBlobAccessConditions.leaseAccessConditions(), pageBlobAccessConditions.sequenceNumberAccessConditions(), - pageBlobAccessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Returns the list of valid page ranges for a page blob or snapshot of a page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.getPageRanges")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRanges(BlobRange blobRange) { - return this.getPageRanges(blobRange, null); - } - - /** - * Returns the list of valid page ranges for a page blob or snapshot of a page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.getPageRanges")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRanges(BlobRange blobRange, - BlobAccessConditions accessConditions) { - blobRange = blobRange == null ? new BlobRange(0) : blobRange; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesWithRestResponseAsync( - null, null, snapshot, null, null, blobRange.toHeaderValue(), - null, accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), - Context.NONE)); - } - - /** - * Gets the collection of page ranges that differ between a specified snapshot and this page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param prevSnapshot - * Specifies that the response will contain only pages that were changed between target blob and previous - * snapshot. Changed pages include both updated and cleared pages. The target - * blob may be a snapshot, as long as the snapshot specified by prevsnapshot is the older of the two. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_diff "Sample code for PageBlobAsyncRawClient.getPageRangesDiff")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRangesDiff(BlobRange blobRange, String prevSnapshot) { - return this.getPageRangesDiff(blobRange, prevSnapshot, null); - } - - /** - * Gets the collection of page ranges that differ between a specified snapshot and this page blob. - * For more information, see the Azure Docs. - * - * @param blobRange - * {@link BlobRange} - * @param prevSnapshot - * Specifies that the response will contain only pages that were changed between target blob and previous - * snapshot. Changed pages include both updated and cleared pages. The target - * blob may be a snapshot, as long as the snapshot specified by prevsnapshot is the older of the two. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code prevSnapshot} is {@code null} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_diff "Sample code for PageBlobAsyncRawClient.getPageRangesDiff")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getPageRangesDiff(BlobRange blobRange, String prevSnapshot, - BlobAccessConditions accessConditions) { - blobRange = blobRange == null ? new BlobRange(0) : blobRange; - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - if (prevSnapshot == null) { - throw new IllegalArgumentException("prevSnapshot cannot be null"); - } - - return postProcessResponse(this.azureBlobStorage.pageBlobs().getPageRangesDiffWithRestResponseAsync( - null, null, snapshot, null, null, prevSnapshot, - blobRange.toHeaderValue(), null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Resizes the page blob to the specified size (which must be a multiple of 512). - * For more information, see the Azure Docs. - * - * @param size - * Resizes a page blob to the specified size. If the specified value is less than the current size of the - * blob, then all pages above the specified value are cleared. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.resize")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono resize(long size) { - return this.resize(size, null); - } - - /** - * Resizes the page blob to the specified size (which must be a multiple of 512). - * For more information, see the Azure Docs. - * - * @param size - * Resizes a page blob to the specified size. If the specified value is less than the current size of the - * blob, then all pages above the specified value are cleared. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code size} isn't a multiple of {@link PageBlobAsyncRawClient#PAGE_BYTES} - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.resize")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono resize(long size, BlobAccessConditions accessConditions) { - if (size % PageBlobAsyncRawClient.PAGE_BYTES != 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("size must be a multiple of PageBlobAsyncRawClient.PAGE_BYTES."); - } - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - - return postProcessResponse(this.azureBlobStorage.pageBlobs().resizeWithRestResponseAsync(null, - null, size, null, null, accessConditions.leaseAccessConditions(), - accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Sets the page blob's sequence number. - * For more information, see the Azure Docs. - * - * @param action - * Indicates how the service should modify the blob's sequence number. - * @param sequenceNumber - * The blob's sequence number. The sequence number is a user-controlled property that you can use to track - * requests and manage concurrency issues. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.updateSequenceNumber")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber) { - return this.updateSequenceNumber(action, sequenceNumber, null); - } - - /** - * Sets the page blob's sequence number. - * For more information, see the Azure Docs. - * - * @param action - * Indicates how the service should modify the blob's sequence number. - * @param sequenceNumber - * The blob's sequence number. The sequence number is a user-controlled property that you can use to track - * requests and manage concurrency issues. - * @param accessConditions - * {@link BlobAccessConditions} - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code sequenceNumber} isn't null and is less than 0 - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=page_blob_basic "Sample code for PageBlobAsyncRawClient.updateSequenceNumber")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono updateSequenceNumber(SequenceNumberActionType action, - Long sequenceNumber, BlobAccessConditions accessConditions) { - if (sequenceNumber != null && sequenceNumber < 0) { - // Throwing is preferred to Single.error because this will error out immediately instead of waiting until - // subscription. - throw new IllegalArgumentException("SequenceNumber must be greater than or equal to 0."); - } - accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; - sequenceNumber = action == SequenceNumberActionType.INCREMENT ? null : sequenceNumber; - - return postProcessResponse( - this.azureBlobStorage.pageBlobs().updateSequenceNumberWithRestResponseAsync(null, - null, action, null, sequenceNumber, null, - accessConditions.leaseAccessConditions(), accessConditions.modifiedAccessConditions(), Context.NONE)); - } - - /** - * Begins an operation to start an incremental copy from one page blob's snapshot to this page - * blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are - * transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read - * or copied from as usual. For more information, see - * the Azure Docs here and - * here. - * - * @param source - * The source page blob. - * @param snapshot - * The snapshot on the copy source. - * - * @return Emits the successful response. - */ - public Mono copyIncremental(URL source, String snapshot) { - return this.copyIncremental(source, snapshot, null); - } - - /** - * Begins an operation to start an incremental copy from one page blob's snapshot to this page - * blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are - * transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read - * or copied from as usual. For more information, see - * the Azure Docs here and - * here. - * - * @param source - * The source page blob. - * @param snapshot - * The snapshot on the copy source. - * @param modifiedAccessConditions - * Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used - * to construct conditions related to when the blob was changed relative to the given request. The request - * will fail if the specified condition is not satisfied. - * - * @return Emits the successful response. - * @throws Error If {@code source} and {@code snapshot} form a malformed URL. - */ - public Mono copyIncremental(URL source, String snapshot, - ModifiedAccessConditions modifiedAccessConditions) { - - UrlBuilder builder = UrlBuilder.parse(source); - builder.setQueryParameter(Constants.SNAPSHOT_QUERY_PARAMETER, snapshot); - try { - source = builder.toURL(); - } catch (MalformedURLException e) { - // We are parsing a valid url and adding a query parameter. If this fails, we can't recover. - throw new Error(e); - } - return postProcessResponse(this.azureBlobStorage.pageBlobs().copyIncrementalWithRestResponseAsync( - null, null, source, null, null, modifiedAccessConditions, Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java index 284f74d0216ac..62d2146ea8d61 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobClient.java @@ -15,13 +15,14 @@ import com.azure.storage.blob.models.PageRange; import com.azure.storage.blob.models.SequenceNumberActionType; import com.azure.storage.blob.models.SourceModifiedAccessConditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; import java.io.InputStream; import java.net.URL; -import java.nio.ByteBuffer; import java.time.Duration; /** @@ -45,12 +46,12 @@ public final class PageBlobClient extends BlobClient { /** * Indicates the number of bytes in a page. */ - public static final int PAGE_BYTES = 512; + public static final int PAGE_BYTES = PageBlobAsyncClient.PAGE_BYTES; /** * Indicates the maximum number of bytes that may be sent in a call to putPage. */ - public static final int MAX_PUT_PAGES_BYTES = 4 * Constants.MB; + public static final int MAX_PUT_PAGES_BYTES = PageBlobAsyncClient.MAX_PUT_PAGES_BYTES; /** * Package-private constructor for use by {@link PageBlobClientBuilder}. @@ -189,7 +190,7 @@ public Response uploadPages(PageRange pageRange, InputStream body) public Response uploadPages(PageRange pageRange, InputStream body, PageBlobAccessConditions pageBlobAccessConditions, Duration timeout) { long length = pageRange.end() - pageRange.start(); - Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) PAGE_BYTES)) + Flux fbb = Flux.range(0, (int) Math.ceil((double) length / (double) PAGE_BYTES)) .map(i -> i * PAGE_BYTES) .concatMap(pos -> Mono.fromCallable(() -> { byte[] cache = new byte[PAGE_BYTES]; @@ -197,7 +198,8 @@ public Response uploadPages(PageRange pageRange, InputStream body, while (read < PAGE_BYTES) { read += body.read(cache, read, PAGE_BYTES - read); } - return ByteBuffer.wrap(cache); + + return ByteBufAllocator.DEFAULT.buffer(read).writeBytes(cache); })); Mono> response = pageBlobAsyncClient.uploadPages(pageRange, diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java index 114c28eb71209..f6b4767cada56 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ServiceSASSignatureValues.java @@ -12,10 +12,10 @@ import java.time.OffsetDateTime; /** - * ServiceSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage service. Once - * all the values here are set appropriately, call generateSASQueryParameters to obtain a representation of the SAS - * which can actually be applied to blob urls. Note: that both this class and {@link SASQueryParameters} exist because - * the former is mutable and a logical representation while the latter is immutable and used to generate actual REST + * ServiceSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage service. Once all + * the values here are set appropriately, call generateSASQueryParameters to obtain a representation of the SAS which + * can actually be applied to blob urls. Note: that both this class and {@link SASQueryParameters} exist because the + * former is mutable and a logical representation while the latter is immutable and used to generate actual REST * requests. *

* Please see here @@ -24,9 +24,9 @@ * Please see here for * more details on each value, including which are required. * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_sas "Sample code for ServiceSASSignatureValues")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) + * @apiNote ## Sample Code \n [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_sas + * "Sample code for ServiceSASSignatureValues")] \n For more samples, please see the [Samples + * file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) */ final class ServiceSASSignatureValues { @@ -68,6 +68,7 @@ final class ServiceSASSignatureValues { /** * Creates an object with the specified expiry time and permissions + * * @param expiryTime * @param permissions */ @@ -78,6 +79,7 @@ final class ServiceSASSignatureValues { /** * Creates an object with the specified identifier + * * @param identifier */ ServiceSASSignatureValues(String identifier) { @@ -85,8 +87,8 @@ final class ServiceSASSignatureValues { } ServiceSASSignatureValues(String version, SASProtocol sasProtocol, OffsetDateTime startTime, - OffsetDateTime expiryTime, String permission, IPRange ipRange, String identifier, String cacheControl, - String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { + OffsetDateTime expiryTime, String permission, IPRange ipRange, String identifier, String cacheControl, + String contentDisposition, String contentEncoding, String contentLanguage, String contentType) { if (version != null) { this.version = version; } @@ -229,6 +231,7 @@ public ServiceSASSignatureValues canonicalName(String canonicalName) { /** * The canonical name of the object the SAS user may access. + * * @throws RuntimeException If urlString is a malformed URL. */ public ServiceSASSignatureValues canonicalName(String urlString, String accountName) { @@ -359,9 +362,7 @@ public ServiceSASSignatureValues contentType(String contentType) { * Uses an account's shared key credential to sign these signature values to produce the proper SAS query * parameters. * - * @param sharedKeyCredentials - * A {@link SharedKeyCredential} object used to sign the SAS values. - * + * @param sharedKeyCredentials A {@link SharedKeyCredential} object used to sign the SAS values. * @return {@link SASQueryParameters} * @throws Error If the accountKey is not a valid Base64-encoded string. */ @@ -380,17 +381,15 @@ public SASQueryParameters generateSASQueryParameters(SharedKeyCredential sharedK } return new SASQueryParameters(this.version, null, null, - this.protocol, this.startTime, this.expiryTime, this.ipRange, this.identifier, resource, - this.permissions, signature, this.cacheControl, this.contentDisposition, this.contentEncoding, - this.contentLanguage, this.contentType, null /* delegate */); + this.protocol, this.startTime, this.expiryTime, this.ipRange, this.identifier, resource, + this.permissions, signature, this.cacheControl, this.contentDisposition, this.contentEncoding, + this.contentLanguage, this.contentType, null /* delegate */); } /** * Uses a user delegation key to sign these signature values to produce the proper SAS query parameters. * - * @param delegationKey - * A {@link UserDelegationKey} object used to sign the SAS values. - * + * @param delegationKey A {@link UserDelegationKey} object used to sign the SAS values. * @return {@link SASQueryParameters} * @throws Error If the accountKey is not a valid Base64-encoded string. */ @@ -409,9 +408,9 @@ public SASQueryParameters generateSASQueryParameters(UserDelegationKey delegatio } return new SASQueryParameters(this.version, null, null, - this.protocol, this.startTime, this.expiryTime, this.ipRange, null /* identifier */, resource, - this.permissions, signature, this.cacheControl, this.contentDisposition, this.contentEncoding, - this.contentLanguage, this.contentType, delegationKey); + this.protocol, this.startTime, this.expiryTime, this.ipRange, null /* identifier */, resource, + this.permissions, signature, this.cacheControl, this.contentDisposition, this.contentEncoding, + this.contentLanguage, this.contentType, delegationKey); } /** @@ -441,46 +440,46 @@ private void assertGenerateOK(boolean usingUserDelegation) { private String stringToSign() { return String.join("\n", - this.permissions == null ? "" : this.permissions, - this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), - this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), - this.canonicalName == null ? "" : this.canonicalName, - this.identifier == null ? "" : this.identifier, - this.ipRange == null ? (new IPRange()).toString() : this.ipRange.toString(), - this.protocol == null ? "" : protocol.toString(), - this.version == null ? "" : this.version, - this.resource == null ? "" : this.resource, - this.snapshotId == null ? "" : this.snapshotId, - this.cacheControl == null ? "" : this.cacheControl, - this.contentDisposition == null ? "" : this.contentDisposition, - this.contentEncoding == null ? "" : this.contentEncoding, - this.contentLanguage == null ? "" : this.contentLanguage, - this.contentType == null ? "" : this.contentType + this.permissions == null ? "" : this.permissions, + this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), + this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), + this.canonicalName == null ? "" : this.canonicalName, + this.identifier == null ? "" : this.identifier, + this.ipRange == null ? (new IPRange()).toString() : this.ipRange.toString(), + this.protocol == null ? "" : protocol.toString(), + this.version == null ? "" : this.version, + this.resource == null ? "" : this.resource, + this.snapshotId == null ? "" : this.snapshotId, + this.cacheControl == null ? "" : this.cacheControl, + this.contentDisposition == null ? "" : this.contentDisposition, + this.contentEncoding == null ? "" : this.contentEncoding, + this.contentLanguage == null ? "" : this.contentLanguage, + this.contentType == null ? "" : this.contentType ); } private String stringToSign(final UserDelegationKey key) { return String.join("\n", - this.permissions == null ? "" : this.permissions, - this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), - this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), - this.canonicalName == null ? "" : this.canonicalName, - key.signedOid() == null ? "" : key.signedOid(), - key.signedTid() == null ? "" : key.signedTid(), - key.signedStart() == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(key.signedStart()), - key.signedExpiry() == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(key.signedExpiry()), - key.signedService() == null ? "" : key.signedService(), - key.signedVersion() == null ? "" : key.signedVersion(), - this.ipRange == null ? new IPRange().toString() : this.ipRange.toString(), - this.protocol == null ? "" : this.protocol.toString(), - this.version == null ? "" : this.version, - this.resource == null ? "" : this.resource, - this.snapshotId == null ? "" : this.snapshotId, - this.cacheControl == null ? "" : this.cacheControl, - this.contentDisposition == null ? "" : this.contentDisposition, - this.contentEncoding == null ? "" : this.contentEncoding, - this.contentLanguage == null ? "" : this.contentLanguage, - this.contentType == null ? "" : this.contentType + this.permissions == null ? "" : this.permissions, + this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime), + this.expiryTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime), + this.canonicalName == null ? "" : this.canonicalName, + key.signedOid() == null ? "" : key.signedOid(), + key.signedTid() == null ? "" : key.signedTid(), + key.signedStart() == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(key.signedStart()), + key.signedExpiry() == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(key.signedExpiry()), + key.signedService() == null ? "" : key.signedService(), + key.signedVersion() == null ? "" : key.signedVersion(), + this.ipRange == null ? new IPRange().toString() : this.ipRange.toString(), + this.protocol == null ? "" : this.protocol.toString(), + this.version == null ? "" : this.version, + this.resource == null ? "" : this.resource, + this.snapshotId == null ? "" : this.snapshotId, + this.cacheControl == null ? "" : this.cacheControl, + this.contentDisposition == null ? "" : this.contentDisposition, + this.contentEncoding == null ? "" : this.contentEncoding, + this.contentLanguage == null ? "" : this.contentLanguage, + this.contentType == null ? "" : this.contentType ); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index c6c48d7e5770d..b93ee7bd579e7 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -8,8 +8,11 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; +import com.azure.core.util.Context; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.ContainerItem; +import com.azure.storage.blob.models.KeyInfo; import com.azure.storage.blob.models.ListContainersOptions; import com.azure.storage.blob.models.Metadata; import com.azure.storage.blob.models.PublicAccessType; @@ -26,11 +29,12 @@ import java.net.URL; import java.time.OffsetDateTime; +import static com.azure.storage.blob.Utility.postProcessResponse; + /** - * Client to a storage account. It may only be instantiated through a {@link StorageClientBuilder}. - * This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. + * Client to a storage account. It may only be instantiated through a {@link StorageClientBuilder}. This class does not + * hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests + * to the resource on the service. It may also be used to construct URLs to blobs and containers. * *

* This client contains operations on a blob. Operations on a container are available on {@link ContainerAsyncClient} @@ -41,36 +45,35 @@ * information on containers. * *

- * Note this client is an async client that returns reactive responses from Spring Reactor Core - * project (https://projectreactor.io/). Calling the methods in this client will NOT - * start the actual network operation, until {@code .subscribe()} is called on the reactive response. - * You can simply convert one of these responses to a {@link java.util.concurrent.CompletableFuture} - * object through {@link Mono#toFuture()}. + * Note this client is an async client that returns reactive responses from Spring Reactor Core project + * (https://projectreactor.io/). Calling the methods in this client will NOT start the actual network + * operation, until {@code .subscribe()} is called on the reactive response. You can simply convert one of these + * responses to a {@link java.util.concurrent.CompletableFuture} object through {@link Mono#toFuture()}. */ public final class StorageAsyncClient { - StorageAsyncRawClient storageAsyncRawClient; + private final AzureBlobStorageImpl azureBlobStorage; /** * Package-private constructor for use by {@link StorageClientBuilder}. + * * @param azureBlobStorageBuilder the API client builder for blob storage API */ StorageAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.storageAsyncRawClient = new StorageAsyncRawClient(azureBlobStorageBuilder.build()); + this.azureBlobStorage = azureBlobStorageBuilder.build(); } /** - * Initializes a {@link ContainerAsyncClient} object pointing to the specified container. This method does not create a - * container. It simply constructs the URL to the container and offers access to methods relevant to containers. + * Initializes a {@link ContainerAsyncClient} object pointing to the specified container. This method does not + * create a container. It simply constructs the URL to the container and offers access to methods relevant to + * containers. * - * @param containerName - * The name of the container to point to. - * @return - * A {@link ContainerAsyncClient} object pointing to the specified container + * @param containerName The name of the container to point to. + * @return A {@link ContainerAsyncClient} object pointing to the specified container */ public ContainerAsyncClient getContainerAsyncClient(String containerName) { return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getAccountUrl(), containerName).toString()) - .pipeline(storageAsyncRawClient.azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline())); } /** @@ -91,11 +94,9 @@ public Mono> createContainer(String containerName * Azure Docs. * * @param containerName Name of the container to create - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. + * @param metadata {@link Metadata} + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. * @return A response containing a {@link ContainerAsyncClient} used to interact with the container created. */ public Mono> createContainer(String containerName, Metadata metadata, PublicAccessType accessType) { @@ -107,50 +108,76 @@ public Mono> createContainer(String containerName /** * Gets the URL of the storage account represented by this client. + * * @return the URL. * @throws RuntimeException If the account URL is malformed. */ public URL getAccountUrl() { try { - return new URL(storageAsyncRawClient.azureBlobStorage.url()); + return new URL(azureBlobStorage.url()); } catch (MalformedURLException e) { - throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), storageAsyncRawClient.azureBlobStorage.url()), e); + throw new RuntimeException(String.format("Invalid URL on %s: %s" + getClass().getSimpleName(), azureBlobStorage.url()), e); } } /** - * Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, see - * the Azure Docs. + * Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, + * see the Azure Docs. * - * @return - * A reactive response emitting the list of containers. + * @return A reactive response emitting the list of containers. */ public Flux listContainers() { return this.listContainers(new ListContainersOptions()); } /** - * Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, see + * Returns a reactive Publisher emitting all the containers in this account lazily as needed. For more information, + * see the Azure Docs. + * + * @param options A {@link ListContainersOptions} which specifies what data should be returned by the service. + * @return A reactive response emitting the list of containers. + */ + public Flux listContainers(ListContainersOptions options) { + return listContainersSegment(null, options) + .flatMapMany(response -> listContainersHelper(response.value().marker(), options, response)); + } + + /* + * Returns a Mono segment of containers starting from the specified Marker. + * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. + * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned + * Marker) to get the next segment. For more information, see * the Azure Docs. * + * @param marker + * Identifies the portion of the list to be returned with the next list operation. + * This value is returned in the response of a previous list operation as the + * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. * @param options * A {@link ListContainersOptions} which specifies what data should be returned by the service. * - * @return - * A reactive response emitting the list of containers. + * @return Emits the successful response. + * + * @apiNote ## Sample Code \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n + * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n + * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) */ - public Flux listContainers(ListContainersOptions options) { - return storageAsyncRawClient - .listContainersSegment(null, options) - .flatMapMany(response -> listContainersHelper(response.value().marker(), options, response)); + private Mono listContainersSegment(String marker, ListContainersOptions options) { + options = options == null ? new ListContainersOptions() : options; + + return postProcessResponse( + this.azureBlobStorage.services().listContainersSegmentWithRestResponseAsync( + options.prefix(), marker, options.maxResults(), options.details().toIncludeType(), null, + null, Context.NONE)); } private Flux listContainersHelper(String marker, ListContainersOptions options, - ServicesListContainersSegmentResponse response) { + ServicesListContainersSegmentResponse response) { Flux result = Flux.fromIterable(response.value().containerItems()); if (response.value().nextMarker() != null) { // Recursively add the continuation items to the observable. - result = result.concatWith(storageAsyncRawClient.listContainersSegment(marker, options) + result = result.concatWith(listContainersSegment(marker, options) .flatMapMany((r) -> listContainersHelper(response.value().nextMarker(), options, r))); } @@ -162,12 +189,11 @@ private Flux listContainersHelper(String marker, ListContainersOp * Gets the properties of a storage account’s Blob service. For more information, see the * Azure Docs. * - * @return - * A reactive response containing the storage account properties. + * @return A reactive response containing the storage account properties. */ public Mono> getProperties() { - return storageAsyncRawClient - .getProperties() + return postProcessResponse( + this.azureBlobStorage.services().getPropertiesWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.value())); } @@ -177,48 +203,50 @@ public Mono> getProperties() { * Note that setting the default service version has no effect when using this client because this client explicitly * sets the version header on each request, overriding the default. * - * @param properties - * Configures the service. - * - * @return - * A reactive response containing the storage account properties. + * @param properties Configures the service. + * @return A reactive response containing the storage account properties. */ public Mono setProperties(StorageServiceProperties properties) { - return storageAsyncRawClient - .setProperties(properties) + return postProcessResponse( + this.azureBlobStorage.services().setPropertiesWithRestResponseAsync(properties, null, null, Context.NONE)) .map(VoidResponse::new); } /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link TokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. + * Gets a user delegation key for use with this account's blob storage. Note: This method call is only valid when + * using {@link TokenCredential} in this object's {@link HttpPipeline}. * - * @return - * A reactive response containing the user delegation key. + * @param start Start time for the key's validity. Null indicates immediate start. + * @param expiry Expiration of the key's validity. + * @return A reactive response containing the user delegation key. + * @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}. */ public Mono> getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - return storageAsyncRawClient - .getUserDelegationKey(start, expiry) - .map(rb -> new SimpleResponse<>(rb, rb.value())); + Utility.assertNotNull("expiry", expiry); + if (start != null && !start.isBefore(expiry)) { + throw new IllegalArgumentException("`start` must be null or a datetime before `expiry`."); + } + + return postProcessResponse( + this.azureBlobStorage.services().getUserDelegationKeyWithRestResponseAsync( + new KeyInfo() + .start(start == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(start)) + .expiry(Utility.ISO_8601_UTC_DATE_FORMATTER.format(expiry)), + null, null, Context.NONE) + ).map(rb -> new SimpleResponse<>(rb, rb.value())); } /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the + * Retrieves statistics related to replication for the Blob service. It is only available on the secondary location + * endpoint when read-access geo-redundant replication is enabled for the storage account. For more information, see + * the * Azure Docs. * - * @return - * A reactive response containing the storage account statistics. + * @return A reactive response containing the storage account statistics. */ public Mono> getStatistics() { - return storageAsyncRawClient - .getStatistics() + return postProcessResponse( + this.azureBlobStorage.services().getStatisticsWithRestResponseAsync(null, null, Context.NONE)) .map(rb -> new SimpleResponse<>(rb, rb.value())); } @@ -226,32 +254,24 @@ public Mono> getStatistics() { * Returns the sku name and account kind for the account. For more information, please see the * Azure Docs. * - * @return - * A reactive response containing the storage account info. + * @return A reactive response containing the storage account info. */ public Mono> getAccountInfo() { - return storageAsyncRawClient - .getAccountInfo() + return postProcessResponse(this.azureBlobStorage.services().getAccountInfoWithRestResponseAsync(Context.NONE)) .map(rb -> new SimpleResponse<>(rb, new StorageAccountInfo(rb.deserializedHeaders()))); } /** * Generates an account SAS token with the specified parameters * - * @param accountSASService - * The {@code AccountSASService} services for the account SAS - * @param accountSASResourceType - * An optional {@code AccountSASResourceType} resources for the account SAS - * @param accountSASPermission - * The {@code AccountSASPermission} permission for the account SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the account SAS - * - * @return - * A string that represents the SAS token + * @param accountSASService The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the account SAS + * @return A string that represents the SAS token */ public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, - AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { return this.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime, null /* startTime */, null /* version */, null /* ipRange */, null /* sasProtocol */); } @@ -259,29 +279,19 @@ public String generateAccountSAS(AccountSASService accountSASService, AccountSAS /** * Generates an account SAS token with the specified parameters * - * @param accountSASService - * The {@code AccountSASService} services for the account SAS - * @param accountSASResourceType - * An optional {@code AccountSASResourceType} resources for the account SAS - * @param accountSASPermission - * The {@code AccountSASPermission} permission for the account SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the account SAS - * @param startTime - * The {@code OffsetDateTime} start time for the account SAS - * @param version - * The {@code String} version for the account SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * - * @return - * A string that represents the SAS token + * @param accountSASService The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the account SAS + * @param startTime The {@code OffsetDateTime} start time for the account SAS + * @param version The {@code String} version for the account SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @return A string that represents the SAS token */ public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, - AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, - SASProtocol sasProtocol) { + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, + SASProtocol sasProtocol) { AccountSASSignatureValues accountSASSignatureValues = new AccountSASSignatureValues(); accountSASSignatureValues.services(accountSASService == null ? null : accountSASService.toString()); @@ -297,7 +307,7 @@ public String generateAccountSAS(AccountSASService accountSASService, AccountSAS accountSASSignatureValues.ipRange(ipRange); accountSASSignatureValues.protocol(sasProtocol); - SharedKeyCredential sharedKeyCredential = Utility.getSharedKeyCredential(this.storageAsyncRawClient.azureBlobStorage.httpPipeline()); + SharedKeyCredential sharedKeyCredential = Utility.getSharedKeyCredential(this.azureBlobStorage.httpPipeline()); SASQueryParameters sasQueryParameters = accountSASSignatureValues.generateSASQueryParameters(sharedKeyCredential); diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java deleted file mode 100644 index a2b6be965ed30..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncRawClient.java +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.credentials.TokenCredential; -import com.azure.core.http.HttpPipeline; -import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.KeyInfo; -import com.azure.storage.blob.models.ListContainersOptions; -import com.azure.storage.blob.models.ServicesGetAccountInfoResponse; -import com.azure.storage.blob.models.ServicesGetPropertiesResponse; -import com.azure.storage.blob.models.ServicesGetStatisticsResponse; -import com.azure.storage.blob.models.ServicesGetUserDelegationKeyResponse; -import com.azure.storage.blob.models.ServicesListContainersSegmentResponse; -import com.azure.storage.blob.models.ServicesSetPropertiesResponse; -import com.azure.storage.blob.models.StorageServiceProperties; -import reactor.core.publisher.Mono; - -import java.time.OffsetDateTime; - -import static com.azure.storage.blob.Utility.postProcessResponse; - -/** - * Represents a URL to a storage service. This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. - * Please see here for more - * information on containers. - */ -final class StorageAsyncRawClient { - - final AzureBlobStorageImpl azureBlobStorage; - - /** - * Creates a {@code ServiceURL} object pointing to the account specified by the URL and using the provided pipeline - * to make HTTP requests. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_url "Sample code for ServiceURL constructor")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - StorageAsyncRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.azureBlobStorage = azureBlobStorage; - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono listContainersSegment(String marker, - ListContainersOptions options) { - options = options == null ? new ListContainersOptions() : options; - - return postProcessResponse( - this.azureBlobStorage.services().listContainersSegmentWithRestResponseAsync( - options.prefix(), marker, options.maxResults(), options.details().toIncludeType(), null, - null, Context.NONE)); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getProperties() { - return postProcessResponse( - this.azureBlobStorage.services().getPropertiesWithRestResponseAsync(null, null, Context.NONE)); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono setProperties(StorageServiceProperties properties) { - return postProcessResponse( - this.azureBlobStorage.services().setPropertiesWithRestResponseAsync(properties, null, null, Context.NONE)); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link TokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - * @throws IllegalArgumentException If {@code start} isn't null and is after {@code expiry}. - */ - public Mono getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - Utility.assertNotNull("expiry", expiry); - if (start != null && !start.isBefore(expiry)) { - throw new IllegalArgumentException("`start` must be null or a datetime before `expiry`."); - } - - return postProcessResponse( - this.azureBlobStorage.services().getUserDelegationKeyWithRestResponseAsync( - new KeyInfo() - .start(start == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(start)) - .expiry(Utility.ISO_8601_UTC_DATE_FORMATTER.format(expiry)), - null, null, Context.NONE) - ); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getStatistics() { - return postProcessResponse( - this.azureBlobStorage.services().getStatisticsWithRestResponseAsync(null, null, Context.NONE)); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public Mono getAccountInfo() { - return postProcessResponse( - this.azureBlobStorage.services().getAccountInfoWithRestResponseAsync(Context.NONE)); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java index c895cdda58bbc..1511726d653bb 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClient.java @@ -24,25 +24,24 @@ import java.time.OffsetDateTime; /** - * Client to a storage account. It may only be instantiated through a {@link StorageClientBuilder}. - * This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. + * Client to a storage account. It may only be instantiated through a {@link StorageClientBuilder}. This class does not + * hold any state about a particular storage account but is instead a convenient way of sending off appropriate requests + * to the resource on the service. It may also be used to construct URLs to blobs and containers. * *

- * This client contains operations on a blob. Operations on a container are available on {@link ContainerClient} - * through {@link #getContainerClient(String)}, and operations on a blob are available on {@link BlobClient}. + * This client contains operations on a blob. Operations on a container are available on {@link ContainerClient} through + * {@link #getContainerClient(String)}, and operations on a blob are available on {@link BlobClient}. * *

* Please see here for more * information on containers. */ public final class StorageClient { - - private StorageAsyncClient storageAsyncClient; + private final StorageAsyncClient storageAsyncClient; /** * Package-private constructor for use by {@link StorageClientBuilder}. + * * @param storageAsyncClient the async storage account client */ StorageClient(StorageAsyncClient storageAsyncClient) { @@ -53,10 +52,8 @@ public final class StorageClient { * Initializes a {@link ContainerClient} object pointing to the specified container. This method does not create a * container. It simply constructs the URL to the container and offers access to methods relevant to containers. * - * @param containerName - * The name of the container to point to. - * @return - * A {@link ContainerClient} object pointing to the specified container + * @param containerName The name of the container to point to. + * @return A {@link ContainerClient} object pointing to the specified container */ public ContainerClient getContainerClient(String containerName) { return new ContainerClient(storageAsyncClient.getContainerAsyncClient(containerName)); @@ -80,11 +77,9 @@ public Response createContainer(String containerName) { * Azure Docs. * * @param containerName Name of the container to create - * @param metadata - * {@link Metadata} - * @param accessType - * Specifies how the data in this container is available to the public. See the x-ms-blob-public-access header - * in the Azure Docs for more information. Pass null for no public access. + * @param metadata {@link Metadata} + * @param accessType Specifies how the data in this container is available to the public. See the + * x-ms-blob-public-access header in the Azure Docs for more information. Pass null for no public access. * @return A response containing a {@link ContainerClient} used to interact with the container created. */ public Response createContainer(String containerName, Metadata metadata, PublicAccessType accessType) { @@ -95,6 +90,7 @@ public Response createContainer(String containerName, Metadata /** * Gets the URL of the storage account represented by this client. + * * @return the URL. */ public URL getAccountUrl() { @@ -102,29 +98,24 @@ public URL getAccountUrl() { } /** - * Returns a lazy loaded list of containers in this account. The returned {@link Iterable} can be iterated - * through while new items are automatically retrieved as needed. For more information, see - * the Azure Docs. + * Returns a lazy loaded list of containers in this account. The returned {@link Iterable} can be iterated through + * while new items are automatically retrieved as needed. For more information, see the Azure Docs. * - * @return - * The list of containers. + * @return The list of containers. */ public Iterable listContainers() { return this.listContainers(new ListContainersOptions(), null); } /** - * Returns a lazy loaded list of containers in this account. The returned {@link Iterable} can be iterated - * through while new items are automatically retrieved as needed. For more information, see - * the Azure Docs. - * - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * Returns a lazy loaded list of containers in this account. The returned {@link Iterable} can be iterated through + * while new items are automatically retrieved as needed. For more information, see the Azure Docs. * - * @return - * The list of containers. + * @param options A {@link ListContainersOptions} which specifies what data should be returned by the service. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The list of containers. */ public Iterable listContainers(ListContainersOptions options, Duration timeout) { Flux response = storageAsyncClient.listContainers(options); @@ -136,8 +127,7 @@ public Iterable listContainers(ListContainersOptions options, Dur * Gets the properties of a storage account’s Blob service. For more information, see the * Azure Docs. * - * @return - * The storage account properties. + * @return The storage account properties. */ public Response getProperties() { return this.getProperties(null); @@ -147,11 +137,8 @@ public Response getProperties() { * Gets the properties of a storage account’s Blob service. For more information, see the * Azure Docs. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The storage account properties. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The storage account properties. */ public Response getProperties(Duration timeout) { @@ -166,11 +153,8 @@ public Response getProperties(Duration timeout) { * Note that setting the default service version has no effect when using this client because this client explicitly * sets the version header on each request, overriding the default. * - * @param properties - * Configures the service. - * - * @return - * The storage account properties. + * @param properties Configures the service. + * @return The storage account properties. */ public VoidResponse setProperties(StorageServiceProperties properties) { return this.setProperties(properties, null); @@ -182,13 +166,9 @@ public VoidResponse setProperties(StorageServiceProperties properties) { * Note that setting the default service version has no effect when using this client because this client explicitly * sets the version header on each request, overriding the default. * - * @param properties - * Configures the service. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The storage account properties. + * @param properties Configures the service. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The storage account properties. */ public VoidResponse setProperties(StorageServiceProperties properties, Duration timeout) { Mono response = storageAsyncClient.setProperties(properties); @@ -197,66 +177,53 @@ public VoidResponse setProperties(StorageServiceProperties properties, Duration } /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link TokenCredential} in this object's {@link HttpPipeline}. + * Gets a user delegation key for use with this account's blob storage. Note: This method call is only valid when + * using {@link TokenCredential} in this object's {@link HttpPipeline}. * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return - * The user delegation key. + * @param start Start time for the key's validity. Null indicates immediate start. + * @param expiry Expiration of the key's validity. + * @return The user delegation key. */ public Response getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { return this.getUserDelegationKey(start, expiry, null); } /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link TokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. + * Gets a user delegation key for use with this account's blob storage. Note: This method call is only valid when + * using {@link TokenCredential} in this object's {@link HttpPipeline}. * - * @return - * The user delegation key. + * @param start Start time for the key's validity. Null indicates immediate start. + * @param expiry Expiration of the key's validity. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The user delegation key. */ public Response getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry, - Duration timeout) { + Duration timeout) { Mono> response = storageAsyncClient.getUserDelegationKey(start, expiry); return Utility.blockWithOptionalTimeout(response, timeout); } /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the + * Retrieves statistics related to replication for the Blob service. It is only available on the secondary location + * endpoint when read-access geo-redundant replication is enabled for the storage account. For more information, see + * the * Azure Docs. * - * @return - * The storage account statistics. + * @return The storage account statistics. */ public Response getStatistics() { return this.getStatistics(null); } /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the + * Retrieves statistics related to replication for the Blob service. It is only available on the secondary location + * endpoint when read-access geo-redundant replication is enabled for the storage account. For more information, see + * the * Azure Docs. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The storage account statistics. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The storage account statistics. */ public Response getStatistics(Duration timeout) { Mono> response = storageAsyncClient.getStatistics(); @@ -268,8 +235,7 @@ public Response getStatistics(Duration timeout) { * Returns the sku name and account kind for the account. For more information, please see the * Azure Docs. * - * @return - * The storage account info. + * @return The storage account info. */ public Response getAccountInfo() { return this.getAccountInfo(null); @@ -279,11 +245,8 @@ public Response getAccountInfo() { * Returns the sku name and account kind for the account. For more information, please see the * Azure Docs. * - * @param timeout - * An optional timeout value beyond which a {@link RuntimeException} will be raised. - * - * @return - * The storage account info. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. + * @return The storage account info. */ public Response getAccountInfo(Duration timeout) { Mono> response = storageAsyncClient.getAccountInfo(); @@ -294,49 +257,33 @@ public Response getAccountInfo(Duration timeout) { /** * Generates an account SAS token with the specified parameters * - * @param accountSASService - * The {@code AccountSASService} services for the account SAS - * @param accountSASResourceType - * An optional {@code AccountSASResourceType} resources for the account SAS - * @param accountSASPermission - * The {@code AccountSASPermission} permission for the account SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the account SAS - * - * @return - * A string that represents the SAS token + * @param accountSASService The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the account SAS + * @return A string that represents the SAS token */ public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, - AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime) { return this.storageAsyncClient.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime); } /** * Generates an account SAS token with the specified parameters * - * @param accountSASService - * The {@code AccountSASService} services for the account SAS - * @param accountSASResourceType - * An optional {@code AccountSASResourceType} resources for the account SAS - * @param accountSASPermission - * The {@code AccountSASPermission} permission for the account SAS - * @param expiryTime - * The {@code OffsetDateTime} expiry time for the account SAS - * @param startTime - * The {@code OffsetDateTime} start time for the account SAS - * @param version - * The {@code String} version for the account SAS - * @param ipRange - * An optional {@code IPRange} ip address range for the SAS - * @param sasProtocol - * An optional {@code SASProtocol} protocol for the SAS - * - * @return - * A string that represents the SAS token + * @param accountSASService The {@code AccountSASService} services for the account SAS + * @param accountSASResourceType An optional {@code AccountSASResourceType} resources for the account SAS + * @param accountSASPermission The {@code AccountSASPermission} permission for the account SAS + * @param expiryTime The {@code OffsetDateTime} expiry time for the account SAS + * @param startTime The {@code OffsetDateTime} start time for the account SAS + * @param version The {@code String} version for the account SAS + * @param ipRange An optional {@code IPRange} ip address range for the SAS + * @param sasProtocol An optional {@code SASProtocol} protocol for the SAS + * @return A string that represents the SAS token */ public String generateAccountSAS(AccountSASService accountSASService, AccountSASResourceType accountSASResourceType, - AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, - SASProtocol sasProtocol) { + AccountSASPermission accountSASPermission, OffsetDateTime expiryTime, OffsetDateTime startTime, String version, IPRange ipRange, + SASProtocol sasProtocol) { return this.storageAsyncClient.generateAccountSAS(accountSASService, accountSASResourceType, accountSASPermission, expiryTime, startTime, version, ipRange, sasProtocol); } } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java deleted file mode 100644 index cebfdc451ae67..0000000000000 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageRawClient.java +++ /dev/null @@ -1,259 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.storage.blob; - -import com.azure.core.http.HttpPipeline; -import com.azure.storage.blob.implementation.AzureBlobStorageImpl; -import com.azure.storage.blob.models.ListContainersOptions; -import com.azure.storage.blob.models.ServicesGetAccountInfoResponse; -import com.azure.storage.blob.models.ServicesGetPropertiesResponse; -import com.azure.storage.blob.models.ServicesGetStatisticsResponse; -import com.azure.storage.blob.models.ServicesGetUserDelegationKeyResponse; -import com.azure.storage.blob.models.ServicesListContainersSegmentResponse; -import com.azure.storage.blob.models.ServicesSetPropertiesResponse; -import com.azure.storage.blob.models.StorageServiceProperties; -import com.azure.storage.common.credentials.SASTokenCredential; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.time.OffsetDateTime; - -/** - * Represents a URL to a storage service. This class does not hold any state about a particular storage account but is - * instead a convenient way of sending off appropriate requests to the resource on the service. - * It may also be used to construct URLs to blobs and containers. - * Please see here for more - * information on containers. - */ -final class StorageRawClient { - - StorageAsyncRawClient storageAsyncRawClient; - - /** - * Creates a {@code ServiceURL} object pointing to the account specified by the URL and using the provided pipeline - * to make HTTP requests. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_url "Sample code for ServiceURL constructor")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - StorageRawClient(AzureBlobStorageImpl azureBlobStorage) { - this.storageAsyncRawClient = new StorageAsyncRawClient(azureBlobStorage); - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesListContainersSegmentResponse listContainersSegment(String marker, - ListContainersOptions options) { - return this.listContainersSegment(marker, options, null); - } - - /** - * Returns a Mono segment of containers starting from the specified Marker. - * Use an empty marker to start enumeration from the beginning. Container names are returned in lexicographic order. - * After getting a segment, process it, and then call ListContainers again (passing the the previously-returned - * Marker) to get the next segment. For more information, see - * the Azure Docs. - * - * @param marker - * Identifies the portion of the list to be returned with the next list operation. - * This value is returned in the response of a previous list operation as the - * ListContainersSegmentResponse.body().nextMarker(). Set to null to list the first segment. - * @param options - * A {@link ListContainersOptions} which specifies what data should be returned by the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list "Sample code for ServiceURL.listContainersSegment")] \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_list_helper "Helper code for ServiceURL.listContainersSegment")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesListContainersSegmentResponse listContainersSegment(String marker, - ListContainersOptions options, Duration timeout) { - Mono response = storageAsyncRawClient.listContainersSegment(marker, options); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetPropertiesResponse getProperties() { - return this.getProperties(null); - } - - /** - * Gets the properties of a storage account’s Blob service. For more information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.getProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetPropertiesResponse getProperties(Duration timeout) { - Mono response = storageAsyncRawClient.getProperties(); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesSetPropertiesResponse setProperties(StorageServiceProperties properties) { - return this.setProperties(properties, null); - } - - /** - * Sets properties for a storage account's Blob service endpoint. For more information, see the - * Azure Docs. - * Note that setting the default service version has no effect when using this client because this client explicitly - * sets the version header on each request, overriding the default. - * - * @param properties - * Configures the service. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_getsetprops "Sample code for ServiceURL.setProperties")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesSetPropertiesResponse setProperties(StorageServiceProperties properties, Duration timeout) { - Mono response = storageAsyncRawClient.setProperties(properties); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link SASTokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - */ - public ServicesGetUserDelegationKeyResponse getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry) { - return this.getUserDelegationKey(start, expiry, null); - } - - /** - * Gets a user delegation key for use with this account's blob storage. - * Note: This method call is only valid when using {@link SASTokenCredential} in this object's {@link HttpPipeline}. - * - * @param start - * Start time for the key's validity. Null indicates immediate start. - * @param expiry - * Expiration of the key's validity. - * - * @return Emits the successful response. - */ - public ServicesGetUserDelegationKeyResponse getUserDelegationKey(OffsetDateTime start, OffsetDateTime expiry, - Duration timeout) { - Mono response = storageAsyncRawClient.getUserDelegationKey(start, expiry); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetStatisticsResponse getStatistics() { - return this.getStatistics(null); - } - - /** - * Retrieves statistics related to replication for the Blob service. It is only available on the secondary - * location endpoint when read-access geo-redundant replication is enabled for the storage account. For more - * information, see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_stats "Sample code for ServiceURL.getStats")] \n - * For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetStatisticsResponse getStatistics(Duration timeout) { - Mono response = storageAsyncRawClient.getStatistics(); - return Utility.blockWithOptionalTimeout(response, timeout); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetAccountInfoResponse getAccountInfo() { - return this.getAccountInfo(null); - } - - /** - * Returns the sku name and account kind for the account. For more information, please see the - * Azure Docs. - * - * @return Emits the successful response. - * - * @apiNote ## Sample Code \n - * [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=account_info "Sample code for ServiceURL.getAccountInfo")] \n - * For more samples, please see the [Samples file] (https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java) - */ - public ServicesGetAccountInfoResponse getAccountInfo(Duration timeout) { - Mono response = storageAsyncRawClient.getAccountInfo(); - return Utility.blockWithOptionalTimeout(response, timeout); - } -} diff --git a/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java b/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java index 4dce1c831ce21..cff7bc91f7765 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java +++ b/storage/client/blob/src/main/java/com/azure/storage/common/credentials/SASTokenCredential.java @@ -43,6 +43,7 @@ public final class SASTokenCredential { /** * Creates a SAS token credential from the passed SAS token. + * * @param sasToken SAS token used to authenticate requests with the service. */ public SASTokenCredential(String sasToken) { @@ -58,6 +59,7 @@ public String sasToken() { /** * Creates a SAS token credential from the passed URL query string + * * @param query URL query used to build the SAS token * @return a SAS token credential if the query param contains all the necessary pieces */ diff --git a/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java b/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java index 743eae8f262e4..e8b54914cb762 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java +++ b/storage/client/blob/src/main/java/com/azure/storage/common/policy/SharedKeyCredentialPolicy.java @@ -18,6 +18,7 @@ public final class SharedKeyCredentialPolicy implements HttpPipelinePolicy { /** * Creates a SharedKey pipeline policy that adds the SharedKey into the request's authorization header. + * * @param credential the SharedKey credential used to create the policy. */ public SharedKeyCredentialPolicy(SharedKeyCredential credential) { @@ -25,9 +26,7 @@ public SharedKeyCredentialPolicy(SharedKeyCredential credential) { } /** - * Gets the shared key credential linked to the policy. - * @return - * The {@link SharedKeyCredential} linked to the policy. + * @return the {@link SharedKeyCredential} linked to the policy. */ public SharedKeyCredential sharedKeyCredential() { return this.credential; diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java b/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java index 1ac12cbe978da..f6d19d6b84167 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/Sample.java @@ -8,6 +8,8 @@ import com.azure.storage.blob.models.BlobItem; import com.azure.storage.blob.models.ContainerItem; import com.azure.storage.common.credentials.SharedKeyCredential; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -16,7 +18,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.UUID; @@ -116,8 +117,7 @@ public void asyncSample() throws IOException { for (int i = 0; i < 5; i++) { BlockBlobAsyncClient blobClient = finalContainerClient.getBlockBlobAsyncClient("testblob-" + i); byte[] message = ("test data" + i).getBytes(StandardCharsets.UTF_8); - Flux testdata = Flux.just(ByteBuffer.wrap(message)); - + Flux testdata = Flux.just(ByteBufAllocator.DEFAULT.buffer(message.length).writeBytes(message)); finished = finished.and(blobClient.upload(testdata, message.length) .then(Mono.defer(() -> { From acdea023fa751d64a97561652579458f2f7e3141 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 18 Jul 2019 09:36:39 -0700 Subject: [PATCH 6/9] Added getAppendBlob with snapshot to ContainerClient --- .../com/azure/storage/blob/ContainerClient.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java index de5d4f1431f39..12d5844a696f4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClient.java @@ -127,6 +127,22 @@ public AppendBlobClient getAppendBlobClient(String blobName) { return new AppendBlobClient(containerAsyncClient.getAppendBlobAsyncClient(blobName)); } + /** + * Creates creates a new AppendBlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. + * The new AppendBlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the + * pipeline, create the AppendBlobClient and then call its WithPipeline method passing in the desired pipeline + * object. Or, call this package's NewAppendBlobAsyncClient instead of calling this object's + * NewAppendBlobAsyncClient method. + * + * @param blobName A {@code String} representing the name of the blob. + * @param snapshot the snapshot identifier for the blob. + * @return A new {@link AppendBlobClient} object which references the blob with the specified name in this + * container. + */ + public AppendBlobClient getAppendBlobClient(String blobName, String snapshot) { + return new AppendBlobClient(containerAsyncClient.getAppendBlobAsyncClient(blobName, snapshot)); + } + /** * Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new * BlobClient uses the same request policy pipeline as the ContainerAsyncClient. To change the pipeline, create the From 8f056165f7d29ee2d242037e1599cf5f987ef791 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 18 Jul 2019 11:17:12 -0700 Subject: [PATCH 7/9] Updated Storage and Container clients to use AzureBlobStorageImpl to construct clients --- .../storage/blob/ContainerAsyncClient.java | 9 ++-- .../storage/blob/ContainerClientBuilder.java | 47 ++++++++----------- .../storage/blob/StorageAsyncClient.java | 6 +-- .../storage/blob/StorageClientBuilder.java | 31 ++++++------ 4 files changed, 41 insertions(+), 52 deletions(-) diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 936bab6932528..47e8207403f00 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -71,10 +71,10 @@ public final class ContainerAsyncClient { /** * Package-private constructor for use by {@link ContainerClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - ContainerAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + ContainerAsyncClient(AzureBlobStorageImpl azureBlobStorage) { + this.azureBlobStorage = azureBlobStorage; } /** @@ -213,7 +213,8 @@ public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { public StorageAsyncClient getStorageAsyncClient() { return new StorageAsyncClient(new AzureBlobStorageBuilder() .url(Utility.stripLastPathSegment(getContainerUrl()).toString()) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline()) + .build()); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java index c1e4e6bbdaeb2..aaae09fb6ab05 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerClientBuilder.java @@ -78,10 +78,16 @@ public ContainerClientBuilder() { } /** - * Constructs an instance of ContainerAsyncClient based on the configurations stored in the appendBlobClientBuilder. - * @return a new client instance + * @return a {@link ContainerClient} created from the configurations in this builder. + */ + public ContainerClient buildClient() { + return new ContainerClient(buildAsyncClient()); + } + + /** + * @return a {@link ContainerAsyncClient} created from the configurations in this builder. */ - private AzureBlobStorageBuilder buildImpl() { + public ContainerAsyncClient buildAsyncClient() { Objects.requireNonNull(endpoint); Objects.requireNonNull(containerName); @@ -115,36 +121,21 @@ private AzureBlobStorageBuilder buildImpl() { .httpClient(httpClient) .build(); - return new AzureBlobStorageBuilder() + return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s/%s", endpoint, containerName)) - .pipeline(pipeline); - } - - /** - * @return a {@link ContainerClient} created from the configurations in this builder. - */ - public ContainerClient buildClient() { - return new ContainerClient(buildAsyncClient()); - } - - /** - * @return a {@link ContainerAsyncClient} created from the configurations in this builder. - */ - public ContainerAsyncClient buildAsyncClient() { - return new ContainerAsyncClient(buildImpl()); + .pipeline(pipeline) + .build()); } /** * Sets the service endpoint, additionally parses it for information (SAS token, container name) * @param endpoint URL of the service * @return the updated ContainerClientBuilder object - * @throws IllegalArgumentException If {@code endpoint} is a malformed URL. + * @throws IllegalArgumentException If {@code endpoint} is {@code null} or is a malformed URL. */ public ContainerClientBuilder endpoint(String endpoint) { - Objects.requireNonNull(endpoint); - URL url; try { - url = new URL(endpoint); + URL url = new URL(endpoint); this.endpoint = url.getProtocol() + "://" + url.getAuthority(); String path = url.getPath(); if (path != null && !path.isEmpty() && !path.equals("/")) { @@ -155,15 +146,15 @@ public ContainerClientBuilder endpoint(String endpoint) { this.containerName = path; } } + + SASTokenCredential credential = SASTokenCredential.fromQuery(url.getQuery()); + if (credential != null) { + this.credential(credential); + } } catch (MalformedURLException ex) { throw new IllegalArgumentException("The Azure Storage Blob endpoint url is malformed."); } - SASTokenCredential credential = SASTokenCredential.fromQuery(url.getQuery()); - if (credential != null) { - this.credential(credential); - } - return this; } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index 9e4d0fb2140f5..5203875eb93d3 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -56,10 +56,10 @@ public final class StorageAsyncClient { /** * Package-private constructor for use by {@link StorageClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - StorageAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + StorageAsyncClient(AzureBlobStorageImpl azureBlobStorage) { + this.azureBlobStorage = azureBlobStorage; } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java index 0aff9d26aa029..5893347ed2c40 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageClientBuilder.java @@ -76,7 +76,17 @@ public StorageClientBuilder() { policies = new ArrayList<>(); } - private AzureBlobStorageBuilder buildImpl() { + /** + * @return a {@link StorageClient} created from the configurations in this builder. + */ + public StorageClient buildClient() { + return new StorageClient(buildAsyncClient()); + } + + /** + * @return a {@link StorageAsyncClient} created from the configurations in this builder. + */ + public StorageAsyncClient buildAsyncClient() { Objects.requireNonNull(endpoint); // Closest to API goes first, closest to wire goes last. @@ -109,23 +119,10 @@ private AzureBlobStorageBuilder buildImpl() { .httpClient(httpClient) .build(); - return new AzureBlobStorageBuilder() + return new StorageAsyncClient(new AzureBlobStorageBuilder() .url(endpoint) - .pipeline(pipeline); - } - - /** - * @return a {@link StorageClient} created from the configurations in this builder. - */ - public StorageClient buildClient() { - return new StorageClient(buildAsyncClient()); - } - - /** - * @return a {@link StorageAsyncClient} created from the configurations in this builder. - */ - public StorageAsyncClient buildAsyncClient() { - return new StorageAsyncClient(buildImpl()); + .pipeline(pipeline) + .build()); } /** From afd086742e55dd2ce3b01ee7f843dd48882aa10b Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 18 Jul 2019 12:50:26 -0700 Subject: [PATCH 8/9] Updating unit tests --- .../storage/blob/AccountSASPermission.java | 2 +- .../storage/blob/AccountSASResourceType.java | 2 +- .../azure/storage/blob/AccountSASService.java | 2 +- .../storage/blob/AppendBlobAsyncClient.java | 8 ++-- .../azure/storage/blob/BlobAsyncClient.java | 47 +++++++++++++------ .../com/azure/storage/blob/BlobClient.java | 30 ++++++++---- .../azure/storage/blob/BlobClientBuilder.java | 6 ++- .../azure/storage/blob/BlobSASPermission.java | 2 +- .../storage/blob/BlockBlobAsyncClient.java | 8 ++-- .../storage/blob/ContainerAsyncClient.java | 12 +++-- .../storage/blob/ContainerSASPermission.java | 2 +- .../storage/blob/PageBlobAsyncClient.java | 8 ++-- .../storage/blob/StorageAsyncClient.java | 3 +- .../java/com/azure/storage/blob/Utility.java | 2 +- .../com/azure/storage/blob/BlobAPITest.groovy | 24 +++------- .../storage/blob/ContainerAPITest.groovy | 2 +- .../azure/storage/blob/PageBlobAPITest.groovy | 16 +++---- .../com/azure/storage/blob/SASTest.groovy | 38 +++++++-------- 18 files changed, 121 insertions(+), 93 deletions(-) diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASPermission.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASPermission.java index 11369aabed0d7..87ef5998c7252 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASPermission.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASPermission.java @@ -33,7 +33,7 @@ final class AccountSASPermission { /** * Initializes an {@code AccountSASPermission} object with all fields set to false. */ - private AccountSASPermission() { + public AccountSASPermission() { } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASResourceType.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASResourceType.java index 6fc53c1902937..a1b47dc4f7372 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASResourceType.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASResourceType.java @@ -23,7 +23,7 @@ final class AccountSASResourceType { /** * Initializes an {@code AccountSASResourceType} object with all fields set to false. */ - private AccountSASResourceType() { + public AccountSASResourceType() { } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASService.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASService.java index 0f88ccb2203a9..359085fb13084 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASService.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AccountSASService.java @@ -25,7 +25,7 @@ final class AccountSASService { /** * Initializes an {@code AccountSASService} object with all fields set to false. */ - private AccountSASService() { + public AccountSASService() { } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index 7275f0fb326fe..2c0fce313e531 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -6,7 +6,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.AppendBlobAccessConditions; import com.azure.storage.blob.models.AppendBlobItem; import com.azure.storage.blob.models.BlobAccessConditions; @@ -59,10 +59,10 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + AppendBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index c8ceb3f311d3f..0399d06f06bfe 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -82,10 +82,10 @@ public class BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. * - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - this.azureBlobStorage = azureBlobStorageBuilder.build(); + BlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + this.azureBlobStorage = azureBlobStorage; this.snapshot = snapshot; } @@ -98,7 +98,8 @@ public class BlobAsyncClient { public BlockBlobAsyncClient asBlockBlobAsyncClient() { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -110,7 +111,8 @@ public BlockBlobAsyncClient asBlockBlobAsyncClient() { public AppendBlobAsyncClient asAppendBlobAsyncClient() { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -122,7 +124,21 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() { public PageBlobAsyncClient asPageBlobAsyncClient() { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(getBlobUrl().toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); + } + + /** + * Creates a new {@link BlobAsyncClient} linked to the {@code snapshot} of this blob resource. + * + * @param snapshot the identifier for a specific snapshot of this blob + * @return a {@link BlobAsyncClient} used to interact with the specific snapshot. + */ + public BlobAsyncClient getSnapshotClient(String snapshot) { + return new BlobAsyncClient(new AzureBlobStorageBuilder() + .url(getBlobUrl().toString()) + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -136,7 +152,8 @@ public ContainerAsyncClient getContainerAsyncClient() { BlobURLParts parts = URLParser.parse(getBlobUrl()); return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(String.format("%s://%s/%s", parts.scheme(), parts.host(), parts.containerName())) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline()) + .build()); } /** @@ -555,22 +572,24 @@ public Mono setMetadata(Metadata metadata, BlobAccessConditions ac } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * - * @return A reactive response containing the ID of the new snapshot. + * @return A response containing a {@link BlobAsyncClient} which is used to interact with the created snapshot, use + * {@link BlobAsyncClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Mono> createSnapshot() { + public Mono> createSnapshot() { return this.createSnapshot(null, null); } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * * @param metadata {@link Metadata} * @param accessConditions {@link BlobAccessConditions} - * @return A reactive response containing the ID of the new snapshot. + * @return A response containing a {@link BlobAsyncClient} which is used to interact with the created snapshot, use + * {@link BlobAsyncClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { + public Mono> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions) { metadata = metadata == null ? new Metadata() : metadata; accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions; @@ -578,7 +597,7 @@ public Mono> createSnapshot(Metadata metadata, BlobAccessCondit null, null, null, metadata, null, null, null, null, accessConditions.modifiedAccessConditions(), accessConditions.leaseAccessConditions(), Context.NONE)) - .map(rb -> new SimpleResponse<>(rb, rb.deserializedHeaders().snapshot())); + .map(rb -> new SimpleResponse<>(rb, this.getSnapshotClient(rb.deserializedHeaders().snapshot()))); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java index e2c6eab47a768..fe2f68a2e3610 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClient.java @@ -4,6 +4,7 @@ package com.azure.storage.blob; import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; import com.azure.core.http.rest.VoidResponse; import com.azure.storage.blob.models.AccessTier; import com.azure.storage.blob.models.BlobAccessConditions; @@ -88,6 +89,16 @@ public PageBlobClient asPageBlobClient() { return new PageBlobClient(blobAsyncClient.asPageBlobAsyncClient()); } + /** + * Creates a new {@link BlobClient} linked to the {@code snapshot} of this blob resource. + * + * @param snapshot the identifier for a specific snapshot of this blob + * @return a {@link BlobClient} used to interact with the specific snapshot. + */ + public BlobClient getSnapshotClient(String snapshot) { + return new BlobClient(blobAsyncClient.getSnapshotClient(snapshot)); + } + /** * Initializes a {@link ContainerClient} object pointing to the container this blob is in. This method does not * create a container. It simply constructs the URL to the container and offers access to methods relevant to @@ -440,25 +451,28 @@ public VoidResponse setMetadata(Metadata metadata, BlobAccessConditions accessCo } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * - * @return The ID of the new snapshot. + * @return A response containing a {@link BlobClient} which is used to interact with the created snapshot, use + * {@link BlobClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Response createSnapshot() { + public Response createSnapshot() { return this.createSnapshot(null, null, null); } /** - * Creates a read-only snapshot of a blob. + * Creates a read-only snapshot of the blob. * * @param metadata {@link Metadata} * @param accessConditions {@link BlobAccessConditions} * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. - * @return The ID of the new snapshot. + * @return A response containing a {@link BlobClient} which is used to interact with the created snapshot, use + * {@link BlobClient#getSnapshotId()} to get the identifier for the snapshot. */ - public Response createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { - Mono> response = blobAsyncClient - .createSnapshot(metadata, accessConditions); + public Response createSnapshot(Metadata metadata, BlobAccessConditions accessConditions, Duration timeout) { + Mono> response = blobAsyncClient + .createSnapshot(metadata, accessConditions) + .map(rb -> new SimpleResponse<>(rb, new BlobClient(rb.value()))); return Utility.blockWithOptionalTimeout(response, timeout); } diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java index f913fea852bbb..cbe71c6311587 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobClientBuilder.java @@ -17,6 +17,7 @@ import com.azure.core.util.configuration.Configuration; import com.azure.core.util.configuration.ConfigurationManager; import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.common.credentials.SASTokenCredential; import com.azure.storage.common.credentials.SharedKeyCredential; import com.azure.storage.common.policy.RequestRetryOptions; @@ -87,7 +88,7 @@ public BlobClientBuilder() { policies = new ArrayList<>(); } - private AzureBlobStorageBuilder buildImpl() { + private AzureBlobStorageImpl buildImpl() { Objects.requireNonNull(endpoint); Objects.requireNonNull(containerName); Objects.requireNonNull(blobName); @@ -124,7 +125,8 @@ private AzureBlobStorageBuilder buildImpl() { return new AzureBlobStorageBuilder() .url(String.format("%s/%s/%s", endpoint, containerName, blobName)) - .pipeline(pipeline); + .pipeline(pipeline) + .build(); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobSASPermission.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobSASPermission.java index 6dd79f092ecd3..6c8843a140bd8 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlobSASPermission.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlobSASPermission.java @@ -27,7 +27,7 @@ final class BlobSASPermission { /** * Initializes a {@code BlobSASPermission} object with all fields set to false. */ - private BlobSASPermission() { + public BlobSASPermission() { } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java index cdb0a06fa68e2..ee881859a32e4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/BlockBlobAsyncClient.java @@ -9,7 +9,7 @@ import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.util.FluxUtil; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; import com.azure.storage.blob.models.BlobRange; @@ -85,10 +85,10 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + BlockBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java index 47e8207403f00..af6ab175020df 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerAsyncClient.java @@ -107,7 +107,8 @@ public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName) { public BlockBlobAsyncClient getBlockBlobAsyncClient(String blobName, String snapshot) { return new BlockBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -140,7 +141,8 @@ public PageBlobAsyncClient getPageBlobAsyncClient(String blobName) { public PageBlobAsyncClient getPageBlobAsyncClient(String blobName, String snapshot) { return new PageBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -173,7 +175,8 @@ public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName) { public AppendBlobAsyncClient getAppendBlobAsyncClient(String blobName, String snapshot) { return new AppendBlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** @@ -202,7 +205,8 @@ public BlobAsyncClient getBlobAsyncClient(String blobName) { public BlobAsyncClient getBlobAsyncClient(String blobName, String snapshot) { return new BlobAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getContainerUrl(), blobName).toString()) - .pipeline(azureBlobStorage.httpPipeline()), snapshot); + .pipeline(azureBlobStorage.httpPipeline()) + .build(), snapshot); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerSASPermission.java b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerSASPermission.java index 0ac5e0f6738a3..e92d5d8239840 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerSASPermission.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/ContainerSASPermission.java @@ -29,7 +29,7 @@ final class ContainerSASPermission { /** * Initializes an {@code ContainerSASPermssion} object with all fields set to false. */ - private ContainerSASPermission() { + public ContainerSASPermission() { } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index 925f167b2ad91..4c9c5b9ab9ada 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -7,7 +7,7 @@ import com.azure.core.http.rest.SimpleResponse; import com.azure.core.implementation.http.UrlBuilder; import com.azure.core.util.Context; -import com.azure.storage.blob.implementation.AzureBlobStorageBuilder; +import com.azure.storage.blob.implementation.AzureBlobStorageImpl; import com.azure.storage.blob.models.BlobAccessConditions; import com.azure.storage.blob.models.BlobHTTPHeaders; import com.azure.storage.blob.models.BlobRange; @@ -64,10 +64,10 @@ public final class PageBlobAsyncClient extends BlobAsyncClient { /** * Package-private constructor for use by {@link BlobClientBuilder}. - * @param azureBlobStorageBuilder the API client builder for blob storage API + * @param azureBlobStorage the API client for blob storage */ - PageBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) { - super(azureBlobStorageBuilder, snapshot); + PageBlobAsyncClient(AzureBlobStorageImpl azureBlobStorage, String snapshot) { + super(azureBlobStorage, snapshot); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java index 5203875eb93d3..61ba6ed5861b4 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/StorageAsyncClient.java @@ -73,7 +73,8 @@ public final class StorageAsyncClient { public ContainerAsyncClient getContainerAsyncClient(String containerName) { return new ContainerAsyncClient(new AzureBlobStorageBuilder() .url(Utility.appendToURLPath(getAccountUrl(), containerName).toString()) - .pipeline(azureBlobStorage.httpPipeline())); + .pipeline(azureBlobStorage.httpPipeline()) + .build()); } /** diff --git a/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java b/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java index 252a5e83bbaf2..d22c2fc6dde21 100644 --- a/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java +++ b/storage/client/blob/src/main/java/com/azure/storage/blob/Utility.java @@ -371,7 +371,7 @@ static URL appendToURLPath(URL baseURL, String name) { static URL stripLastPathSegment(URL baseURL) { UrlBuilder url = UrlBuilder.parse(baseURL); - if (url.path() != null || !url.path().contains("/")) { + if (url.path() == null || !url.path().contains("/")) { throw new IllegalArgumentException(String.format("URL %s does not contain path segments", baseURL)); } diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy index d0be4d532642a..6c8bbcb20fb13 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy @@ -7,6 +7,7 @@ import com.azure.core.http.HttpHeaders import com.azure.core.http.rest.Response import com.azure.core.http.rest.VoidResponse import com.azure.core.implementation.util.ImplUtils +import com.azure.storage.blob.BlobProperties import com.azure.storage.blob.models.* import spock.lang.Unroll @@ -231,16 +232,11 @@ class BlobAPITest extends APISpec { ByteArrayOutputStream originalStream = new ByteArrayOutputStream() bu.download(originalStream) - String snapshot = bu.createSnapshot().value() BlockBlobClient bu2 = bu.asBlockBlobClient() bu2.upload(new ByteArrayInputStream("ABC".getBytes()), 3) then: - BlobClient bu3 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .snapshot(snapshot) - .credential(primaryCreds) - .buildBlobClient() + BlobClient bu3 = bu.createSnapshot().value() ByteArrayOutputStream snapshotStream = new ByteArrayOutputStream() bu3.download(snapshotStream) snapshotStream.toByteArray() == originalStream.toByteArray() @@ -981,12 +977,8 @@ class BlobAPITest extends APISpec { def "Snapshot"() { when: - Response snapshotResponse = bu.createSnapshot() - BlobClient bu2 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .credential(primaryCreds) - .snapshot(snapshotResponse.value()) - .buildBlobClient() + Response snapshotResponse = bu.createSnapshot() + BlobClient bu2 = snapshotResponse.value() then: bu2.getProperties().statusCode() == 200 @@ -1009,12 +1001,8 @@ class BlobAPITest extends APISpec { metadata.put(key2, value2) } - Response response = bu.createSnapshot(metadata, null, null) - BlobClient bu2 = new BlobClientBuilder() - .endpoint(bu.getBlobUrl().toString()) - .credential(primaryCreds) - .snapshot(response.value()) - .buildBlobClient() + Response response = bu.createSnapshot(metadata, null, null) + BlobClient bu2 = response.value() expect: response.statusCode() == 201 diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy index 86da9838d53bb..42bd73945f717 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy @@ -618,7 +618,7 @@ class ContainerAPITest extends APISpec { values.put("foo", "bar") metadataBlob.create(512, null, null, values, null, null) - String snapshotTime = normal.createSnapshot().value() + String snapshotTime = normal.createSnapshot().value().getSnapshotId() BlockBlobClient uncommittedBlob = cu.getBlockBlobClient(uncommittedName) diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy index eee346b007288..c1cb2100bd34f 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/PageBlobAPITest.groovy @@ -723,7 +723,7 @@ class PageBlobAPITest extends APISpec { def "Get page ranges diff min"() { setup: - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() when: bu.getPageRangesDiff(null, snapshot).iterator().hasNext() @@ -735,7 +735,7 @@ class PageBlobAPITest extends APISpec { @Unroll def "Get page ranges diff AC"() { setup: - String snapshot = bu.createSnapshot(null, null, null).value() + String snapshot = bu.createSnapshot().value().getSnapshotId() BlobAccessConditions bac = new BlobAccessConditions() .leaseAccessConditions(new LeaseAccessConditions().leaseId(setupBlobLeaseCondition(bu, leaseID))) .modifiedAccessConditions(new ModifiedAccessConditions() @@ -984,7 +984,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() Response copyResponse = bu2.copyIncremental(bu.getBlobUrl(), snapshot) String status = copyResponse.value().toString() @@ -1012,7 +1012,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() expect: bu2.copyIncremental(bu.getBlobUrl(), snapshot).statusCode() == 202 @@ -1023,7 +1023,7 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() Response copyResponse = bu2.copyIncremental(bu.getBlobUrl(), snapshot) String status = copyResponse.value().toString() @@ -1038,7 +1038,7 @@ class PageBlobAPITest extends APISpec { sleep(1000) } - snapshot = bu.createSnapshot().value() + snapshot = bu.createSnapshot().value().getSnapshotId() match = setupBlobMatchCondition(bu2, match) def mac = new ModifiedAccessConditions() .ifModifiedSince(modified) @@ -1063,9 +1063,9 @@ class PageBlobAPITest extends APISpec { setup: cu.setAccessPolicy(PublicAccessType.BLOB, null) PageBlobClient bu2 = cu.getPageBlobClient(generateBlobName()) - String snapshot = bu.createSnapshot().value() + String snapshot = bu.createSnapshot().value().getSnapshotId() bu2.copyIncremental(bu.getBlobUrl(), snapshot) - snapshot = bu.createSnapshot().value() + snapshot = bu.createSnapshot().value().getSnapshotId() noneMatch = setupBlobMatchCondition(bu2, noneMatch) def mac = new ModifiedAccessConditions() .ifModifiedSince(modified) diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy index 1ebf9860f2ac3..e80449a80ce33 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/SASTest.groovy @@ -80,7 +80,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + def snapshotId = bu.createSnapshot().value().getSnapshotId() when: def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -96,7 +96,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + def snapshotId = bu.createSnapshot().value().getSnapshotId() when: def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -135,12 +135,12 @@ class SASTest extends APISpec { when: def sas = bu.generateSAS(null, permissions, expiryTime, startTime, null, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType) - def builder = new BlockBlobClientBuilder() + def builder = new BlobClientBuilder() builder.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client = builder.buildClient() + def client = builder.buildBlockBlobClient() def os = new ByteArrayOutputStream() client.download(os) @@ -162,7 +162,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + String snapshotId = bu.createSnapshot().value().getSnapshotId() def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) @@ -187,13 +187,13 @@ class SASTest extends APISpec { when: def sas = snapshotBlob.generateSAS(null, permissions, expiryTime, startTime, null, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType) - def builder = new BlockBlobClientBuilder() + def builder = new BlobClientBuilder() builder.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .snapshot(snapshotId) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client = builder.buildClient() + def client = builder.buildBlockBlobClient() def os = new ByteArrayOutputStream() client.download(os) @@ -279,12 +279,12 @@ class SASTest extends APISpec { def sas = bu.generateUserDelegationSAS(key, cu.getContainerUrl().getHost().split("\\.")[0], permissions, expiryTime, startTime, null, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType) - def builder = new BlockBlobClientBuilder() + def builder = new BlobClientBuilder() builder.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client = builder.buildClient() + def client = builder.buildBlockBlobClient() def os = new ByteArrayOutputStream() client.download(os) @@ -305,7 +305,7 @@ class SASTest extends APISpec { def blobName = generateBlobName() def bu = cu.getBlockBlobClient(blobName) bu.upload(new ByteArrayInputStream(data), data.length) - def snapshotId = bu.createSnapshot().value() + def snapshotId = bu.createSnapshot().value().getSnapshotId() def snapshotBlob = cu.getBlockBlobClient(blobName, snapshotId) def permissions = new BlobSASPermission() @@ -333,12 +333,12 @@ class SASTest extends APISpec { def sas = snapshotBlob.generateUserDelegationSAS(key, cu.getContainerUrl().getHost().split("\\.")[0], permissions, expiryTime, startTime, null, sasProtocol, ipRange, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType) // base blob with snapshot SAS - def builder1 = new BlockBlobClientBuilder() + def builder1 = new BlobClientBuilder() builder1.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client1 = builder1.buildClient() + def client1 = builder1.buildBlockBlobClient() client1.download(new ByteArrayOutputStream()) then: @@ -348,13 +348,13 @@ class SASTest extends APISpec { when: // blob snapshot with snapshot SAS - def builder2 = new BlockBlobClientBuilder() + def builder2 = new BlobClientBuilder() builder2.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .snapshot(snapshotId) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client2 = builder2.buildClient() + def client2 = builder2.buildBlockBlobClient() def os = new ByteArrayOutputStream() client2.download(os) @@ -363,7 +363,7 @@ class SASTest extends APISpec { os.toString() == new String(data) and: - def properties = client2.getProperties(null, null).value() + def properties = client2.getProperties().value() then: properties.cacheControl() == "cache" @@ -420,12 +420,12 @@ class SASTest extends APISpec { when: def sas = primaryServiceURL.generateAccountSAS(service, resourceType, permissions, expiryTime, null, null, null, null) - def builder = new BlockBlobClientBuilder() + def builder = new BlobClientBuilder() builder.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client = builder.buildClient() + def client = builder.buildBlockBlobClient() def os = new ByteArrayOutputStream() client.download(os) @@ -454,12 +454,12 @@ class SASTest extends APISpec { when: def sas = primaryServiceURL.generateAccountSAS(service, resourceType, permissions, expiryTime, null, null, null, null) - def builder = new BlockBlobClientBuilder() + def builder = new BlobClientBuilder() builder.endpoint(cu.getContainerUrl().toString()) .blobName(blobName) .credential(new SASTokenCredential(sas)) .httpClient(getHttpClient()) - def client = builder.buildClient() + def client = builder.buildBlockBlobClient() client.delete() then: From 97318d0c0c5adcc05f8306e7cfaeaf439a8340d7 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 18 Jul 2019 13:00:33 -0700 Subject: [PATCH 9/9] Fix a snapshot test --- .../src/test/java/com/azure/storage/blob/BlobAPITest.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy index 6c8bbcb20fb13..8fe6954745437 100644 --- a/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy +++ b/storage/client/blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy @@ -233,10 +233,10 @@ class BlobAPITest extends APISpec { bu.download(originalStream) BlockBlobClient bu2 = bu.asBlockBlobClient() + BlobClient bu3 = bu.createSnapshot().value() bu2.upload(new ByteArrayInputStream("ABC".getBytes()), 3) then: - BlobClient bu3 = bu.createSnapshot().value() ByteArrayOutputStream snapshotStream = new ByteArrayOutputStream() bu3.download(snapshotStream) snapshotStream.toByteArray() == originalStream.toByteArray()