Skip to content

Commit

Permalink
all changes ready
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Jul 12, 2019
1 parent 4174146 commit fae3cad
Show file tree
Hide file tree
Showing 140 changed files with 2,028 additions and 2,065 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
<Match>
<Or>
<Package name="com.microsoft.azure.storage.blob"/>
<Package name="com.azure.storage.file.models"/>
<Class name="com.azure.storage.blob.HTTPGetterInfo"/>
</Or>
<Bug pattern="NM_CONFUSING"/>
Expand Down
14 changes: 0 additions & 14 deletions storage/client/file/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
<tag>HEAD</tag>
</scm>

<pluginRepositories>
<pluginRepository>
<id>bintray</id>
<name>Groovy Bintray</name>
<url>https://dl.bintray.com/groovy/maven</url>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public final class SharedKeyCredential {
private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKey %s:%s";

// Pieces of the connection string that are needed.
private static final String ACCOUNT_NAME = "AccountName".toLowerCase();
private static final String ACCOUNT_KEY = "AccountKey".toLowerCase();
private static final String ACCOUNT_NAME = "accountname";
private static final String ACCOUNT_KEY = "accountkey";

private final String accountName;
private final byte[] accountKey;
Expand Down Expand Up @@ -59,7 +59,7 @@ public static SharedKeyCredential fromConnectionString(String connectionString)
HashMap<String, String> connectionStringPieces = new HashMap<>();
for (String connectionStringPiece : connectionString.split(";")) {
String[] kvp = connectionStringPiece.split("=", 2);
connectionStringPieces.put(kvp[0].toLowerCase(), kvp[1]);
connectionStringPieces.put(kvp[0].toLowerCase(Locale.ROOT), kvp[1]);
}

