Skip to content

Commit

Permalink
[BUG] Set secret operation of the Key Vault Secrets Client overrides …
Browse files Browse the repository at this point in the history
…the content type of the secret with application/json (#37020)

* [BUG] Set secret operation of the Key Vault Secrets Client overrides the content type of the secret with application/json
- Fixes sync and async implementations to use the contentType value set by the caller in the payload
- Adds entry to changelog

Resolves #37019

Signed-off-by: Esta Nagy <[email protected]>

* [BUG] Set secret operation of the Key Vault Secrets Client overrides the content type of the secret with application/json
- Removes default contentType value when the properties are not defined

Resolves #37019

Signed-off-by: Esta Nagy <[email protected]>

* Added changes missing setSecret and updateSecret methods.

* Updated tests.

* Added missing fix for updateSecretPropertiesWithResponse() methods in sync and async clients.

* Updated test recordings.

* Removed unused imports.

---------

Signed-off-by: Esta Nagy <[email protected]>
Co-authored-by: Victor Colin Amador <[email protected]>
  • Loading branch information
nagyesta and vcolin7 authored Oct 4, 2023
1 parent 57211e0 commit 0f0190a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 46 deletions.
2 changes: 2 additions & 0 deletions sdk/keyvault/azure-security-keyvault-secrets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue preventing the client from setting the contentType of the secret when the set secret operation is performed. ([#37019](https://github.com/Azure/azure-sdk-for-java/issues/37019))

### Other Changes

## 4.7.0 (2023-09-25)
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/azure-security-keyvault-secrets/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/keyvault/azure-security-keyvault-secrets",
"Tag": "java/keyvault/azure-security-keyvault-secrets_888b31153a"
"Tag": "java/keyvault/azure-security-keyvault-secrets_068b53aa9a"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.ContentType;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
Expand Down Expand Up @@ -289,13 +288,13 @@ public Mono<Response<KeyVaultSecret>> setSecretWithResponse(KeyVaultSecret secre
SecretProperties secretProperties = secret.getProperties();
if (secretProperties == null) {
return implClient.setSecretWithResponseAsync(vaultUrl, secret.getName(), secret.getValue(),
null, ContentType.APPLICATION_JSON, null)
null, null, null)
.onErrorMap(KeyVaultErrorException.class, SecretAsyncClient::mapSetSecretException)
.map(response -> new SimpleResponse<>(response, createKeyVaultSecret(response.getValue())));
} else {
return implClient.setSecretWithResponseAsync(vaultUrl, secret.getName(), secret.getValue(),
secret.getProperties().getTags(), ContentType.APPLICATION_JSON,
createSecretAttributes(secret.getProperties()))
secretProperties.getTags(), secretProperties.getContentType(),
createSecretAttributes(secretProperties))
.onErrorMap(KeyVaultErrorException.class, SecretAsyncClient::mapSetSecretException)
.map(response -> new SimpleResponse<>(response, createKeyVaultSecret(response.getValue())));
}
Expand Down Expand Up @@ -516,7 +515,7 @@ public Mono<SecretProperties> updateSecretProperties(SecretProperties secretProp
public Mono<Response<SecretProperties>> updateSecretPropertiesWithResponse(SecretProperties secretProperties) {
try {
return implClient.updateSecretWithResponseAsync(vaultUrl, secretProperties.getName(),
secretProperties.getVersion(), ContentType.APPLICATION_JSON,
secretProperties.getVersion(), secretProperties.getContentType(),
createSecretAttributes(secretProperties), secretProperties.getTags())
.map(response -> new SimpleResponse<>(response, createSecretProperties(response.getValue())));
} catch (RuntimeException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.ContentType;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
Expand Down Expand Up @@ -261,11 +260,11 @@ public Response<KeyVaultSecret> setSecretWithResponse(KeyVaultSecret secret, Con
SecretProperties secretProperties = secret.getProperties();
if (secretProperties == null) {
Response<SecretBundle> response = implClient.setSecretWithResponse(vaultUrl, secret.getName(),
secret.getValue(), null, ContentType.APPLICATION_JSON, null, context);
secret.getValue(), null, null, null, context);
return new SimpleResponse<>(response, createKeyVaultSecret(response.getValue()));
} else {
Response<SecretBundle> response = implClient.setSecretWithResponse(vaultUrl, secret.getName(),
secret.getValue(), secretProperties.getTags(), ContentType.APPLICATION_JSON,
secret.getValue(), secretProperties.getTags(), secretProperties.getContentType(),
createSecretAttributes(secretProperties), context);
return new SimpleResponse<>(response, createKeyVaultSecret(response.getValue()));
}
Expand Down Expand Up @@ -435,7 +434,7 @@ public SecretProperties updateSecretProperties(SecretProperties secretProperties
public Response<SecretProperties> updateSecretPropertiesWithResponse(SecretProperties secretProperties,
Context context) {
Response<SecretBundle> response = implClient.updateSecretWithResponse(vaultUrl, secretProperties.getName(),
secretProperties.getVersion(), ContentType.APPLICATION_JSON, createSecretAttributes(secretProperties),
secretProperties.getVersion(), secretProperties.getContentType(), createSecretAttributes(secretProperties),
secretProperties.getTags(), context);
return new SimpleResponse<>(response, createSecretProperties(response.getValue()));
}
Expand Down
Loading

0 comments on commit 0f0190a

Please sign in to comment.