Skip to content

Commit

Permalink
Merge pull request Azure#12 from alzimmermsft/AzStorage_Blobs_Verify_…
Browse files Browse the repository at this point in the history
…Tests

Fixing Feedback on PR
  • Loading branch information
alzimmermsft authored Jun 24, 2019
2 parents 6d9d6d4 + 04b53dc commit a91b6b4
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
package com.azure.storage.blob;

import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.ResponseBase;
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.AppendBlobAppendBlockFromUrlHeaders;
import com.azure.storage.blob.models.AppendBlobAppendBlockHeaders;
import com.azure.storage.blob.models.AppendBlobCreateHeaders;
import com.azure.storage.blob.models.AppendBlobItem;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;
Expand Down Expand Up @@ -46,7 +41,7 @@
* object through {@link Mono#toFuture()}.
*/
public final class AppendBlobAsyncClient extends BlobAsyncClient {
AppendBlobAsyncRawClient appendBlobAsyncRawClient;
private final AppendBlobAsyncRawClient appendBlobAsyncRawClient;

/**
* Indicates the maximum number of bytes that can be sent in a call to appendBlock.
Expand All @@ -63,7 +58,7 @@ public final class AppendBlobAsyncClient extends BlobAsyncClient {
* @param azureBlobStorageBuilder the API client builder for blob storage API
*/
AppendBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) {
super(azureBlobStorageBuilder);
super(azureBlobStorageBuilder, null);
appendBlobAsyncRawClient = new AppendBlobAsyncRawClient(azureBlobStorageBuilder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* <p><ul>
* <li>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}}.
* <li>the credential through {@code .credentials()} or {@code .connectionString()} if the container is not publicly accessible.
* <li>the credential through {@code .credential()} or {@code .connectionString()} if the container is not publicly accessible.
* </ul>
*
* <p>
Expand Down Expand Up @@ -180,40 +180,40 @@ public AppendBlobClientBuilder blobName(String blobName) {
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated AppendBlobClientBuilder object
*/
public AppendBlobClientBuilder credentials(SharedKeyCredential credentials) {
this.sharedKeyCredential = credentials;
public AppendBlobClientBuilder credential(SharedKeyCredential credential) {
this.sharedKeyCredential = credential;
return this;
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated AppendBlobClientBuilder object
*/
public AppendBlobClientBuilder credentials(TokenCredential credentials) {
this.tokenCredential = credentials;
public AppendBlobClientBuilder credential(TokenCredential credential) {
this.tokenCredential = credential;
return this;
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated AppendBlobClientBuilder object
*/
public AppendBlobClientBuilder credentials(SASTokenCredential credentials) {
this.sasTokenCredential = credentials;
public AppendBlobClientBuilder credential(SASTokenCredential credential) {
this.sasTokenCredential = credential;
return this;
}

/**
* Clears the credentials used to authorize requests sent to the service
* Clears the credential used to authorize requests sent to the service
* @return the updated AppendBlobClientBuilder object
*/
public AppendBlobClientBuilder anonymousCredentials() {
public AppendBlobClientBuilder anonymousCredential() {
this.sharedKeyCredential = null;
this.tokenCredential = null;
return this;
Expand Down Expand Up @@ -248,7 +248,7 @@ public AppendBlobClientBuilder connectionString(String connectionString) {
}

// Use accountName and accountKey to get the SAS token using the credential class.
return credentials(new SharedKeyCredential(accountName, accountKey));
return credential(new SharedKeyCredential(accountName, accountKey));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,29 @@

import com.azure.core.http.HttpResponse;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.ResponseBase;
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.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.AccessTier;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.BlobStartCopyFromURLHeaders;
import com.azure.storage.blob.models.DeleteSnapshotsOptionType;
import com.azure.storage.blob.models.LeaseAccessConditions;
import com.azure.storage.blob.models.ModifiedAccessConditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.netty.ByteBufFlux;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.time.Duration;
Expand Down Expand Up @@ -71,14 +64,17 @@
public class BlobAsyncClient {
private static final long BLOB_DEFAULT_DOWNLOAD_BLOCK_SIZE = 4 * Constants.MB;

BlobAsyncRawClient blobAsyncRawClient;
private final BlobAsyncRawClient blobAsyncRawClient;

private final String snapshot;

/**
* Package-private constructor for use by {@link BlobClientBuilder}.
* @param azureBlobStorageBuilder the API client builder for blob storage API
*/
BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) {
blobAsyncRawClient = new BlobAsyncRawClient(azureBlobStorageBuilder.build());
BlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) {
this.blobAsyncRawClient = new BlobAsyncRawClient(azureBlobStorageBuilder.build());
this.snapshot = snapshot;
}

/**
Expand All @@ -99,7 +95,7 @@ public static BlobClientBuilder blobClientBuilder() {
* A {@link BlockBlobAsyncClient} to this resource.
*/
public BlockBlobAsyncClient asBlockBlobAsyncClient() {
return new BlockBlobAsyncClient(new AzureBlobStorageBuilder().url(getUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()));
return new BlockBlobAsyncClient(new AzureBlobStorageBuilder().url(getUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot);
}

/**
Expand All @@ -121,7 +117,7 @@ public AppendBlobAsyncClient asAppendBlobAsyncClient() {
* A {@link PageBlobAsyncClient} to this resource.
*/
public PageBlobAsyncClient asPageBlobAsyncClient() {
return new PageBlobAsyncClient(new AzureBlobStorageBuilder().url(getUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()));
return new PageBlobAsyncClient(new AzureBlobStorageBuilder().url(getUrl().toString()).pipeline(blobAsyncRawClient.azureBlobStorage.httpPipeline()), snapshot);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class BlobClient {

private BlobAsyncClient blobAsyncClient;
private final BlobAsyncClient blobAsyncClient;

/**
* Package-private constructor for use by {@link BlobClientBuilder}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* <p><ul>
* <li>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}}.
* <li>the credential through {@code .credentials()} or {@code .connectionString()} if the container is not publicly accessible.
* <li>the credential through {@code .credential()} or {@code .connectionString()} if the container is not publicly accessible.
* </ul>
*
* <p>
Expand All @@ -57,6 +57,7 @@ public final class BlobClientBuilder {
private URL endpoint;
private String containerName;
private String blobName;
private String snapshot;
private SharedKeyCredential sharedKeyCredential;
private TokenCredential tokenCredential;
private SASTokenCredential sasTokenCredential;
Expand Down Expand Up @@ -122,7 +123,7 @@ public BlobClient buildClient() {
* @return a {@link BlobAsyncClient} created from the configurations in this builder.
*/
public BlobAsyncClient buildAsyncClient() {
return new BlobAsyncClient(buildImpl());
return new BlobAsyncClient(buildImpl(), snapshot);
}

/**
Expand Down Expand Up @@ -180,40 +181,50 @@ public BlobClientBuilder blobName(String blobName) {
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the snapshot of the blob this client is connecting to.
* @param snapshot the snapshot identifier for the blob
* @return the updated BlobClientBuilder object
*/
public BlobClientBuilder credentials(SharedKeyCredential credentials) {
this.sharedKeyCredential = credentials;
public BlobClientBuilder snapshot(String snapshot) {
this.snapshot = snapshot;
return this;
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated BlobClientBuilder object
*/
public BlobClientBuilder credentials(TokenCredential credentials) {
this.tokenCredential = credentials;
public BlobClientBuilder credential(SharedKeyCredential credential) {
this.sharedKeyCredential = credential;
return this;
}

/**
* Sets the credentials used to authorize requests sent to the service
* @param credentials authorization credentials
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated BlobClientBuilder object
*/
public BlobClientBuilder credentials(SASTokenCredential credentials) {
this.sasTokenCredential = credentials;
public BlobClientBuilder credential(TokenCredential credential) {
this.tokenCredential = credential;
return this;
}

/**
* Clears the credentials used to authorize requests sent to the service
* Sets the credential used to authorize requests sent to the service
* @param credential authorization credential
* @return the updated BlobClientBuilder object
*/
public BlobClientBuilder anonymousCredentials() {
public BlobClientBuilder credential(SASTokenCredential credential) {
this.sasTokenCredential = credential;
return this;
}

/**
* Clears the credential used to authorize requests sent to the service
* @return the updated BlobClientBuilder object
*/
public BlobClientBuilder anonymousCredential() {
this.sharedKeyCredential = null;
this.tokenCredential = null;
return this;
Expand Down Expand Up @@ -248,7 +259,7 @@ public BlobClientBuilder connectionString(String connectionString) {
}

// Use accountName and accountKey to get the SAS token using the credential class.
return credentials(new SharedKeyCredential(accountName, accountKey));
return credential(new SharedKeyCredential(accountName, accountKey));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.ResponseBase;
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.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.BlockBlobItem;
import com.azure.storage.blob.models.BlockItem;
Expand All @@ -21,7 +19,6 @@
import io.netty.buffer.Unpooled;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.ByteBufFlux;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -65,7 +62,7 @@
public final class BlockBlobAsyncClient extends BlobAsyncClient {
static final long BLOB_DEFAULT_UPLOAD_BLOCK_SIZE = 4 * Constants.MB;

private BlockBlobAsyncRawClient blockBlobAsyncRawClient;
private final BlockBlobAsyncRawClient blockBlobAsyncRawClient;

/**
* Indicates the maximum number of bytes that can be sent in a call to upload.
Expand All @@ -86,9 +83,9 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient {
* Package-private constructor for use by {@link BlockBlobClientBuilder}.
* @param azureBlobStorageBuilder the API client builder for blob storage API
*/
BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder) {
super(azureBlobStorageBuilder);
blockBlobAsyncRawClient = new BlockBlobAsyncRawClient(azureBlobStorageBuilder.build());
BlockBlobAsyncClient(AzureBlobStorageBuilder azureBlobStorageBuilder, String snapshot) {
super(azureBlobStorageBuilder, snapshot);
this.blockBlobAsyncRawClient = new BlockBlobAsyncRawClient(azureBlobStorageBuilder.build());
}

/**
Expand All @@ -97,7 +94,7 @@ public final class BlockBlobAsyncClient extends BlobAsyncClient {
* @return
* A new {@link BlockBlobClientBuilder} instance.
*/
public static BlockBlobClientBuilder builder() {
public static BlockBlobClientBuilder blockBlobClientBuilder() {
return new BlockBlobClientBuilder();
}

Expand Down
Loading

0 comments on commit a91b6b4

Please sign in to comment.