Skip to content
Merged
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 @@ -3,6 +3,7 @@

package com.azure.storage.blob.batch;

import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
Expand Down Expand Up @@ -61,7 +62,7 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
* Content-Type will contain the boundary for each batch response. The expected format is:
* "Content-Type: multipart/mixed; boundary=batchresponse_66925647-d0cb-4109-b6d3-28efe3e1e5ed"
*/
String contentType = rawResponse.getHeaders().getValue(Constants.HeaderConstants.CONTENT_TYPE);
String contentType = rawResponse.getHeaders().getValue(HttpHeaderName.CONTENT_TYPE);

// Split on the boundary [ "multipart/mixed; boundary", "batchresponse_66925647-d0cb-4109-b6d3-28efe3e1e5ed"]
String[] boundaryPieces = contentType.split("=", 2);
Expand Down Expand Up @@ -94,7 +95,7 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
HttpHeaders headers = getHttpHeaders(exceptionSections[1]);

sink.error(logger.logExceptionAsError(new BlobStorageException(
headers.getValue(Constants.HeaderConstants.ERROR_CODE),
headers.getValue(Constants.HeaderConstants.ERROR_CODE_HEADER_NAME),
createHttpResponse(rawResponse.getRequest(), statusCode, headers, body), body)));
}

Expand Down Expand Up @@ -123,7 +124,7 @@ static Mono<SimpleResponse<Void>> mapBatchResponse(BlobBatchOperationInfo batchO
}
}

