From 84abfdf586ee05b9b445571f339f3f84e461131d Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 23 Sep 2019 14:05:34 -0700 Subject: [PATCH] Fix missing response fields using transforms (#5440) --- .../storage/blob/AppendBlobAsyncClient.java | 3 +- .../storage/blob/PageBlobAsyncClient.java | 7 +- .../AppendBlobAppendBlockFromUrlHeaders.java | 32 ++++++++++ .../storage/blob/models/AppendBlobItem.java | 4 +- .../models/PageBlobClearPagesHeaders.java | 64 +++++++++++++++++++ .../storage/blob/models/PageBlobItem.java | 11 ++-- .../PageBlobUploadPagesFromURLHeaders.java | 32 ++++++++++ .../azure-storage-blob/swagger/README.md | 51 +++++++++++++++ 8 files changed, 189 insertions(+), 15 deletions(-) diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java index 4cef778eb1770..dfa5ca9bb966f 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/AppendBlobAsyncClient.java @@ -224,7 +224,6 @@ Mono> appendBlockFromUrlWithResponse(URL sourceURL, Blo destAccessConditions.getLeaseAccessConditions(), destAccessConditions.getAppendPositionAccessConditions(), destAccessConditions.getModifiedAccessConditions(), sourceAccessConditions, context)) - .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.getDeserializedHeaders(), - rb.getHeaders().getValue("x-ms-request-server-encrypted")))); + .map(rb -> new SimpleResponse<>(rb, new AppendBlobItem(rb.getDeserializedHeaders()))); } } diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java index cae5a0eb7c647..7893553588172 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/PageBlobAsyncClient.java @@ -296,8 +296,7 @@ Mono> uploadPagesFromURLWithResponse(PageRange range, URL null, null, sourceURL, sourceRangeString, 0, rangeString, sourceContentMD5, null, null, null, cpk, destAccessConditions.getLeaseAccessConditions(), destAccessConditions.getSequenceNumberAccessConditions(), destAccessConditions.getModifiedAccessConditions(), sourceAccessConditions, context)) - .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.getDeserializedHeaders(), - rb.getHeaders().getValue("x-ms-encryption-key-sha256")))); + .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.getDeserializedHeaders()))); } /** @@ -354,9 +353,7 @@ Mono> clearPagesWithResponse(PageRange pageRange, pageBlobAccessConditions.getLeaseAccessConditions(), cpk, pageBlobAccessConditions.getSequenceNumberAccessConditions(), pageBlobAccessConditions.getModifiedAccessConditions(), context)) - .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.getDeserializedHeaders(), - rb.getHeaders().getValue("x-ms-request-server-encrypted"), - rb.getHeaders().getValue("x-ms-encryption-key-sha256")))); + .map(rb -> new SimpleResponse<>(rb, new PageBlobItem(rb.getDeserializedHeaders()))); } /** diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobAppendBlockFromUrlHeaders.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobAppendBlockFromUrlHeaders.java index e0e6472108e64..10bd672a6ba39 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobAppendBlockFromUrlHeaders.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobAppendBlockFromUrlHeaders.java @@ -93,6 +93,14 @@ public final class AppendBlobAppendBlockFromUrlHeaders { @JsonProperty(value = "x-ms-encryption-key-sha256") private String encryptionKeySha256; + /* + * The value of this header is set to true if the contents of the request + * are successfully encrypted using the specified algorithm, and false + * otherwise. + */ + @JsonProperty(value = "x-ms-request-server-encrypted") + private Boolean isServerEncrypted; + /* * The errorCode property. */ @@ -351,6 +359,30 @@ public AppendBlobAppendBlockFromUrlHeaders setEncryptionKeySha256(String encrypt return this; } + /** + * Get the isServerEncrypted property: The value of this header is set to + * true if the contents of the request are successfully encrypted using the + * specified algorithm, and false otherwise. + * + * @return the isServerEncrypted value. + */ + public Boolean isServerEncrypted() { + return this.isServerEncrypted; + } + + /** + * Set the isServerEncrypted property: The value of this header is set to + * true if the contents of the request are successfully encrypted using the + * specified algorithm, and false otherwise. + * + * @param isServerEncrypted the isServerEncrypted value to set. + * @return the AppendBlobAppendBlockFromUrlHeaders object itself. + */ + public AppendBlobAppendBlockFromUrlHeaders setIsServerEncrypted(Boolean isServerEncrypted) { + this.isServerEncrypted = isServerEncrypted; + return this; + } + /** * Get the errorCode property: The errorCode property. * diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobItem.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobItem.java index 084813348c2ea..d522ec00c3d97 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobItem.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/AppendBlobItem.java @@ -39,11 +39,11 @@ public AppendBlobItem(AppendBlobAppendBlockHeaders generatedHeaders) { this.blobCommittedBlockCount = generatedHeaders.getBlobCommittedBlockCount(); } - public AppendBlobItem(AppendBlobAppendBlockFromUrlHeaders generatedHeaders, String isServerEncryptedHeader) { + public AppendBlobItem(AppendBlobAppendBlockFromUrlHeaders generatedHeaders) { this.eTag = generatedHeaders.getETag(); this.lastModified = generatedHeaders.getLastModified(); this.contentMD5 = generatedHeaders.getContentMD5(); - this.isServerEncrypted = Boolean.parseBoolean(isServerEncryptedHeader); + this.isServerEncrypted = generatedHeaders.isServerEncrypted(); this.encryptionKeySha256 = generatedHeaders.getEncryptionKeySha256(); this.blobAppendOffset = generatedHeaders.getBlobAppendOffset(); this.blobCommittedBlockCount = generatedHeaders.getBlobCommittedBlockCount(); diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobClearPagesHeaders.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobClearPagesHeaders.java index a27a6e29978b2..3b3082bd53d65 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobClearPagesHeaders.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobClearPagesHeaders.java @@ -84,6 +84,22 @@ public final class PageBlobClearPagesHeaders { @JsonProperty(value = "Date") private DateTimeRfc1123 dateProperty; + /* + * The value of this header is set to true if the contents of the request + * are successfully encrypted using the specified algorithm, and false + * otherwise. + */ + @JsonProperty(value = "x-ms-request-server-encrypted") + private Boolean isServerEncrypted; + + /* + * The SHA-256 hash of the encryption key used to encrypt the pages. This + * header is only returned when the pages were encrypted with a + * customer-provided key. + */ + @JsonProperty(value = "x-ms-encryption-key-sha256") + private String encryptionKeySha256; + /* * The errorCode property. */ @@ -318,6 +334,54 @@ public PageBlobClearPagesHeaders setDateProperty(OffsetDateTime dateProperty) { return this; } + /** + * Get the isServerEncrypted property: The value of this header is set to + * true if the contents of the request are successfully encrypted using the + * specified algorithm, and false otherwise. + * + * @return the isServerEncrypted value. + */ + public Boolean isServerEncrypted() { + return this.isServerEncrypted; + } + + /** + * Set the isServerEncrypted property: The value of this header is set to + * true if the contents of the request are successfully encrypted using the + * specified algorithm, and false otherwise. + * + * @param isServerEncrypted the isServerEncrypted value to set. + * @return the PageBlobClearPagesHeaders object itself. + */ + public PageBlobClearPagesHeaders setIsServerEncrypted(Boolean isServerEncrypted) { + this.isServerEncrypted = isServerEncrypted; + return this; + } + + /** + * Get the encryptionKeySha256 property: The SHA-256 hash of the encryption + * key used to encrypt the pages. This header is only returned when the + * pages were encrypted with a customer-provided key. + * + * @return the encryptionKeySha256 value. + */ + public String getEncryptionKeySha256() { + return this.encryptionKeySha256; + } + + /** + * Set the encryptionKeySha256 property: The SHA-256 hash of the encryption + * key used to encrypt the pages. This header is only returned when the + * pages were encrypted with a customer-provided key. + * + * @param encryptionKeySha256 the encryptionKeySha256 value to set. + * @return the PageBlobClearPagesHeaders object itself. + */ + public PageBlobClearPagesHeaders setEncryptionKeySha256(String encryptionKeySha256) { + this.encryptionKeySha256 = encryptionKeySha256; + return this; + } + /** * Get the errorCode property: The errorCode property. * diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobItem.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobItem.java index 6206acd558cb5..afebfc8834919 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobItem.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobItem.java @@ -33,22 +33,21 @@ public PageBlobItem(PageBlobUploadPagesHeaders generatedHeaders) { this.blobSequenceNumber = generatedHeaders.getBlobSequenceNumber(); } - public PageBlobItem(PageBlobUploadPagesFromURLHeaders generatedHeaders, String encryptionKeySha256Header) { + public PageBlobItem(PageBlobUploadPagesFromURLHeaders generatedHeaders) { this.eTag = generatedHeaders.getETag(); this.lastModified = generatedHeaders.getLastModified(); this.contentMD5 = generatedHeaders.getContentMD5(); this.isServerEncrypted = generatedHeaders.isServerEncrypted(); - this.encryptionKeySha256 = encryptionKeySha256Header; + this.encryptionKeySha256 = generatedHeaders.getEncryptionKeySha256(); this.blobSequenceNumber = generatedHeaders.getBlobSequenceNumber(); } - public PageBlobItem(PageBlobClearPagesHeaders generatedHeaders, String isServerEncryptedHeader, - String encryptionKeySha256Header) { + public PageBlobItem(PageBlobClearPagesHeaders generatedHeaders) { this.eTag = generatedHeaders.getETag(); this.lastModified = generatedHeaders.getLastModified(); this.contentMD5 = generatedHeaders.getContentMD5(); - this.isServerEncrypted = Boolean.parseBoolean(isServerEncryptedHeader); - this.encryptionKeySha256 = encryptionKeySha256Header; + this.isServerEncrypted = generatedHeaders.isServerEncrypted(); + this.encryptionKeySha256 = generatedHeaders.getEncryptionKeySha256(); this.blobSequenceNumber = generatedHeaders.getBlobSequenceNumber(); } diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobUploadPagesFromURLHeaders.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobUploadPagesFromURLHeaders.java index 10e1a465aeb0b..77ab765a76243 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobUploadPagesFromURLHeaders.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/PageBlobUploadPagesFromURLHeaders.java @@ -85,6 +85,14 @@ public final class PageBlobUploadPagesFromURLHeaders { @JsonProperty(value = "x-ms-request-server-encrypted") private Boolean isServerEncrypted; + /* + * The SHA-256 hash of the encryption key used to encrypt the pages. This + * header is only returned when the pages were encrypted with a + * customer-provided key. + */ + @JsonProperty(value = "x-ms-encryption-key-sha256") + private String encryptionKeySha256; + /* * The errorCode property. */ @@ -319,6 +327,30 @@ public PageBlobUploadPagesFromURLHeaders setIsServerEncrypted(Boolean isServerEn return this; } + /** + * Get the encryptionKeySha256 property: The SHA-256 hash of the encryption + * key used to encrypt the pages. This header is only returned when the + * pages were encrypted with a customer-provided key. + * + * @return the encryptionKeySha256 value. + */ + public String getEncryptionKeySha256() { + return this.encryptionKeySha256; + } + + /** + * Set the encryptionKeySha256 property: The SHA-256 hash of the encryption + * key used to encrypt the pages. This header is only returned when the + * pages were encrypted with a customer-provided key. + * + * @param encryptionKeySha256 the encryptionKeySha256 value to set. + * @return the PageBlobUploadPagesFromURLHeaders object itself. + */ + public PageBlobUploadPagesFromURLHeaders setEncryptionKeySha256(String encryptionKeySha256) { + this.encryptionKeySha256 = encryptionKeySha256; + return this; + } + /** * Get the errorCode property: The errorCode property. * diff --git a/sdk/storage/azure-storage-blob/swagger/README.md b/sdk/storage/azure-storage-blob/swagger/README.md index 5ada8e591d323..470f72b659098 100644 --- a/sdk/storage/azure-storage-blob/swagger/README.md +++ b/sdk/storage/azure-storage-blob/swagger/README.md @@ -882,3 +882,54 @@ directive: "@JsonDeserialize(using = CustomHierarchicalListingDeserializer.class)\npublic final class BlobHierarchyListSegment {"); ``` +### Add EncryptionKeySha256 to PageBlobUploadPagesFromURLHeaders +``` yaml +directive: +- from: swagger-document + where: $["x-ms-paths"]["/{containerName}/{blob}?comp=page&update&fromUrl"].put.responses["201"].headers + transform: > + if (!$["x-ms-encryption-key-sha256"]) { + $["x-ms-encryption-key-sha256"] = { + "x-ms-client-name": "EncryptionKeySha256", + "type": "string", + "description": "The SHA-256 hash of the encryption key used to encrypt the pages. This header is only returned when the pages were encrypted with a customer-provided key." + }; + } +``` + +### Add IsServerEncrypted to AppendBlobAppendBlockFromUrlHeaders +``` yaml +directive: +- from: swagger-document + where: $["x-ms-paths"]["/{containerName}/{blob}?comp=appendblock&fromUrl"].put.responses["201"].headers + transform: > + if (!$["x-ms-request-server-encrypted"]) { + $["x-ms-request-server-encrypted"] = { + "x-ms-client-name": "IsServerEncrypted", + "type": "boolean", + "description": "The value of this header is set to true if the contents of the request are successfully encrypted using the specified algorithm, and false otherwise." + }; + } +``` + +### Add EncryptionKeySha256 and IsServerEncrypted to PageBlobClearPagesHeaders +``` yaml +directive: +- from: swagger-document + where: $["x-ms-paths"]["/{containerName}/{blob}?comp=page&clear"].put.responses["201"].headers + transform: > + if (!$["x-ms-request-server-encrypted"]) { + $["x-ms-request-server-encrypted"] = { + "x-ms-client-name": "IsServerEncrypted", + "type": "boolean", + "description": "The value of this header is set to true if the contents of the request are successfully encrypted using the specified algorithm, and false otherwise." + }; + } + if (!$["x-ms-encryption-key-sha256"]) { + $["x-ms-encryption-key-sha256"] = { + "x-ms-client-name": "EncryptionKeySha256", + "type": "string", + "description": "The SHA-256 hash of the encryption key used to encrypt the pages. This header is only returned when the pages were encrypted with a customer-provided key." + }; + } +```