String accountName = connectionStringPieces.get(ACCOUNT_NAME);
Expand Down Expand Up @@ -98,9 +98,13 @@ public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map
*
* @param stringToSign The UTF-8-encoded string to sign.
* @return A {@code String} that contains the HMAC-SHA256-encoded signature.
* @throws InvalidKeyException If the accountKey is not a valid Base64-encoded string.
* @throws RuntimeException for one of the following cases:
* <ul>
* <li> If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate. </li>
* <li> If the an invalid key has been given to the client. </li>
* </ul>
*/
public String computeHmac256(final String stringToSign) throws InvalidKeyException {
public String computeHmac256(final String stringToSign) {
try {
/*
We must get a new instance of the Mac calculator for each signature calculated because the instances are
Expand All @@ -111,8 +115,10 @@ public String computeHmac256(final String stringToSign) throws InvalidKeyExcepti
hmacSha256.init(new SecretKeySpec(this.accountKey, "HmacSHA256"));
byte[] utf8Bytes = stringToSign.getBytes(StandardCharsets.UTF_8);
return Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes));
} catch (final NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (final NoSuchAlgorithmException e) {
throw new RuntimeException("There is no such algorithm. Error Details: " + e.getMessage());
} catch (InvalidKeyException e) {
throw new RuntimeException("Please double check the account key. Error details: " + e.getMessage());
}
}

Expand All @@ -121,20 +127,20 @@ private String buildStringToSign(URL requestURL, String httpMethod, Map<String,
contentLength = contentLength.equals("0") ? "" : contentLength;

// If the x-ms-header exists ignore the Date header
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : getStandardHeaderValue(headers,"Date");
String dateHeader = (headers.containsKey("x-ms-date")) ? "" : getStandardHeaderValue(headers, "Date");

return String.join("\n",
httpMethod,
getStandardHeaderValue(headers,"Content-Encoding"),
getStandardHeaderValue(headers,"Content-Language"),
getStandardHeaderValue(headers, "Content-Encoding"),
getStandardHeaderValue(headers, "Content-Language"),
contentLength,
getStandardHeaderValue(headers,"Content-MD5"),
getStandardHeaderValue(headers,"Content-Type"),
getStandardHeaderValue(headers, "Content-MD5"),
getStandardHeaderValue(headers, "Content-Type"),
dateHeader,
getStandardHeaderValue(headers,"If-Modified-Since"),
getStandardHeaderValue(headers,"If-Match"),
getStandardHeaderValue(headers, "If-Modified-Since"),
getStandardHeaderValue(headers, "If-Match"),
getStandardHeaderValue(headers, "If-None-Match"),
getStandardHeaderValue(headers,"If-Unmodified-Since"),
getStandardHeaderValue(headers, "If-Unmodified-Since"),
getStandardHeaderValue(headers, "Range"),
getAdditionalXmsHeaders(headers),
getCanonicalizedResource(requestURL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public RequestRetryOptions() {
* <p><strong>Sample Code</strong></p>
*
* <p>For more samples, please see the <a href="https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java">samples file</a></p>
* @throws IllegalArgumentException If one of the following case exists:
* <ul>
* <li> There is only one null value for retryDelay and maxRetryDelay.<li/>
* <li> Unrecognized retry policy type.<li/>
* </ul>
*/
public RequestRetryOptions(RetryPolicyType retryPolicyType, Integer maxTries, Integer tryTimeout,
Long retryDelayInMs, Long maxRetryDelayInMs, String secondaryHost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
public final class RequestRetryPolicy implements HttpPipelinePolicy {
private final RequestRetryOptions requestRetryOptions;

/**
* Constructs the policy using the retry options.
*
* @param requestRetryOptions Retry options for the policy.
*/
public RequestRetryPolicy(RequestRetryOptions requestRetryOptions) {
this.requestRetryOptions = requestRetryOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ public FileAsyncClient getFileClient(String fileName) {
* <p>If the file doesn't exist in the storage account {@link DirectoryAsyncClient#create()} create} in the client will
* need to be called before interaction with the directory can happen.</p>
*
* @param directoryName Name of the directory
* @param subDirectoryName Name of the directory
* @return a DirectoryAsyncClient that interacts with the specified directory
*/
public DirectoryAsyncClient getSubDirectoryClient(String directoryName) {
return new DirectoryAsyncClient(azureFileStorageClient, shareName, directoryName, shareSnapshot);
public DirectoryAsyncClient getSubDirectoryClient(String subDirectoryName) {
String directoryPath = directoryName + "/" + subDirectoryName;
return new DirectoryAsyncClient(azureFileStorageClient, shareName, directoryPath, shareSnapshot);
}

/**
Expand Down Expand Up @@ -165,7 +166,7 @@ public Mono<Response<DirectoryInfo>> create() {
* @throws StorageErrorException If the directory has already existed, the parent directory does not exist or directory name is an invalid resource name.
*/
public Mono<Response<DirectoryInfo>> create(Map<String, String> metadata) {
return azureFileStorageClient.directorys().createWithRestResponseAsync(shareName, directoryName,null, metadata, Context.NONE)
return azureFileStorageClient.directorys().createWithRestResponseAsync(shareName, directoryName, null, metadata, Context.NONE)
.map(this::createWithRestResponse);
}

Expand All @@ -182,7 +183,7 @@ public Mono<Response<DirectoryInfo>> create(Map<String, String> metadata) {
* @throws StorageErrorException If the share doesn't exist
*/
public Mono<VoidResponse> delete() {
return azureFileStorageClient.directorys().deleteWithRestResponseAsync(shareName, directoryName, Context.NONE).map(VoidResponse::new)
return azureFileStorageClient.directorys().deleteWithRestResponseAsync(shareName, directoryName, Context.NONE).map(VoidResponse::new)
.map(VoidResponse::new);
}

Expand Down Expand Up @@ -480,11 +481,11 @@ private Flux<FileRef> nextPageForFileAndDirecotries(final DirectorysListFilesAnd
return Flux.fromIterable(fileRefs);
}
Mono<DirectorysListFilesAndDirectoriesSegmentResponse> listResponse = azureFileStorageClient.directorys().listFilesAndDirectoriesSegmentWithRestResponseAsync(shareName, directoryName, prefix, shareSnapshot, response.value().nextMarker(), maxResult, null, Context.NONE);
Flux<FileRef> fileRefPublisher = listResponse.flatMapMany(newResponse ->nextPageForFileAndDirecotries(newResponse, prefix, maxResult));
Flux<FileRef> fileRefPublisher = listResponse.flatMapMany(newResponse -> nextPageForFileAndDirecotries(newResponse, prefix, maxResult));
return Flux.fromIterable(fileRefs).concatWith(fileRefPublisher);
}

private Flux<HandleItem> nextPageForHandles (DirectorysListHandlesResponse response, Integer maxResult, boolean recursive) {
private Flux<HandleItem> nextPageForHandles(DirectorysListHandlesResponse response, Integer maxResult, boolean recursive) {
List<HandleItem> handleItems = response.value().handleList();

if (response.value().nextMarker() == null) {
Expand All @@ -506,7 +507,7 @@ private Flux<Integer> nextPageForForceCloseHandles(DirectorysForceCloseHandlesRe
return Flux.fromIterable(handleCount).concatWith(fileRefPublisher);
}

private List<FileRef> convertResponseAndGetNumOfResults(DirectorysListFilesAndDirectoriesSegmentResponse response){
private List<FileRef> convertResponseAndGetNumOfResults(DirectorysListFilesAndDirectoriesSegmentResponse response) {
List<FileRef> fileRefs = new ArrayList<>();
response.value().segment().directoryItems().forEach(directoryItem -> fileRefs.add(new FileRef(directoryItem.name(), true, null)));
response.value().segment().fileItems().forEach(fileItem -> fileRefs.add(new FileRef(fileItem.name(), false, fileItem.properties())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class DirectoryClient {

public final DirectoryAsyncClient directoryAsyncClient;
private final DirectoryAsyncClient directoryAsyncClient;

/**
* Creates a DirectoryClient that wraps a DirectoryAsyncClient and blocks requests.
Expand Down Expand Up @@ -78,11 +78,11 @@ public FileClient getFileClient(String fileName) {
* <p>If the file doesn't exist in the storage account {@link DirectoryClient#create()} create} in the client will
* need to be called before interaction with the directory can happen.</p>
*
* @param directoryName Name of the directory
* @param subDirectoryName Name of the directory
* @return a DirectoryClient that interacts with the specified directory
*/
public DirectoryClient getSubDirectoryClient(String directoryName) {
return new DirectoryClient(directoryAsyncClient.getSubDirectoryClient(directoryName));
public DirectoryClient getSubDirectoryClient(String subDirectoryName) {
return new DirectoryClient(directoryAsyncClient.getSubDirectoryClient(subDirectoryName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -76,7 +77,7 @@
* @see SharedKeyCredential
*/
public class DirectoryClientBuilder {
private static final String ACCOUNT_NAME = "AccountName".toLowerCase();
private static final String ACCOUNT_NAME = "accountname";
private final List<HttpPipelinePolicy> policies;
private final RetryPolicy retryPolicy;

Expand Down Expand Up @@ -115,11 +116,15 @@ public DirectoryClientBuilder() {
*
* @return A ShareAsyncClient with the options set from the builder.
* @throws NullPointerException If {@code endpoint} or {@code shareName} is {@code null}.
* @throws IllegalStateException If neither a {@link SharedKeyCredential} or {@link SASTokenCredential} has been set.
* @throws IllegalArgumentException If neither a {@link SharedKeyCredential} or {@link SASTokenCredential} has been set.
*/
public DirectoryAsyncClient buildAsyncClient() {
Objects.requireNonNull(endpoint);

if (pipeline != null) {
return new DirectoryAsyncClient(endpoint, pipeline, shareName, directoryName, shareSnapshot);
}

if (sasTokenCredential == null && sharedKeyCredential == null) {
throw new IllegalArgumentException("Credentials are required for authorization");
}
Expand Down Expand Up @@ -165,7 +170,7 @@ public DirectoryAsyncClient buildAsyncClient() {
*
* @return A DirectoryClient with the options set from the builder.
* @throws NullPointerException If {@code endpoint}, {@code shareName} or {@code directoryName} is {@code null}.
* @throws IllegalStateException If neither a {@link SharedKeyCredential} or {@link SASTokenCredential} has been set.
* @throws IllegalArgumentException If neither a {@link SharedKeyCredential} or {@link SASTokenCredential} has been set.
*/
public DirectoryClient buildClient() {
return new DirectoryClient(this.buildAsyncClient());
Expand Down Expand Up @@ -237,14 +242,14 @@ private void getEndPointFromConnectionString(String connectionString) {
Map<String, String> connectionStringPieces = new HashMap<>();
for (String connectionStringPiece : connectionString.split(";")) {
String[] kvp = connectionStringPiece.split("=", 2);
connectionStringPieces.put(kvp[0].toLowerCase(), kvp[1]);
connectionStringPieces.put(kvp[0].toLowerCase(Locale.ROOT), kvp[1]);
}
String accountName = connectionStringPieces.get(ACCOUNT_NAME);
try {
this.endpoint = new URL(String.format("https://%s.file.core.windows.net", accountName));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(String.format("There is no valid endpoint for the connection string. " +
"Connection String: %s", connectionString));
throw new IllegalArgumentException(String.format("There is no valid endpoint for the connection string. "
+ "Connection String: %s", connectionString));
}
}

Expand All @@ -255,7 +260,7 @@ private void getEndPointFromConnectionString(String connectionString) {
* @return the updated DirectoryClientBuilder object
* @throws NullPointerException If {@code shareName} is {@code null}.
*/
public DirectoryClientBuilder shareName (String shareName) {
public DirectoryClientBuilder shareName(String shareName) {
this.shareName = shareName;
return this;
}
Expand Down
Loading

0 comments on commit fae3cad

Please sign in to comment.