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

Azure Storage Common Package #4926

Merged
merged 5 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions pom.client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@
<module>./sdk/keyvault/azure-keyvault-keys</module>
<module>./sdk/tracing/tracing-opentelemetry</module>
<module>./sdk/identity/azure-identity</module>
<module>./sdk/storage/azure-storage-common</module>
<module>./sdk/storage/azure-storage-blob</module>
<module>./sdk/storage/azure-storage-file</module>
<module>./sdk/storage/azure-storage-queue</module>
Expand Down
5 changes: 5 additions & 0 deletions 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.4</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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

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;

/**
Expand Down Expand Up @@ -223,14 +226,7 @@ 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,
Expand All @@ -243,10 +239,10 @@ private String stringToSign(final SharedKeyCredential sharedKeyCredentials) {
AccountSASPermission.parse(this.permissions).toString(), // guarantees ordering
this.services,
resourceTypes,
this.startTime == null ? "" : Utility.ISO_8601_UTC_DATE_FORMATTER.format(this.startTime),
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 ? (new IPRange()).toString() : this.ipRange.toString(),
this.protocol == null ? "" : this.protocol.toString(),
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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +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;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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.Utility;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import reactor.core.publisher.Flux;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
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.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 io.netty.buffer.ByteBuf;
import reactor.core.publisher.Flux;
Expand All @@ -44,7 +48,7 @@
import java.util.ArrayList;
import java.util.List;

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

/**
* Client to a blob of any type: block, append, or page. It may only be instantiated through a {@link BlobClientBuilder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
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.IPRange;
import com.azure.storage.common.SASProtocol;
import com.azure.storage.common.Utility;
import reactor.core.publisher.Mono;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public BlobClientBuilder endpoint(String endpoint) {
this.blobName = parts.blobName();
this.snapshot = parts.snapshot();

this.sasTokenCredential = SASTokenCredential.fromQueryParameters(parts.sasQueryParameters());
this.sasTokenCredential = SASTokenCredential.fromSASTokenString(parts.sasQueryParameters().encode());
if (this.sasTokenCredential != null) {
this.tokenCredential = null;
this.sharedKeyCredential = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

class BlobConfiguration {
static final String NAME = "azure-storage-blob";
static final String VERSION = "12.0.0-preview.2";
static final String VERSION = "12.0.0-preview.3";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.azure.storage.blob.models.BlobAccessConditions;
import com.azure.storage.blob.models.BlobRange;
import com.azure.storage.common.Constants;
import reactor.netty.ByteBufFlux;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private Mono<Integer> dispatchWrite(Flux<ByteBuf> bufferRef, int writeLength, lo
return Mono.empty();
}

if (this.streamType == BlobType.PAGE_BLOB && (writeLength % Constants.PAGE_SIZE != 0)) {
if (this.streamType == BlobType.PAGE_BLOB && (writeLength % PageBlobAsyncClient.PAGE_BYTES != 0)) {
return Mono.error(new IOException(String.format(SR.INVALID_NUMBER_OF_BYTES_IN_THE_BUFFER, writeLength)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
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.IPRange;
import com.azure.storage.common.SASProtocol;
import com.azure.storage.common.Utility;
import com.azure.storage.common.credentials.SharedKeyCredential;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -29,7 +32,7 @@
import java.net.URL;
import java.time.OffsetDateTime;

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

/**
* Client to a storage account. It may only be instantiated through a {@link BlobServiceClientBuilder}. This class does not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
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.IPRange;
import com.azure.storage.common.SASProtocol;
import com.azure.storage.common.Utility;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public BlobServiceClientBuilder endpoint(String endpoint) {
URL url = new URL(endpoint);
this.endpoint = url.getProtocol() + "://" + url.getAuthority();

this.sasTokenCredential = SASTokenCredential.fromQueryParameters(URLParser.parse(url).sasQueryParameters());
this.sasTokenCredential = SASTokenCredential.fromSASTokenString(URLParser.parse(url).sasQueryParameters().encode());
if (this.sasTokenCredential != null) {
this.tokenCredential = null;
this.sharedKeyCredential = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package com.azure.storage.blob;

import com.azure.core.implementation.http.UrlBuilder;
import com.azure.storage.common.Constants;
import com.azure.storage.common.Utility;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -189,7 +191,7 @@ public URL toURL() throws MalformedURLException {
for (Map.Entry<String, String[]> entry : this.unparsedParameters.entrySet()) {
// The commas are intentionally encoded.
url.setQueryParameter(entry.getKey(),
Utility.safeURLEncode(String.join(",", entry.getValue())));
Utility.urlEncode(String.join(",", entry.getValue())));
}

return url.toURL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.azure.storage.blob.models.LeaseAccessConditions;
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;
Expand All @@ -39,7 +40,7 @@
import java.util.TreeMap;
import java.util.UUID;

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

/**
* Client to a block blob. It may only be instantiated through a {@link BlobClientBuilder}, via
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.azure.storage.blob.models.LeaseAccessConditions;
import com.azure.storage.blob.models.Metadata;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;
import com.azure.storage.common.Utility;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import reactor.core.publisher.Flux;
Expand Down
Loading