if (throwOnAnyFailure && exceptions.size() != 0) {
if (throwOnAnyFailure && !exceptions.isEmpty()) {
sink.error(logger.logExceptionAsError(new BlobBatchStorageException("Batch had operation failures.",
createHttpResponse(rawResponse), exceptions)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.cryptography.AsyncKeyEncryptionKey;
import com.azure.core.cryptography.AsyncKeyEncryptionKeyResolver;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpPipelineCallContext;
Expand All @@ -14,7 +15,6 @@
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.blob.models.BlobRange;
import com.azure.storage.common.implementation.Constants;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand All @@ -23,10 +23,7 @@
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicLong;

import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.CONTENT_LENGTH;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.CONTENT_RANGE;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.ENCRYPTION_BLOCK_SIZE;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.ENCRYPTION_DATA_KEY;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.ENCRYPTION_METADATA_HEADER;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.ENCRYPTION_PROTOCOL_V1;
import static com.azure.storage.blob.specialized.cryptography.CryptographyConstants.RANGE_HEADER;
Expand Down Expand Up @@ -95,8 +92,7 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
* didn't expand the range at all.
*/
EncryptionData encryptionData = EncryptionData.getAndValidateEncryptionData(
httpResponse.getHeaderValue(Constants.HeaderConstants.X_MS_META + "-"
+ ENCRYPTION_DATA_KEY), requiresEncryption);
httpResponse.getHeaderValue(ENCRYPTION_METADATA_HEADER), requiresEncryption);
// If there was no encryption data, it was either an error response or the blob is not encrypted.
if (!isEncryptedBlob(encryptionData)) {
return Mono.just(httpResponse);
Expand All @@ -110,7 +106,7 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
*/
EncryptedBlobRange encryptedRange = new EncryptedBlobRange(new BlobRange(0), encryptionData);
encryptedRange.setAdjustedDownloadCount(
Long.parseLong(responseHeaders.getValue(CONTENT_LENGTH)));
Long.parseLong(responseHeaders.getValue(HttpHeaderName.CONTENT_LENGTH)));

boolean padding = hasPadding(responseHeaders, encryptionData, encryptedRange);

Expand Down Expand Up @@ -147,7 +143,7 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
return httpResponse;
}
encryptedRange.setAdjustedDownloadCount(
Long.parseLong(responseHeaders.getValue(CONTENT_LENGTH)));
Long.parseLong(responseHeaders.getValue(HttpHeaderName.CONTENT_LENGTH)));

/*
* We expect padding only if we are at the end of a blob and it is not a multiple of the
Expand Down Expand Up @@ -325,12 +321,12 @@ Flux<ByteBuffer> trimData(EncryptedBlobRange encryptedBlobRange,

private Long blobSize(HttpHeaders headers) {
// e.g. 0-5/1024
if (headers.getValue(CONTENT_RANGE) != null) {
String range = headers.getValue(CONTENT_RANGE);
if (headers.getValue(HttpHeaderName.CONTENT_RANGE) != null) {
String range = headers.getValue(HttpHeaderName.CONTENT_RANGE);
return Long.valueOf(range.split("/")[1]);
} else {
// If there was no content range header, we requested a full blob, so the blobSize = contentLength
return Long.valueOf(headers.getValue(CONTENT_LENGTH));
return Long.valueOf(headers.getValue(HttpHeaderName.CONTENT_LENGTH));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.storage.blob.specialized.cryptography;

import com.azure.core.http.HttpHeaderName;
import com.azure.core.util.CoreUtils;
import com.azure.storage.common.implementation.Constants;

Expand Down Expand Up @@ -30,18 +31,14 @@ final class CryptographyConstants {

static final String ENCRYPTION_DATA_KEY = "encryptiondata";

static final String ENCRYPTION_METADATA_HEADER = Constants.HeaderConstants.X_MS_META + "-"
+ ENCRYPTION_DATA_KEY;
static final HttpHeaderName ENCRYPTION_METADATA_HEADER
= HttpHeaderName.fromString(Constants.HeaderConstants.X_MS_META + "-" + ENCRYPTION_DATA_KEY);

static final String ENCRYPTION_MODE = "FullBlob";

static final int ENCRYPTION_BLOCK_SIZE = 16;

static final String RANGE_HEADER = "x-ms-range";

static final String CONTENT_RANGE = "Content-Range";

static final String CONTENT_LENGTH = "Content-Length";
static final HttpHeaderName RANGE_HEADER = HttpHeaderName.fromString("x-ms-range");

static final int NONCE_LENGTH = 12;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.core.cryptography.AsyncKeyEncryptionKey;
import com.azure.core.cryptography.AsyncKeyEncryptionKeyResolver;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
Expand Down Expand Up @@ -172,6 +173,7 @@ public EncryptedBlobClientBuilder() {
* preferred for security reasons, though v1 continues to be supported for compatibility reasons. Note that even a
* client configured to encrypt using v2 can decrypt blobs that use the v1 protocol.
*/
@SuppressWarnings("deprecation")
public EncryptedBlobClientBuilder(EncryptionVersion version) {
Objects.requireNonNull(version);
logOptions = getDefaultHttpLogOptions();
Expand Down Expand Up @@ -321,8 +323,7 @@ private HttpPipeline getHttpPipeline() {
List<HttpPipelinePolicy> policies = new ArrayList<>();

policies.add(new BlobDecryptionPolicy(keyWrapper, keyResolver, requiresEncryption));
String applicationId = clientOptions.getApplicationId() != null ? clientOptions.getApplicationId()
: logOptions.getApplicationId();
String applicationId = CoreUtils.getApplicationId(clientOptions, logOptions);

// adding modified user-agent string that will contain "azstorage-clientsideencryption/" + encryption version
String modifiedUserAgent = modifyUserAgentString(applicationId, userAgentConfiguration);
Expand All @@ -338,9 +339,8 @@ private HttpPipeline getHttpPipeline() {

// We need to place this policy right before the credential policy since headers may affect the string to sign
// of the request.
HttpHeaders headers = new HttpHeaders();
clientOptions.getHeaders().forEach(header -> headers.put(header.getName(), header.getValue()));
if (headers.getSize() > 0) {
HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(clientOptions);
if (headers != null) {
policies.add(new AddHeadersPolicy(headers));
}
policies.add(new MetadataValidationPolicy());
Expand All @@ -361,8 +361,8 @@ private HttpPipeline getHttpPipeline() {
HttpPolicyProviders.addAfterRetryPolicies(policies);

policies.add(new ResponseValidationPolicyBuilder()
.addOptionalEcho(Constants.HeaderConstants.CLIENT_REQUEST_ID)
.addOptionalEcho(Constants.HeaderConstants.ENCRYPTION_KEY_SHA256)
.addOptionalEcho(HttpHeaderName.X_MS_CLIENT_REQUEST_ID)
.addOptionalEcho(Constants.HeaderConstants.ENCRYPTION_KEY_SHA256_HEADER_NAME)
.build());

policies.add(new HttpLoggingPolicy(logOptions));
Expand Down Expand Up @@ -711,7 +711,7 @@ public EncryptedBlobClientBuilder configuration(Configuration configuration) {

/**
* Sets the request retry options for all the requests made through the client.
*
* <p>
* Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
*
* @param retryOptions {@link RequestRetryOptions}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ Mono<Response<Void>> createWithResponse(Map<String, String> metadata, PublicAcce
Context context) {
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getContainers().createNoCustomHeadersWithResponseAsync(containerName, null,
metadata, accessType, null, blobContainerEncryptionScope, context);
metadata, accessType, null, blobContainerEncryptionScope, context)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -575,7 +576,8 @@ Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestConditions,

return this.azureBlobStorage.getContainers().deleteNoCustomHeadersWithResponseAsync(containerName, null,
requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, context);
requestConditions.getIfUnmodifiedSince(), null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -716,6 +718,7 @@ Mono<Response<BlobContainerProperties>> getPropertiesWithResponse(String leaseId

return this.azureBlobStorage.getContainers()
.getPropertiesWithResponseAsync(containerName, null, leaseId, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> {
ContainersGetPropertiesHeaders hd = rb.getDeserializedHeaders();
BlobContainerProperties properties = new BlobContainerProperties(hd.getXMsMeta(), hd.getETag(),
Expand Down Expand Up @@ -799,7 +802,8 @@ Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata,
}

return this.azureBlobStorage.getContainers().setMetadataNoCustomHeadersWithResponseAsync(containerName, null,
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context);
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -867,6 +871,7 @@ Mono<Response<BlobContainerAccessPolicies>> getAccessPolicyWithResponse(String l
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getContainers().getAccessPolicyWithResponseAsync(
containerName, null, leaseId, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(response -> new SimpleResponse<>(response,
new BlobContainerAccessPolicies(response.getDeserializedHeaders().getXMsBlobPublicAccess(),
response.getValue().items())));
Expand Down Expand Up @@ -990,7 +995,8 @@ OffsetDateTime.now will only give back milliseconds (more precise fields are zer

return this.azureBlobStorage.getContainers().setAccessPolicyNoCustomHeadersWithResponseAsync(containerName,
null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, identifiers, context);
requestConditions.getIfUnmodifiedSince(), null, identifiers, context)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -1197,7 +1203,8 @@ PagedFlux<BlobItem> listBlobsFlatWithOptionalTimeout(ListBlobsOptions options, S
return StorageImplUtils.applyOptionalTimeout(
this.azureBlobStorage.getContainers().listBlobFlatSegmentWithResponseAsync(containerName,
options.getPrefix(), marker, options.getMaxResultsPerPage(), include, null, null, Context.NONE),
timeout);
timeout)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -1371,7 +1378,8 @@ PagedFlux<BlobItem> listBlobsHierarchyWithOptionalTimeout(String delimiter, List
this.azureBlobStorage.getContainers().listBlobHierarchySegmentWithResponseAsync(containerName, delimiter,
options.getPrefix(), marker, options.getMaxResultsPerPage(), include, null, null,
Context.NONE),
timeout);
timeout)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -1454,6 +1462,7 @@ private Mono<PagedResponse<TaggedBlobItem>> findBlobsByTags(
return StorageImplUtils.applyOptionalTimeout(
this.azureBlobStorage.getContainers().filterBlobsWithResponseAsync(containerName, null, null,
options.getQuery(), marker, options.getMaxResultsPerPage(), null, context), timeout)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(response -> {
List<TaggedBlobItem> value = response.getValue().getBlobs().stream()
.map(ModelHelper::populateTaggedBlobItem)
Expand Down Expand Up @@ -1520,6 +1529,7 @@ public Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse() {
Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse(Context context) {
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getContainers().getAccountInfoWithResponseAsync(containerName, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> {
ContainersGetAccountInfoHeaders hd = rb.getDeserializedHeaders();
return new SimpleResponse<>(rb, new StorageAccountInfo(hd.getXMsSkuName(), hd.getXMsAccountKind()));
Expand Down Expand Up @@ -1562,6 +1572,7 @@ Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse(Context context) {
// return this.azureBlobStorage.getContainers().renameWithResponseAsync(containerName,
// sourceContainerName, null, null, requestConditions.getLeaseId(),
// context)
// .onErrorMap(ModelHelper::mapToBlobStorageException)
// .map(response -> new SimpleResponse<>(response, this));
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ private Mono<PagedResponse<BlobContainerItem>> listBlobContainersSegment(String
this.azureBlobStorage.getServices().listBlobContainersSegmentSinglePageAsync(
options.getPrefix(), marker, options.getMaxResultsPerPage(),
toIncludeTypes(options.getDetails()),
null, null, Context.NONE), timeout);
null, null, Context.NONE), timeout)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -613,6 +614,7 @@ private Mono<PagedResponse<TaggedBlobItem>> findBlobsByTags(
return StorageImplUtils.applyOptionalTimeout(
this.azureBlobStorage.getServices().filterBlobsWithResponseAsync(null, null,
options.getQuery(), marker, options.getMaxResultsPerPage(), null, context), timeout)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(response -> {
List<TaggedBlobItem> value = response.getValue().getBlobs().stream()
.map(ModelHelper::populateTaggedBlobItem)
Expand Down Expand Up @@ -710,6 +712,7 @@ Mono<Response<BlobServiceProperties>> getPropertiesWithResponse(Context context)
context = context == null ? Context.NONE : context;
throwOnAnonymousAccess();
return this.azureBlobStorage.getServices().getPropertiesWithResponseAsync(null, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> new SimpleResponse<>(rb, rb.getValue()));
}

Expand Down Expand Up @@ -856,7 +859,8 @@ Mono<Response<Void>> setPropertiesWithResponse(BlobServiceProperties properties,
context = context == null ? Context.NONE : context;

return this.azureBlobStorage.getServices()
.setPropertiesNoCustomHeadersWithResponseAsync(finalProperties, null, null, context);
.setPropertiesNoCustomHeadersWithResponseAsync(finalProperties, null, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException);
}

/**
Expand Down Expand Up @@ -960,6 +964,7 @@ Mono<Response<UserDelegationKey>> getUserDelegationKeyWithResponse(OffsetDateTim
.setStart(start == null ? "" : Constants.ISO_8601_UTC_DATE_FORMATTER.format(start))
.setExpiry(Constants.ISO_8601_UTC_DATE_FORMATTER.format(expiry)),
null, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> new SimpleResponse<>(rb, rb.getValue()));
}

Expand Down Expand Up @@ -1017,6 +1022,7 @@ Mono<Response<BlobServiceStatistics>> getStatisticsWithResponse(Context context)
context = context == null ? Context.NONE : context;

return this.azureBlobStorage.getServices().getStatisticsWithResponseAsync(null, null, context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> new SimpleResponse<>(rb, rb.getValue()));
}

Expand Down Expand Up @@ -1068,6 +1074,7 @@ public Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse() {
Mono<Response<StorageAccountInfo>> getAccountInfoWithResponse(Context context) {
throwOnAnonymousAccess();
return this.azureBlobStorage.getServices().getAccountInfoWithResponseAsync(context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(rb -> {
ServicesGetAccountInfoHeaders hd = rb.getDeserializedHeaders();
return new SimpleResponse<>(rb, new StorageAccountInfo(hd.getXMsSkuName(), hd.getXMsAccountKind(),
Expand Down Expand Up @@ -1269,6 +1276,7 @@ Mono<Response<BlobContainerAsyncClient>> undeleteBlobContainerWithResponse(
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getContainers().restoreWithResponseAsync(finalDestinationContainerName, null,
null, options.getDeletedContainerName(), options.getDeletedContainerVersion(), context)
.onErrorMap(ModelHelper::mapToBlobStorageException)
.map(response -> new SimpleResponse<>(response,
getBlobContainerAsyncClient(finalDestinationContainerName)));
}
Expand Down
Loading