Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Storage Common Package and Misc Cleanup #4918

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,13 @@
<Class name="com.azure.storage.blob.ServiceSASSignatureValues"/>
<Bug pattern="UC_USELESS_CONDITION"/>
</Match>

<Match>
<Or>
<Class name="com.azure.storage.blob.models.StorageException"/>
<Class name="com.azure.storage.file.models.StorageException"/>
<Class name="com.azure.storage.queue.models.StorageException"/>
</Or>
<Bug pattern="SE_BAD_FIELD"/>
</Match>
</FindBugsFilter>
19 changes: 13 additions & 6 deletions eng/spotbugs-aggregate-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<azure-identity.version>1.0.0-preview.2</azure-identity.version>
<azure-keyvault.version>4.0.0-preview.1</azure-keyvault.version>
<azure-messaging-eventhubs.version>5.0.0-preview.2</azure-messaging-eventhubs.version>
<azure-storage-common.version>12.0.0-preview.3</azure-storage-common.version>
<azure-storage-blob.version>12.0.0-preview.2</azure-storage-blob.version>
<azure-storage-file.version>12.0.0-preview.2</azure-storage-file.version>
<azure-storage-queue.version>12.0.0-preview.2</azure-storage-queue.version>
Expand Down Expand Up @@ -69,12 +70,13 @@
<!-- <source>..\..\sdk\keyvault\azure-keyvault-keys\src\samples\java</source>-->
<!-- <source>..\..\sdk\keyvault\azure-keyvault-secrets\src\main\java</source>-->
<!-- <source>..\..\sdk\keyvault\azure-keyvault-secrets\src\samples\java</source>-->
<!-- <source>..\..\sdk\storage\client\blob\src\main\java</source>-->
<!-- <source>..\..\sdk\storage\client\blob\src\samples\java</source>-->
<!-- <source>..\..\sdk\storage\client\files\src\main\java</source>-->
<!-- <source>..\..\sdk\storage\client\files\src\samples\java</source>-->
<!-- <source>..\..\sdk\storage\client\queues\src\main\java</source>-->
<!-- <source>..\..\sdk\storage\client\queues\src\samples\java</source>-->
<source>..\..\sdk\storage\azure-storage-common\src\main\java</source>
<source>..\..\sdk\storage\azure-storage-blob\src\main\java</source>
<source>..\..\sdk\storage\azure-storage-blob\src\samples\java</source>
<source>..\..\sdk\storage\azure-storage-file\src\main\java</source>
<source>..\..\sdk\storage\azure-storage-file\src\samples\java</source>
<source>..\..\sdk\storage\azure-storage-queue\src\main\java</source>
<source>..\..\sdk\storage\azure-storage-queue\src\samples\java</source>
<!-- <source>..\..\sdk\tracing\azure-tracing-opentelemetry\src\main\java</source>-->
</sources>
</configuration>
Expand Down Expand Up @@ -181,6 +183,11 @@
<artifactId>azure-keyvault-secrets</artifactId>
<version>${azure-keyvault.version}</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-common</artifactId>
<version>${azure-storage-common.version}</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
Expand Down
1 change: 1 addition & 0 deletions pom.client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@
<module>./sdk/tracing/tracing-opentelemetry</module>
<module>./sdk/identity/azure-identity</module>
<module>./sdk/storage/azure-storage-blob</module>
<module>./sdk/storage/azure-storage-common</module>
<module>./sdk/storage/azure-storage-file</module>
<module>./sdk/storage/azure-storage-queue</module>
</modules>
Expand Down
7 changes: 6 additions & 1 deletion sdk/storage/azure-storage-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>azure-core</artifactId>
<version>1.0.0-preview.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-common</artifactId>
<version>12.0.0-preview.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -75,7 +80,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.0.0-preview.1</version>
<version>1.0.0-preview.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

package com.azure.storage.blob;

import com.azure.storage.common.Constants;
import com.azure.storage.common.IPRange;
import com.azure.storage.common.SASProtocol;
import com.azure.storage.common.Utility;
import com.azure.storage.common.credentials.SharedKeyCredential;

import java.security.InvalidKeyException;
import java.time.OffsetDateTime;

/**
* AccountSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage account. 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
* AccountSASSignatureValues is used to generate a Shared Access Signature (SAS) for an Azure Storage account. 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.
* <p>
* Please see
Expand Down Expand Up @@ -47,8 +50,8 @@ final class AccountSASSignatureValues {
private String resourceTypes;

/**
* Initializes an {@code AccountSASSignatureValues} object with the version number set to the default and all
* other values empty.
* Initializes an {@code AccountSASSignatureValues} object with the version number set to the default and all other
* values empty.
*/
AccountSASSignatureValues() {
}
Expand Down Expand Up @@ -208,9 +211,7 @@ public AccountSASSignatureValues resourceTypes(String resourceTypes) {
* Generates a {@link SASQueryParameters} object which contains all SAS query parameters needed to make an actual
* REST request.
*
* @param sharedKeyCredentials
* Credentials for the storage account and corresponding primary or secondary key.
*
* @param sharedKeyCredentials Credentials for the storage account and corresponding primary or secondary key.
* @return {@link SASQueryParameters}
* @throws RuntimeException If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate.
*/
Expand All @@ -223,32 +224,25 @@ public SASQueryParameters generateSASQueryParameters(SharedKeyCredential sharedK
Utility.assertNotNull("version", this.version);

// Signature is generated on the un-url-encoded values.
final String stringToSign = stringToSign(sharedKeyCredentials);

String signature;
try {
signature = sharedKeyCredentials.computeHmac256(stringToSign);
} catch (InvalidKeyException e) {
throw new RuntimeException(e); // The key should have been validated by now. If it is no longer valid here, we fail.
}
String signature = sharedKeyCredentials.computeHmac256(stringToSign(sharedKeyCredentials));

return new SASQueryParameters(this.version, this.services, resourceTypes,
this.protocol, this.startTime, this.expiryTime, this.ipRange, null,
null, this.permissions, signature, null, null, null, null, null, null);
this.protocol, this.startTime, this.expiryTime, this.ipRange, null,
null, this.permissions, signature, null, null, null, null, null, null);
}

private String stringToSign(final SharedKeyCredential sharedKeyCredentials) {
return String.join("\n",
sharedKeyCredentials.accountName(),
AccountSASPermission.parse(this.permissions).toString(), // guarantees ordering
this.services,
resourceTypes,
this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime),
Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime),
this.ipRange == null ? (new IPRange()).toString() : this.ipRange.toString(),
this.protocol == null ? "" : this.protocol.toString(),
this.version,
Constants.EMPTY_STRING // Account SAS requires an additional newline character
sharedKeyCredentials.accountName(),
AccountSASPermission.parse(this.permissions).toString(), // guarantees ordering
this.services,
resourceTypes,
this.startTime == null ? Constants.EMPTY_STRING : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime),
Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.expiryTime),
this.ipRange == null ? Constants.EMPTY_STRING : this.ipRange.toString(),
this.protocol == null ? Constants.EMPTY_STRING : this.protocol.toString(),
this.version,
Constants.EMPTY_STRING // Account SAS requires an additional newline character
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import com.azure.storage.blob.models.BlobRange;
import com.azure.storage.blob.models.Metadata;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;
import com.azure.storage.common.Constants;
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;

import static com.azure.storage.blob.PostProcessor.postProcessResponse;

/**
* Client to an append blob. It may only be instantiated through a {@link BlobClientBuilder#buildAppendBlobAsyncClient()},
Expand Down
Loading