diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index b4bb26844c52b..9216a9a8332ed 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -450,7 +450,7 @@ - + diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java index 49aa98f54e3fb..4f3ccce61ea45 100644 --- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java +++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java @@ -97,8 +97,7 @@ public final class KeyAsyncClient { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createKey(String name, KeyType keyType) { - return withContext(context -> createKey(name, keyType, context)) - .flatMap(FluxUtil::toMono); + return withContext(context -> createKeyWithResponse(name, keyType, context)).flatMap(FluxUtil::toMono); } /** @@ -120,10 +119,10 @@ public Mono createKey(String name, KeyType keyType) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createKeyWithResponse(KeyCreateOptions keyCreateOptions) { - return withContext(context -> createKey(keyCreateOptions, context)); + return withContext(context -> createKeyWithResponse(keyCreateOptions, context)); } - Mono> createKey(String name, KeyType keyType, Context context) { + Mono> createKeyWithResponse(String name, KeyType keyType, Context context) { KeyRequestParameters parameters = new KeyRequestParameters().kty(keyType); return service.createKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, parameters, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Creating key - {}", name)) @@ -155,11 +154,10 @@ Mono> createKey(String name, KeyType keyType, Context context) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createKey(KeyCreateOptions keyCreateOptions) { - return withContext(context -> createKeyWithResponse(keyCreateOptions)) - .flatMap(FluxUtil::toMono); + return createKeyWithResponse(keyCreateOptions).flatMap(FluxUtil::toMono); } - Mono> createKey(KeyCreateOptions keyCreateOptions, Context context) { + Mono> createKeyWithResponse(KeyCreateOptions keyCreateOptions, Context context) { Objects.requireNonNull(keyCreateOptions, "The key create options parameter cannot be null."); KeyRequestParameters parameters = new KeyRequestParameters() .kty(keyCreateOptions.keyType()) @@ -196,8 +194,7 @@ Mono> createKey(KeyCreateOptions keyCreateOptions, Context context */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { - return withContext(context -> createRsaKeyWithResponse(rsaKeyCreateOptions)) - .flatMap(FluxUtil::toMono); + return createRsaKeyWithResponse(rsaKeyCreateOptions).flatMap(FluxUtil::toMono); } /** @@ -221,10 +218,10 @@ public Mono createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createRsaKeyWithResponse(RsaKeyCreateOptions rsaKeyCreateOptions) { - return withContext(context -> createRsaKey(rsaKeyCreateOptions, context)); + return withContext(context -> createRsaKeyWithResponse(rsaKeyCreateOptions, context)); } - Mono> createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions, Context context) { + Mono> createRsaKeyWithResponse(RsaKeyCreateOptions rsaKeyCreateOptions, Context context) { Objects.requireNonNull(rsaKeyCreateOptions, "The Rsa key options parameter cannot be null."); KeyRequestParameters parameters = new KeyRequestParameters() .kty(rsaKeyCreateOptions.keyType()) @@ -262,8 +259,7 @@ Mono> createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions, Contex */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { - return withContext(context -> createEcKeyWithResponse(ecKeyCreateOptions)) - .flatMap(FluxUtil::toMono); + return createEcKeyWithResponse(ecKeyCreateOptions).flatMap(FluxUtil::toMono); } /** @@ -291,10 +287,10 @@ public Mono createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createEcKeyWithResponse(EcKeyCreateOptions ecKeyCreateOptions) { - return withContext(context -> createEcKey(ecKeyCreateOptions, context)); + return withContext(context -> createEcKeyWithResponse(ecKeyCreateOptions, context)); } - Mono> createEcKey(EcKeyCreateOptions ecKeyCreateOptions, Context context) { + Mono> createEcKeyWithResponse(EcKeyCreateOptions ecKeyCreateOptions, Context context) { Objects.requireNonNull(ecKeyCreateOptions, "The Ec key options options cannot be null."); KeyRequestParameters parameters = new KeyRequestParameters() .kty(ecKeyCreateOptions.keyType()) @@ -326,11 +322,10 @@ Mono> createEcKey(EcKeyCreateOptions ecKeyCreateOptions, Context c */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono importKey(String name, JsonWebKey keyMaterial) { - return withContext(context -> importKey(name, keyMaterial, context)) - .flatMap(FluxUtil::toMono); + return withContext(context -> importKeyWithResponse(name, keyMaterial, context)).flatMap(FluxUtil::toMono); } - Mono> importKey(String name, JsonWebKey keyMaterial, Context context) { + Mono> importKeyWithResponse(String name, JsonWebKey keyMaterial, Context context) { KeyImportRequestParameters parameters = new KeyImportRequestParameters().key(keyMaterial); return service.importKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, parameters, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Importing key - {}", name)) @@ -366,8 +361,7 @@ Mono> importKey(String name, JsonWebKey keyMaterial, Context conte */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono importKey(KeyImportOptions keyImportOptions) { - return withContext(context -> importKeyWithResponse(keyImportOptions)) - .flatMap(FluxUtil::toMono); + return importKeyWithResponse(keyImportOptions).flatMap(FluxUtil::toMono); } /** @@ -398,10 +392,10 @@ public Mono importKey(KeyImportOptions keyImportOptions) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> importKeyWithResponse(KeyImportOptions keyImportOptions) { - return withContext(context -> importKey(keyImportOptions, context)); + return withContext(context -> importKeyWithResponse(keyImportOptions, context)); } - Mono> importKey(KeyImportOptions keyImportOptions, Context context) { + Mono> importKeyWithResponse(KeyImportOptions keyImportOptions, Context context) { Objects.requireNonNull(keyImportOptions, "The key import configuration parameter cannot be null."); KeyImportRequestParameters parameters = new KeyImportRequestParameters() .key(keyImportOptions.keyMaterial()) @@ -430,12 +424,7 @@ Mono> importKey(KeyImportOptions keyImportOptions, Context context */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getKey(String name, String version) { - if (version == null) { - return getKeyWithResponse(name) - .flatMap(FluxUtil::toMono); - } - return withContext(context -> getKeyWithResponse(name, version)) - .flatMap(FluxUtil::toMono); + return getKeyWithResponse(name, version).flatMap(FluxUtil::toMono); } /** @@ -455,13 +444,10 @@ public Mono getKey(String name, String version) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getKeyWithResponse(String name, String version) { - if (version == null) { - return getKeyWithResponse(name); - } - return withContext(context -> getKey(name, version, context)); + return withContext(context -> getKeyWithResponse(name, version == null ? "" : version, context)); } - Mono> getKey(String name, String version, Context context) { + Mono> getKeyWithResponse(String name, String version, Context context) { return service.getKey(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Retrieving key - {}", name)) .doOnSuccess(response -> logger.info("Retrieved key - {}", response.value().name())) @@ -485,28 +471,7 @@ Mono> getKey(String name, String version, Context context) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getKey(String name) { - return getKeyWithResponse(name, "") - .flatMap(FluxUtil::toMono); - } - - /** - * Get the public part of the latest version of the specified key from the key vault. The get key operation is applicable to - * all key types and it requires the {@code keys/get} permission. - * - *

Code Samples

- *

Gets latest version of the key in the key vault. Subscribes to the call asynchronously and prints out the - * returned key details when a response has been received.

- * - * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string} - * - * @param name The name of the key. - * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault. - * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getKeyWithResponse(String name) { - return getKeyWithResponse(name, ""); + return getKeyWithResponse(name, "").flatMap(FluxUtil::toMono); } /** @@ -526,13 +491,7 @@ public Mono> getKeyWithResponse(String name) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getKey(KeyBase keyBase) { - Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null."); - if (keyBase.version() == null) { - return getKeyWithResponse(keyBase.name()) - .flatMap(FluxUtil::toMono); - } - return getKeyWithResponse(keyBase.name(), keyBase.version()) - .flatMap(FluxUtil::toMono); + return getKeyWithResponse(keyBase).flatMap(FluxUtil::toMono); } /** @@ -553,10 +512,7 @@ public Mono getKey(KeyBase keyBase) { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getKeyWithResponse(KeyBase keyBase) { Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null."); - if (keyBase.version() == null) { - return getKeyWithResponse(keyBase.name()); - } - return getKeyWithResponse(keyBase.name(), keyBase.version()); + return withContext(context -> getKeyWithResponse(keyBase.name(), keyBase.version() == null ? "" : keyBase.version(), context)); } /** @@ -578,33 +534,10 @@ public Mono> getKeyWithResponse(KeyBase keyBase) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateKey(KeyBase key) { - return withContext(context -> updateKeyWithResponse(key)) - .flatMap(FluxUtil::toMono); - } - - /** - * Updates the attributes associated with the specified key, but not the cryptographic key material of the specified key in the key vault. The update - * operation changes specified attributes of an existing stored key and attributes that are not specified in the request are left unchanged. - * The cryptographic key material of a key itself cannot be changed. This operation requires the {@code keys/set} permission. - * - *

Code Samples

- *

Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the - * returned key details when a response has been received.

- * - * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase} - * - * @param key The {@link KeyBase base key} object with updated properties. - * @throws NullPointerException if {@code key} is {@code null}. - * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. - * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string. - * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateKeyWithResponse(KeyBase key) { - return withContext(context -> updateKey(key, context)); + return withContext(context -> updateKeyWithResponse(key, context).flatMap(FluxUtil::toMono)); } - Mono> updateKey(KeyBase key, Context context) { + Mono> updateKeyWithResponse(KeyBase key, Context context) { Objects.requireNonNull(key, "The key input parameter cannot be null."); KeyRequestParameters parameters = new KeyRequestParameters() .tags(key.tags()) @@ -635,7 +568,7 @@ Mono> updateKey(KeyBase key, Context context) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> updateKeyWithResponse(KeyBase key, KeyOperation... keyOperations) { - return withContext(context -> updateKey(key, context, keyOperations)); + return withContext(context -> updateKeyWithResponse(key, context, keyOperations)); } /** @@ -658,11 +591,10 @@ public Mono> updateKeyWithResponse(KeyBase key, KeyOperation... ke */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateKey(KeyBase key, KeyOperation... keyOperations) { - return withContext(context -> updateKeyWithResponse(key, keyOperations)) - .flatMap(FluxUtil::toMono); + return updateKeyWithResponse(key, keyOperations).flatMap(FluxUtil::toMono); } - Mono> updateKey(KeyBase key, Context context, KeyOperation... keyOperations) { + Mono> updateKeyWithResponse(KeyBase key, Context context, KeyOperation... keyOperations) { Objects.requireNonNull(key, "The key input parameter cannot be null."); KeyRequestParameters parameters = new KeyRequestParameters() .tags(key.tags()) @@ -694,8 +626,7 @@ Mono> updateKey(KeyBase key, Context context, KeyOperation... keyO */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteKey(String name) { - return withContext(context -> deleteKeyWithResponse(name)) - .flatMap(FluxUtil::toMono); + return deleteKeyWithResponse(name).flatMap(FluxUtil::toMono); } /** @@ -718,10 +649,10 @@ public Mono deleteKey(String name) { */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteKeyWithResponse(String name) { - return withContext(context -> deleteKey(name, context)); + return withContext(context -> deleteKeyWithResponse(name, context)); } - Mono> deleteKey(String name, Context context) { + Mono> deleteKeyWithResponse(String name, Context context) { return service.deleteKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Deleting key - {}", name)) .doOnSuccess(response -> logger.info("Deleted key - {}", response.value().name())) @@ -735,7 +666,6 @@ Mono> deleteKey(String name, Context context) { *

Code Samples

*

Gets the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the * deleted key details when a response has been received.

- *
      * //Assuming key is deleted on a soft-delete enabled vault.
      *
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getDeletedKey#string}
@@ -747,8 +677,7 @@ Mono> deleteKey(String name, Context context) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono getDeletedKey(String name) {
-        return withContext(context -> getDeletedKeyWithResponse(name))
-            .flatMap(FluxUtil::toMono);
+        return getDeletedKeyWithResponse(name).flatMap(FluxUtil::toMono);
     }
 
     /**
@@ -758,7 +687,6 @@ public Mono getDeletedKey(String name) {
      * 

Code Samples

*

Gets the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the * deleted key details when a response has been received.

- *
      * //Assuming key is deleted on a soft-delete enabled vault.
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getDeletedKeyWithResponse#string}
      *
@@ -769,10 +697,10 @@ public Mono getDeletedKey(String name) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono> getDeletedKeyWithResponse(String name) {
-        return withContext(context -> getDeletedKey(name, context));
+        return withContext(context -> getDeletedKeyWithResponse(name, context));
     }
 
-    Mono> getDeletedKey(String name, Context context) {
+    Mono> getDeletedKeyWithResponse(String name, Context context) {
         return service.getDeletedKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Retrieving deleted key - {}",  name))
                 .doOnSuccess(response -> logger.info("Retrieved deleted key - {}", response.value().name()))
@@ -786,7 +714,6 @@ Mono> getDeletedKey(String name, Context context) {
      * 

Code Samples

*

Purges the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the * status code from the server response when a response has been received.

- *
      * //Assuming key is deleted on a soft-delete enabled vault.
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.purgeDeletedKey#string}
      *
@@ -815,7 +742,6 @@ Mono purgeDeletedKey(String name, Context context) {
      * 

Code Samples

*

Recovers the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the * recovered key details when a response has been received.

- *
      * //Assuming key is deleted on a soft-delete enabled vault.
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKey#string}
      *
@@ -826,8 +752,7 @@ Mono purgeDeletedKey(String name, Context context) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono recoverDeletedKey(String name) {
-        return withContext(context -> recoverDeletedKeyWithResponse(name))
-            .flatMap(FluxUtil::toMono);
+        return recoverDeletedKeyWithResponse(name).flatMap(FluxUtil::toMono);
     }
 
     /**
@@ -838,7 +763,6 @@ public Mono recoverDeletedKey(String name) {
      * 

Code Samples

*

Recovers the deleted key from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the * recovered key details when a response has been received.

- *
      * //Assuming key is deleted on a soft-delete enabled vault.
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.recoverDeletedKeyWithResponse#string}
      *
@@ -849,10 +773,10 @@ public Mono recoverDeletedKey(String name) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono> recoverDeletedKeyWithResponse(String name) {
-        return withContext(context -> recoverDeletedKey(name, context));
+        return withContext(context -> recoverDeletedKeyWithResponse(name, context));
     }
 
-    Mono> recoverDeletedKey(String name, Context context) {
+    Mono> recoverDeletedKeyWithResponse(String name, Context context) {
         return service.recoverDeletedKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Recovering deleted key - {}",  name))
                 .doOnSuccess(response -> logger.info("Recovered deleted key - {}", response.value().name()))
@@ -882,8 +806,7 @@ Mono> recoverDeletedKey(String name, Context context) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono backupKey(String name) {
-        return withContext(context -> backupKeyWithResponse(name))
-            .flatMap(FluxUtil::toMono);
+        return backupKeyWithResponse(name).flatMap(FluxUtil::toMono);
     }
 
     /**
@@ -909,10 +832,10 @@ public Mono backupKey(String name) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono> backupKeyWithResponse(String name) {
-        return withContext(context -> backupKey(name, context));
+        return withContext(context -> backupKeyWithResponse(name, context));
     }
 
-    Mono> backupKey(String name, Context context) {
+    Mono> backupKeyWithResponse(String name, Context context) {
         return service.backupKey(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Backing up key - {}",  name))
                 .doOnSuccess(response -> logger.info("Backed up key - {}", name))
@@ -933,7 +856,6 @@ Mono> backupKey(String name, Context context) {
      * 

Code Samples

*

Restores the key in the key vault from its backup. Subscribes to the call asynchronously and prints out the restored key * details when a response has been received.

- *
      * //Pass the Key Backup Byte array to the restore operation.
      *
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.restoreKey#byte}
@@ -944,8 +866,7 @@ Mono> backupKey(String name, Context context) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono restoreKey(byte[] backup) {
-        return withContext(context -> restoreKeyWithResponse(backup))
-            .flatMap(FluxUtil::toMono);
+        return restoreKeyWithResponse(backup).flatMap(FluxUtil::toMono);
     }
 
     /**
@@ -960,7 +881,6 @@ public Mono restoreKey(byte[] backup) {
      * 

Code Samples

*

Restores the key in the key vault from its backup. Subscribes to the call asynchronously and prints out the restored key * details when a response has been received.

- *
      * //Pass the Key Backup Byte array to the restore operation.
      *
      * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.restoreKeyWithResponse#byte}
@@ -971,10 +891,10 @@ public Mono restoreKey(byte[] backup) {
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
     public Mono> restoreKeyWithResponse(byte[] backup) {
-        return withContext(context -> restoreKey(backup, context));
+        return withContext(context -> restoreKeyWithResponse(backup, context));
     }
 
-    Mono> restoreKey(byte[] backup, Context context) {
+    Mono> restoreKeyWithResponse(byte[] backup, Context context) {
         KeyRestoreRequestParameters parameters = new KeyRestoreRequestParameters().keyBackup(backup);
         return service.restoreKey(endpoint, API_VERSION, parameters, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Attempting to restore key"))
diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
index 517883dd328fb..13653b711a1e9 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
@@ -66,7 +66,7 @@ public final class KeyClient {
      * @return The {@link Key created key}.
      */
     public Key createKey(String name, KeyType keyType) {
-        return client.createKey(name, keyType, Context.NONE).block().value();
+        return client.createKeyWithResponse(name, keyType, Context.NONE).block().value();
     }
 
     /**
@@ -90,7 +90,7 @@ public Key createKey(String name, KeyType keyType) {
      * @return The {@link Key created key}.
      */
     public Key createKey(KeyCreateOptions keyCreateOptions) {
-        return this.createKeyWithResponse(keyCreateOptions, Context.NONE).value();
+        return createKeyWithResponse(keyCreateOptions, Context.NONE).value();
     }
 
     /**
@@ -115,7 +115,7 @@ public Key createKey(KeyCreateOptions keyCreateOptions) {
      * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}.
      */
     public Response createKeyWithResponse(KeyCreateOptions keyCreateOptions, Context context) {
-        return client.createKey(keyCreateOptions, context).block();
+        return client.createKeyWithResponse(keyCreateOptions, context).block();
     }
 
     /**
@@ -140,7 +140,7 @@ public Response createKeyWithResponse(KeyCreateOptions keyCreateOptions, Co
      * @return The {@link Key created key}.
      */
     public Key createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) {
-        return this.createKeyWithResponse(rsaKeyCreateOptions, Context.NONE).value();
+        return createRsaKeyWithResponse(rsaKeyCreateOptions, Context.NONE).value();
     }
 
     /**
@@ -156,7 +156,7 @@ public Key createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) {
      *
      * 

Code Samples

*

Creates a new RSA key with size 2048 which activates in one day and expires in one year. Prints out the details of the created key.

- * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions} + * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context} * * @param rsaKeyCreateOptions The key options object containing information about the rsa key being created. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -166,7 +166,7 @@ public Key createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. */ public Response createRsaKeyWithResponse(RsaKeyCreateOptions rsaKeyCreateOptions, Context context) { - return client.createRsaKey(rsaKeyCreateOptions, context).block(); + return client.createRsaKeyWithResponse(rsaKeyCreateOptions, context).block(); } /** @@ -192,7 +192,7 @@ public Response createRsaKeyWithResponse(RsaKeyCreateOptions rsaKeyCreateOp * @return The {@link Key created key}. */ public Key createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { - return this.createEcKeyWithResponse(ecKeyCreateOptions, Context.NONE).value(); + return createEcKeyWithResponse(ecKeyCreateOptions, Context.NONE).value(); } /** @@ -209,7 +209,7 @@ public Key createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { *

Code Samples

*

Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Prints out * the details of the created key.

- * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions} + * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context} * * @param ecKeyCreateOptions The key options object containing information about the ec key being created. * @param context Additional context that is passed through the Http pipeline during the service call. @@ -219,7 +219,7 @@ public Key createEcKey(EcKeyCreateOptions ecKeyCreateOptions) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key created key}. */ public Response createEcKeyWithResponse(EcKeyCreateOptions ecKeyCreateOptions, Context context) { - return client.createEcKey(ecKeyCreateOptions, context).block(); + return client.createEcKeyWithResponse(ecKeyCreateOptions, context).block(); } /** @@ -239,7 +239,7 @@ public Response createEcKeyWithResponse(EcKeyCreateOptions ecKeyCreateOptio * @return The {@link Key imported key}. */ public Key importKey(String name, JsonWebKey keyMaterial) { - return client.importKey(name, keyMaterial, Context.NONE).block().value(); + return client.importKeyWithResponse(name, keyMaterial, Context.NONE).block().value(); } /** @@ -268,7 +268,7 @@ public Key importKey(String name, JsonWebKey keyMaterial) { * @return The {@link Key imported key}. */ public Key importKey(KeyImportOptions keyImportOptions) { - return this.importKeyWithResponse(keyImportOptions, Context.NONE).value(); + return importKeyWithResponse(keyImportOptions, Context.NONE).value(); } /** @@ -298,7 +298,7 @@ public Key importKey(KeyImportOptions keyImportOptions) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key imported key}. */ public Response importKeyWithResponse(KeyImportOptions keyImportOptions, Context context) { - return client.importKey(keyImportOptions, context).block(); + return client.importKeyWithResponse(keyImportOptions, context).block(); } /** @@ -315,7 +315,7 @@ public Response importKeyWithResponse(KeyImportOptions keyImportOptions, Co * @return The requested {@link Key key}. */ public Key getKey(String name, String version) { - return this.getKeyWithResponse(name, version, Context.NONE).value(); + return getKeyWithResponse(name, version, Context.NONE).value(); } /** @@ -333,7 +333,7 @@ public Key getKey(String name, String version) { * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. */ public Response getKeyWithResponse(String name, String version, Context context) { - return client.getKey(name, version, context).block(); + return client.getKeyWithResponse(name, version, context).block(); } /** @@ -350,7 +350,7 @@ public Response getKeyWithResponse(String name, String version, Context con * @return The requested {@link Key key}. */ public Key getKey(String name) { - return this.getKeyWithResponse(name, "", Context.NONE).value(); + return getKeyWithResponse(name, "", Context.NONE).value(); } /** @@ -368,11 +368,27 @@ public Key getKey(String name) { * @return The requested {@link Key key}. */ public Key getKey(KeyBase keyBase) { + return getKeyWithResponse(keyBase, Context.NONE).value(); + } + + /** + * Get public part of the key which represents {@link KeyBase keyBase} from the key vault. The get key operation is applicable + * to all key types and it requires the {@code keys/get} permission. + * + *

The list operations {@link KeyClient#listKeys()} and {@link KeyClient#listKeyVersions(String)} return + * the {@link List} containing {@link KeyBase base key} as output excluding the key material of the key. + * This operation can then be used to get the full key with its key material from {@code keyBase}.

+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context} + * + * @param keyBase The {@link KeyBase base key} holding attributes of the key being requested. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link KeyBase#name()} name} or {@link KeyBase#version() version} is empty string. + * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}. + */ + public Response getKeyWithResponse(KeyBase keyBase, Context context) { Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null."); - if (keyBase.version() == null) { - return getKey(keyBase.name()); - } - return getKeyWithResponse(keyBase.name(), keyBase.version(), Context.NONE).value(); + return client.getKeyWithResponse(keyBase.name(), keyBase.version() == null ? "" : keyBase.version(), context).block(); } /** @@ -391,7 +407,7 @@ public Key getKey(KeyBase keyBase) { * @return The {@link KeyBase updated key}. */ public Key updateKey(KeyBase key) { - return this.updateKeyWithResponse(key, Context.NONE).value(); + return client.updateKeyWithResponse(key, Context.NONE).block().value(); } /** @@ -411,7 +427,7 @@ public Key updateKey(KeyBase key) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}. */ public Key updateKey(KeyBase key, KeyOperation... keyOperations) { - return this.updateKeyWithResponse(key, Context.NONE, keyOperations).value(); + return updateKeyWithResponse(key, Context.NONE, keyOperations).value(); } /** @@ -432,7 +448,7 @@ public Key updateKey(KeyBase key, KeyOperation... keyOperations) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}. */ public Response updateKeyWithResponse(KeyBase key, Context context, KeyOperation... keyOperations) { - return client.updateKey(key, context, keyOperations).block(); + return client.updateKeyWithResponse(key, context, keyOperations).block(); } /** @@ -452,7 +468,7 @@ public Response updateKeyWithResponse(KeyBase key, Context context, KeyOpe * @return The {@link DeletedKey deleted key}. */ public DeletedKey deleteKey(String name) { - return this.deleteKeyWithResponse(name, Context.NONE).value(); + return deleteKeyWithResponse(name, Context.NONE).value(); } /** @@ -473,7 +489,7 @@ public DeletedKey deleteKey(String name) { * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedKey deleted key}. */ public Response deleteKeyWithResponse(String name, Context context) { - return client.deleteKey(name, context).block(); + return client.deleteKeyWithResponse(name, context).block(); } /** @@ -483,7 +499,6 @@ public Response deleteKeyWithResponse(String name, Context context) *

Code Samples

*

Gets the deleted key from the key vault enabled for soft-delete. Prints out the details of the deleted key * returned in the response.

- *
      * //Assuming key is deleted on a soft-delete enabled key vault.
      * {@codesnippet com.azure.keyvault.keys.keyclient.getDeletedKey#string}
      * 
@@ -494,7 +509,7 @@ public Response deleteKeyWithResponse(String name, Context context) * @return The {@link DeletedKey deleted key}. */ public DeletedKey getDeletedKey(String name) { - return this.getDeletedKeyWithResponse(name, Context.NONE).value(); + return getDeletedKeyWithResponse(name, Context.NONE).value(); } /** @@ -504,7 +519,6 @@ public DeletedKey getDeletedKey(String name) { *

Code Samples

*

Gets the deleted key from the key vault enabled for soft-delete. Prints out the details of the deleted key * returned in the response.

- *
      * //Assuming key is deleted on a soft-delete enabled key vault.
      * {@codesnippet com.azure.keyvault.keys.keyclient.getDeletedKeyWithResponse#string-Context}
      *
@@ -515,7 +529,7 @@ public DeletedKey getDeletedKey(String name) {
      * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedKey deleted key}.
      */
     public Response getDeletedKeyWithResponse(String name, Context context) {
-        return client.getDeletedKey(name, context).block();
+        return client.getDeletedKeyWithResponse(name, context).block();
     }
 
     /**
@@ -533,7 +547,7 @@ public Response getDeletedKeyWithResponse(String name, Context conte
      * @return A {@link VoidResponse}.
      */
     public VoidResponse purgeDeletedKey(String name) {
-        return client.purgeDeletedKey(name, Context.NONE).block();
+        return purgeDeletedKey(name, Context.NONE);
     }
 
     /**
@@ -571,7 +585,7 @@ public VoidResponse purgeDeletedKey(String name, Context context) {
      * @return The {@link Key recovered key}.
      */
     public Key recoverDeletedKey(String name) {
-        return this.recoverDeletedKeyWithResponse(name, Context.NONE).value();
+        return recoverDeletedKeyWithResponse(name, Context.NONE).value();
     }
 
     /**
@@ -591,7 +605,7 @@ public Key recoverDeletedKey(String name) {
      * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key recovered key}.
      */
     public Response recoverDeletedKeyWithResponse(String name, Context context) {
-        return client.recoverDeletedKey(name, context).block();
+        return client.recoverDeletedKeyWithResponse(name, context).block();
     }
 
     /**
@@ -614,7 +628,7 @@ public Response recoverDeletedKeyWithResponse(String name, Context context)
      * @return The backed up key blob.
      */
     public byte[] backupKey(String name) {
-        return this.backupKeyWithResponse(name, Context.NONE).value();
+        return backupKeyWithResponse(name, Context.NONE).value();
     }
 
     /**
@@ -638,7 +652,7 @@ public byte[] backupKey(String name) {
      * @return A {@link Response} whose {@link Response#value() value} contains the backed up key blob.
      */
     public Response backupKeyWithResponse(String name, Context context) {
-        return client.backupKey(name, context).block();
+        return client.backupKeyWithResponse(name, context).block();
     }
 
     /**
@@ -660,7 +674,7 @@ public Response backupKeyWithResponse(String name, Context context) {
      * @return The {@link Key restored key}.
      */
     public Key restoreKey(byte[] backup) {
-        return this.restoreKeyWithResponse(backup, Context.NONE).value();
+        return restoreKeyWithResponse(backup, Context.NONE).value();
     }
 
     /**
@@ -683,7 +697,7 @@ public Key restoreKey(byte[] backup) {
      * @return A {@link Response} whose {@link Response#value() value} contains the {@link Key restored key}.
      */
     public Response restoreKeyWithResponse(byte[] backup, Context context) {
-        return client.restoreKey(backup, context).block();
+        return client.restoreKeyWithResponse(backup, context).block();
     }
 
     /**
@@ -698,7 +712,7 @@ public Response restoreKeyWithResponse(byte[] backup, Context context) {
      * @return A {@link List} containing {@link KeyBase key} of all the keys in the vault.
      */
     public Iterable listKeys() {
-        return client.listKeys(Context.NONE).toIterable();
+        return listKeys(Context.NONE);
     }
 
     /**
@@ -729,7 +743,7 @@ public Iterable listKeys(Context context) {
      * @return A {@link List} containing all of the {@link DeletedKey deleted keys} in the vault.
      */
     public Iterable listDeletedKeys() {
-        return client.listDeletedKeys().toIterable();
+        return listDeletedKeys(Context.NONE);
     }
 
     /**
@@ -763,7 +777,7 @@ public Iterable listDeletedKeys(Context context) {
      * @return A {@link List} containing {@link KeyBase key} of all the versions of the specified key in the vault. List is empty if key with {@code name} does not exist in key vault.
      */
     public Iterable listKeyVersions(String name) {
-        return client.listKeyVersions(name).toIterable();
+        return listKeyVersions(name, Context.NONE);
     }
 
     /**
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java
index 50b5e387cf027..954b5e27d6be8 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorld.java
@@ -3,6 +3,8 @@
 
 package com.azure.security.keyvault.keys;
 
+import com.azure.core.http.rest.Response;
+import com.azure.core.util.Context;
 import com.azure.identity.credential.DefaultAzureCredential;
 import com.azure.security.keyvault.keys.models.Key;
 import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
@@ -33,9 +35,12 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum
 
         // Let's create a Rsa key valid for 1 year. if the key
         // already exists in the key vault, then a new version of the key is created.
-        keyClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
-                .expires(OffsetDateTime.now().plusYears(1))
-                .keySize(2048));
+        Response createKeyResponse = keyClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
+                                                                                 .expires(OffsetDateTime.now().plusYears(1))
+                                                                                 .keySize(2048), new Context("key1", "value1"));
+
+        // Let's validate create key operation succeeded using the status code information in the response.
+        System.out.printf("Create Key operation succeeded with status code %s \n", createKeyResponse.statusCode());
 
         // Let's Get the Cloud Rsa Key from the key vault.
         Key cloudRsaKey = keyClient.getKey("CloudRsaKey");
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java
index 922548455aecf..7dddc982ca9d4 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/HelloWorldAsync.java
@@ -3,9 +3,11 @@
 
 package com.azure.security.keyvault.keys;
 
+import com.azure.core.http.rest.Response;
 import com.azure.identity.credential.DefaultAzureCredential;
 import com.azure.security.keyvault.keys.models.Key;
 import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
+import reactor.core.Disposable;
 
 import java.time.OffsetDateTime;
 
@@ -32,11 +34,13 @@ public static void main(String[] args) throws InterruptedException {
 
         // Let's create Cloud Rsa key valid for 1 year. if the key
         // already exists in the key vault, then a new version of the key is created.
-        keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
-                .expires(OffsetDateTime.now().plusYears(1))
-                .keySize(2048))
-                .subscribe(keyResponse ->
-                        System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()));
+        Response createKeyResponse = keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
+                                                                                                .expires(OffsetDateTime.now().plusYears(1))
+                                                                                                .keySize(2048)).block();
+
+        // Let's validate create key operation succeeded using the status code information in the response.
+        System.out.printf("Create Key operation succeeded with status code %s \n", createKeyResponse.statusCode());
+        System.out.printf("Key is created with name %s and type %s \n", createKeyResponse.value().name(), createKeyResponse.value().keyMaterial().kty());
 
         Thread.sleep(2000);
 
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
index 12eacca66a16d..1ecb1479fd7ff 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
@@ -12,7 +12,6 @@
 import com.azure.core.test.policy.RecordNetworkCallPolicy;
 import com.azure.identity.credential.DefaultAzureCredential;
 import com.azure.security.keyvault.keys.models.EcKeyCreateOptions;
-import com.azure.security.keyvault.keys.models.Key;
 import com.azure.security.keyvault.keys.models.KeyBase;
 import com.azure.security.keyvault.keys.models.KeyCreateOptions;
 import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
@@ -209,14 +208,6 @@ public void getKeyWithResponseSnippets() {
                     keyResponse.value().name(), keyResponse.value().id()));
         // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string-string
 
-        // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string
-        keyAsyncClient.getKeyWithResponse("keyName")
-            .subscriberContext(Context.of(key1, value1, key2, value2))
-            .subscribe(keyResponse ->
-                System.out.printf("Key is created with name %s and id %s \n",
-                    keyResponse.value().name(), keyResponse.value().id()));
-        // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string
-
         // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#KeyBase
         keyAsyncClient.listKeys().subscribe(keyBase ->
             keyAsyncClient.getKeyWithResponse(keyBase)
@@ -263,12 +254,11 @@ public void updateKeyWithResponseSnippets() {
         KeyAsyncClient keyAsyncClient = createAsyncClient();
 
         // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations
-        keyAsyncClient.getKeyWithResponse("keyName")
+        keyAsyncClient.getKey("keyName")
             .subscribe(keyResponse  -> {
-                Key key = keyResponse.value();
                 //Update the not before time of the key.
-                key.notBefore(OffsetDateTime.now().plusDays(50));
-                keyAsyncClient.updateKeyWithResponse(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
+                keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
+                keyAsyncClient.updateKeyWithResponse(keyResponse, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
                     .subscriberContext(Context.of(key1, value1, key2, value2))
                     .subscribe(updatedKeyResponse  ->
                         System.out.printf("Key's updated not before time %s \n",
@@ -277,12 +267,11 @@ public void updateKeyWithResponseSnippets() {
         // END: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations
 
         // BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase
-        keyAsyncClient.getKeyWithResponse("keyName")
+        keyAsyncClient.getKey("keyName")
             .subscribe(keyResponse  -> {
-                Key key = keyResponse.value();
                 //Update the not before time of the key.
-                key.notBefore(OffsetDateTime.now().plusDays(50));
-                keyAsyncClient.updateKeyWithResponse(key)
+                keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
+                keyAsyncClient.updateKeyWithResponse(keyResponse)
                     .subscriberContext(Context.of(key1, value1, key2, value2))
                     .subscribe(updatedKeyResponse  ->
                         System.out.printf("Key's updated not before time %s \n",
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
index c2e2caedfee11..6288ff490aa5a 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
@@ -4,10 +4,6 @@
 package com.azure.security.keyvault.keys;
 
 import com.azure.core.credentials.TokenCredential;
-import com.azure.core.http.HttpClient;
-import com.azure.core.http.HttpPipeline;
-import com.azure.core.http.HttpPipelineBuilder;
-import com.azure.core.http.policy.HttpLogDetailLevel;
 import com.azure.core.http.rest.Response;
 import com.azure.core.http.rest.VoidResponse;
 import com.azure.core.util.Context;
@@ -123,23 +119,23 @@ public void createKeyWithResponses() {
         System.out.printf("Key is created with name %s and id %s \n", optionsKey.name(), optionsKey.id());
         // END: com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context
 
-        // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
+        // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context
         RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName")
             .keySize(2048)
             .notBefore(OffsetDateTime.now().plusDays(1))
             .expires(OffsetDateTime.now().plusYears(1));
         Key rsaKey = keyClient.createRsaKeyWithResponse(rsaKeyCreateOptions, new Context(key1, value1)).value();
         System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id());
-        // END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
+        // END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context
 
-        // BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
+        // BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
         EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName")
             .curve(KeyCurveName.P_384)
             .notBefore(OffsetDateTime.now().plusDays(1))
             .expires(OffsetDateTime.now().plusYears(1));
         Key ecKey = keyClient.createEcKeyWithResponse(ecKeyCreateOptions, new Context(key1, value1)).value();
         System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id());
-        // END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
+        // END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
     }
 
     /**
@@ -153,6 +149,14 @@ public void getKeyWithResponseSnippets() {
             new Context(key1, value1)).value();
         System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id());
         // END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context
+
+        // BEGIN: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
+        for (KeyBase key : keyClient.listKeys()) {
+            Key keyResponse = keyClient.getKeyWithResponse(key, new Context(key1, value1)).value();
+            System.out.printf("Received key with name %s and type %s", keyResponse.name(),
+                keyResponse.keyMaterial().kty());
+        }
+        // END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
     }
 
     /**
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
index 35ab9c7b1902f..74ff3fa9fbcfa 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
@@ -39,10 +39,10 @@ public static void main(String[] args) throws InterruptedException {
 
         Thread.sleep(2000);
 
-        keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
+        keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
                 .expires(OffsetDateTime.now().plusYears(1)))
                 .subscribe(keyResponse ->
-                        System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty()));
+                        System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()));
 
         Thread.sleep(2000);
 
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 836e32d0ebfc2..af394d45d880b 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -13,6 +13,7 @@
 import com.azure.core.implementation.annotation.ReturnType;
 import com.azure.core.implementation.annotation.ServiceClient;
 import com.azure.core.implementation.annotation.ServiceMethod;
+import com.azure.core.implementation.util.FluxUtil;
 import com.azure.core.util.Context;
 import com.azure.core.util.logging.ClientLogger;
 import com.azure.security.keyvault.secrets.models.DeletedSecret;
@@ -36,7 +37,7 @@
  * also supports listing {@link DeletedSecret deleted secrets} for a soft-delete enabled Azure Key Vault.
  *
  * 

Samples to construct the async client

- * {@codesnippet com.azure.security.keyvault.secretclient.async.construct} + * {@codesnippet com.azure.security.keyvault.secrets.async.secretclient.construct} * * @see SecretClientBuilder * @see PagedFlux @@ -76,14 +77,31 @@ public final class SecretAsyncClient { *

Code Samples

*

Creates a new secret which activates in 1 day and expires in 1 year in the Azure Key Vault. Subscribes to the call asynchronously and * prints out the newly created secret details when a response is received.

- *
-     * Secret secret = new Secret("secretName", "secretValue")
-     *   .notBefore(OffsetDateTime.now().plusDays(1))
-     *   .expires(OffsetDateTime.now().plusDays(365));
+     * {@codesnippet com.azure.keyvault.secrets.secretclient.setSecret#secret}
      *
-     * secretAsyncClient.setSecret(secret).subscribe(secretResponse ->
-     *   System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
-     * 
+ * @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null. + * @throws NullPointerException if {@code secret} is {@code null}. + * @throws ResourceModifiedException if {@code secret} is malformed. + * @throws HttpRequestException if {@link Secret#name() name} or {@link Secret#value() value} is empty string. + * @return A {@link Mono} containing the {@link Secret created secret}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono setSecret(Secret secret) { + return setSecretWithResponse(secret).flatMap(FluxUtil::toMono); + } + + /** + * The set operation adds a secret to the key vault. If the named secret already exists, Azure Key Vault creates + * a new version of that secret. This operation requires the {@code secrets/set} permission. + * + *

The {@link Secret} is required. The {@link Secret#expires() expires}, {@link Secret#contentType() contentType} and + * {@link Secret#notBefore() notBefore} values in {@code secret} are optional. The {@link Secret#enabled() enabled} field is + * set to true by key vault, if not specified.

+ * + *

Code Samples

+ *

Creates a new secret which activates in 1 day and expires in 1 year in the Azure Key Vault. Subscribes to the call asynchronously and + * prints out the newly created secret details when a response is received.

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.setSecretWithResponse#secret} * * @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null. * @throws NullPointerException if {@code secret} is {@code null}. @@ -92,11 +110,11 @@ public final class SecretAsyncClient { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> setSecret(Secret secret) { - return withContext(context -> setSecret(secret, context)); + public Mono> setSecretWithResponse(Secret secret) { + return withContext(context -> setSecretWithResponse(secret, context)); } - Mono> setSecret(Secret secret, Context context) { + Mono> setSecretWithResponse(Secret secret, Context context) { Objects.requireNonNull(secret, "The Secret input parameter cannot be null."); SecretRequestParameters parameters = new SecretRequestParameters() .value(secret.value()) @@ -118,24 +136,20 @@ Mono> setSecret(Secret secret, Context context) { *

Code Samples

*

Creates a new secret in the key vault. Subscribes to the call asynchronously and prints out * the newly created secret details when a response is received.

- *
-     * secretAsyncClient.setSecret("secretName", "secretValue").subscribe(secretResponse ->
-     *   System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.setSecret#string-string} * * @param name The name of the secret. It is required and cannot be null. * @param value The value of the secret. It is required and cannot be null. - * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} - * contains the {@link Secret created secret}. + * @return A {@link Mono} containing the {@link Secret created secret}. * @throws ResourceModifiedException if invalid {@code name} or {@code value} are specified. * @throws HttpRequestException if {@code name} or {@code value} is empty string. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> setSecret(String name, String value) { - return withContext(context -> setSecret(name, value, context)); + public Mono setSecret(String name, String value) { + return withContext(context -> setSecretWithResponse(name, value, context)).flatMap(FluxUtil::toMono); } - Mono> setSecret(String name, String value, Context context) { + Mono> setSecretWithResponse(String name, String value, Context context) { SecretRequestParameters parameters = new SecretRequestParameters().value(value); return service.setSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, parameters, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Setting secret - {}", name)) @@ -152,12 +166,33 @@ Mono> setSecret(String name, String value, Context context) { *

Gets a specific version of the secret in the key vault. Subscribes to the call * asynchronously and prints out the * returned secret details when a response is received.

- *
-     * String secretVersion = "6A385B124DEF4096AF1361A85B16C204";
-     * secretAsyncClient.getSecret("secretName", secretVersion).subscribe(secretResponse ->
-     *   System.out.printf("Secret with name %s, value %s and version %s", secretResponse.value().name(),
-     *   secretResponse.value().value(), secretResponse.value().version()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#string-string} + * + * @param name The name of the secret, cannot be null + * @param version The version of the secret to retrieve. If this is an empty String or null, this + * call is equivalent to calling {@link #getSecret(String)}, with the latest version being + * retrieved. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} + * contains the requested {@link Secret secret}. + * @throws ResourceNotFoundException when a secret with {@code name} and {@code version} doesn't + * exist in the key vault. + * @throws HttpRequestException if {@code name} name} or {@code version} is empty string. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSecret(String name, String version) { + return getSecretWithResponse(name, version).flatMap(FluxUtil::toMono); + } + + /** + * Get the specified secret with specified version from the key vault. The get operation is + * applicable to any secret stored in Azure Key Vault. This operation requires the {@code + * secrets/get} permission. + * + *

Code Samples

+ *

Gets a specific version of the secret in the key vault. Subscribes to the call + * asynchronously and prints out the + * returned secret details when a response is received.

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecretWithResponse#string-string} * * @param name The name of the secret, cannot be null * @param version The version of the secret to retrieve. If this is an empty String or null, this @@ -170,19 +205,40 @@ Mono> setSecret(String name, String value, Context context) { * @throws HttpRequestException if {@code name} name} or {@code version} is empty string. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSecret(String name, String version) { - return withContext(context -> getSecret(name, version, context)); + public Mono> getSecretWithResponse(String name, String version) { + return withContext(context -> getSecretWithResponse(name, version, context)); } - Mono> getSecret(String name, String version, Context context) { - if (version == null) { - return getSecret(name); - } + Mono> getSecretWithResponse(String name, String version, Context context) { + return service.getSecret(endpoint, name, version == null ? "" : version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) + .doOnRequest(ignoredValue -> logger.info("Retrieving secret - {}", name)) + .doOnSuccess(response -> logger.info("Retrieved secret - {}", response.value().name())) + .doOnError(error -> logger.warning("Failed to get secret - {}", name, error)); + } - return service.getSecret(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) - .doOnRequest(ignoredValue -> logger.info("Retrieving secret - {}", name)) - .doOnSuccess(response -> logger.info("Retrieved secret - {}", response.value().name())) - .doOnError(error -> logger.warning("Failed to get secret - {}", name, error)); + /** + * Get the secret which represents {@link SecretBase secretBase} from the key vault. The get + * operation is applicable to any secret stored in Azure Key Vault. This operation requires the + * {@code secrets/get} permission. + * + *

The list operations {@link SecretAsyncClient#listSecrets()} and {@link + * SecretAsyncClient#listSecretVersions(String)} return + * the {@link Flux} containing {@link SecretBase base secret} as output. This operation can then be used to get + * the full secret with its value from {@code secretBase}.

+ *

Code Samples

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#secretBase} + * + * @param secretBase The {@link SecretBase base secret} secret base holding attributes of the + * secret being requested. + * @return A {@link Mono} containing the requested {@link Secret secret}. + * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link + * SecretBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version() + * version} is empty string. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getSecret(SecretBase secretBase) { + return getSecretWithResponse(secretBase).flatMap(FluxUtil::toMono); } /** @@ -195,11 +251,7 @@ Mono> getSecret(String name, String version, Context context) { * the {@link Flux} containing {@link SecretBase base secret} as output. This operation can then be used to get * the full secret with its value from {@code secretBase}.

*

Code Samples

- *
-     * secretAsyncClient.listSecrets().subscribe(secretBase ->
-     *     client.getSecret(secretBase).subscribe(secretResponse ->
-     *       System.out.printf("Secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecretWithResponse#secretBase} * * @param secretBase The {@link SecretBase base secret} secret base holding attributes of the * secret being requested. @@ -211,21 +263,15 @@ Mono> getSecret(String name, String version, Context context) { * version} is empty string. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSecret(SecretBase secretBase) { - Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null."); - if (secretBase.version() == null) { - return getSecret(secretBase.name()); - } - return getSecret(secretBase.name(), secretBase.version()); + public Mono> getSecretWithResponse(SecretBase secretBase) { + return withContext(context -> getSecretWithResponse(secretBase, context)); } - Mono> getSecret(SecretBase secretBase, Context context) { + Mono> getSecretWithResponse(SecretBase secretBase, Context context) { Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null."); - if (secretBase.version() == null) { - return getSecret(secretBase.name(), context); - } - return getSecret(secretBase.name(), secretBase.version(), context); + return getSecretWithResponse(secretBase.name(), secretBase.version() == null ? "" : secretBase.version(), context); } + /** * Get the latest version of the specified secret from the key vault. The get operation is applicable to any secret stored in Azure Key Vault. * This operation requires the {@code secrets/get} permission. @@ -233,24 +279,39 @@ Mono> getSecret(SecretBase secretBase, Context context) { *

Code Samples

*

Gets latest version of the secret in the key vault. Subscribes to the call asynchronously and prints out the * returned secret details when a response is received.

- *
-     * secretAsyncClient.getSecret("secretName").subscribe(secretResponse ->
-     *   System.out.printf("Secret with name %s , value %s \n", secretResponse.value().name(),
-     *   secretResponse.value().value()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}. + * @return A {@link Mono} containing the requested {@link Secret secret}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getSecret(String name) { - return getSecret(name, ""); + public Mono getSecret(String name) { + return getSecretWithResponse(name, "").flatMap(FluxUtil::toMono); } - Mono> getSecret(String name, Context context) { - return getSecret(name, "", context); + /** + * Updates the attributes associated with the specified secret, but not the value of the specified secret in the key vault. The update + * operation changes specified attributes of an existing stored secret and attributes that are not specified in the request are left unchanged. + * The value of a secret itself cannot be changed. This operation requires the {@code secrets/set} permission. + * + *

Code Samples

+ *

Gets latest version of the secret, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the + * returned secret details when a response is received.

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.updateSecret#secretBase} + * + *

The {@code secret} is required and its fields {@link SecretBase#name() name} and {@link SecretBase#version() version} cannot be null.

+ * + * @param secret The {@link SecretBase base secret} object with updated properties. + * @throws NullPointerException if {@code secret} is {@code null}. + * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version() version} is empty string. + * @return A {@link Mono} containing the {@link SecretBase updated secret}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono updateSecret(SecretBase secret) { + return updateSecretWithResponse(secret).flatMap(FluxUtil::toMono); } /** @@ -261,15 +322,8 @@ Mono> getSecret(String name, Context context) { *

Code Samples

*

Gets latest version of the secret, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the * returned secret details when a response is received.

- *
-     * secretAsyncClient.getSecret("secretName").subscribe(secretResponse -> {
-     *     Secret secret = secretResponse.value();
-     *     //Update the not before time of the secret.
-     *     secret.notBefore(OffsetDateTime.now().plusDays(50));
-     *     secretAsyncClient.updateSecret(secret).subscribe(secretResponse ->
-     *         System.out.printf("Secret's updated not before time %s \n", secretResponse.value().notBefore().toString()));
-     *   });
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.updateSecretWithResponse#secretBase} + * *

The {@code secret} is required and its fields {@link SecretBase#name() name} and {@link SecretBase#version() version} cannot be null.

* * @param secret The {@link SecretBase base secret} object with updated properties. @@ -279,11 +333,11 @@ Mono> getSecret(String name, Context context) { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link SecretBase updated secret}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateSecret(SecretBase secret) { - return withContext(context -> updateSecret(secret, context)); + public Mono> updateSecretWithResponse(SecretBase secret) { + return withContext(context -> updateSecretWithResponse(secret, context)); } - Mono> updateSecret(SecretBase secret, Context context) { + Mono> updateSecretWithResponse(SecretBase secret, Context context) { Objects.requireNonNull(secret, "The secret input parameter cannot be null."); SecretRequestParameters parameters = new SecretRequestParameters() .tags(secret.tags()) @@ -304,10 +358,27 @@ Mono> updateSecret(SecretBase secret, Context context) { *

Code Samples

*

Deletes the secret in the Azure Key Vault. Subscribes to the call asynchronously and prints out the * deleted secret details when a response is received.

- *
-     * secretAsyncClient.deleteSecret("secretName").subscribe(deletedSecretResponse ->
-     *   System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.deleteSecret#string} + * + * @param name The name of the secret to be deleted. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link Mono} containing the {@link DeletedSecret deleted secret}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono deleteSecret(String name) { + return deleteSecretWithResponse(name).flatMap(FluxUtil::toMono); + } + + /** + * Deletes a secret from the key vault. If soft-delete is enabled on the key vault then the secret is placed in the deleted state + * and requires to be purged for permanent deletion else the secret is permanently deleted. The delete operation applies to any secret stored in Azure Key Vault but + * it cannot be applied to an individual version of a secret. This operation requires the {@code secrets/delete} permission. + * + *

Code Samples

+ *

Deletes the secret in the Azure Key Vault. Subscribes to the call asynchronously and prints out the + * deleted secret details when a response is received.

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.deleteSecretWithResponse#string} * * @param name The name of the secret to be deleted. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. @@ -315,11 +386,11 @@ Mono> updateSecret(SecretBase secret, Context context) { * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> deleteSecret(String name) { - return withContext(context -> deleteSecret(name, context)); + public Mono> deleteSecretWithResponse(String name) { + return withContext(context -> deleteSecretWithResponse(name, context)); } - Mono> deleteSecret(String name, Context context) { + Mono> deleteSecretWithResponse(String name, Context context) { return service.deleteSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Deleting secret - {}", name)) .doOnSuccess(response -> logger.info("Deleted secret - {}", response.value().name())) @@ -336,9 +407,30 @@ Mono> deleteSecret(String name, Context context) { * deleted secret details when a response is received.

*
      * //Assuming secret is deleted on a soft-delete enabled vault.
-     * secretAsyncClient.getDeletedSecret("secretName").subscribe(deletedSecretResponse ->
-     *   System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getDeletedSecret#string} + * + * @param name The name of the deleted secret. + * @return A {@link Mono} containing the {@link DeletedSecret deleted secret}. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key + * vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getDeletedSecret(String name) { + return getDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono); + } + + /** + * The get deleted secret operation returns the secrets that have been deleted for a vault enabled + * for soft-delete. This operation requires the {@code secrets/list} permission. + * + *

Code Samples

+ *

Gets the deleted secret from the key vault enabled for soft-delete. Subscribes to the call + * asynchronously and prints out the + * deleted secret details when a response is received.

+ *
+     * //Assuming secret is deleted on a soft-delete enabled vault.
+     * {@codesnippet com.azure.keyvault.secrets.secretclient.getDeletedSecretWithResponse#string}
      *
      * @param name The name of the deleted secret.
      * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
@@ -348,11 +440,11 @@ Mono> deleteSecret(String name, Context context) {
      * @throws HttpRequestException when a secret with {@code name} is empty string.
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
-    public Mono> getDeletedSecret(String name) {
-        return withContext(context -> getDeletedSecret(name, context));
+    public Mono> getDeletedSecretWithResponse(String name) {
+        return withContext(context -> getDeletedSecretWithResponse(name, context));
     }
 
-    Mono> getDeletedSecret(String name, Context context) {
+    Mono> getDeletedSecretWithResponse(String name, Context context) {
         return service.getDeletedSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Retrieving deleted secret - {}", name))
                 .doOnSuccess(response -> logger.info("Retrieved deleted secret - {}", response.value().name()))
@@ -370,9 +462,7 @@ Mono> getDeletedSecret(String name, Context context) {
      * status code from the server response when a response is received.

*
      * //Assuming secret is deleted on a soft-delete enabled vault.
-     * secretAsyncClient.purgeDeletedSecret("deletedSecretName").subscribe(purgeResponse ->
-     *   System.out.printf("Purge Status response %d \n", purgeResponse.statusCode()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.purgeDeletedSecret#string} * * @param name The name of the secret. * @return A {@link Mono} containing a {@link VoidResponse}. @@ -401,9 +491,28 @@ Mono purgeDeletedSecret(String name, Context context) { * recovered secret details when a response is received.

*
      * //Assuming secret is deleted on a soft-delete enabled vault.
-     * secretAsyncClient.recoverDeletedSecret("deletedSecretName").subscribe(recoveredSecretResponse ->
-     *   System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.value().name()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.recoverDeletedSecret#string} + * + * @param name The name of the deleted secret to be recovered. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link Mono} containing the {@link Secret recovered secret}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono recoverDeletedSecret(String name) { + return recoverDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono); + } + + /** + * Recovers the deleted secret in the key vault to its latest version and can only be performed on a soft-delete enabled vault. + * This operation requires the {@code secrets/recover} permission. + * + *

Code Samples

+ *

Recovers the deleted secret from the key vault enabled for soft-delete. Subscribes to the call asynchronously and prints out the + * recovered secret details when a response is received.

+ *
+     * //Assuming secret is deleted on a soft-delete enabled vault.
+     * {@codesnippet com.azure.keyvault.secrets.secretclient.recoverDeletedSecretWithResponse#string}
      *
      * @param name The name of the deleted secret to be recovered.
      * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
@@ -411,11 +520,11 @@ Mono purgeDeletedSecret(String name, Context context) {
      * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Secret recovered secret}.
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
-    public Mono> recoverDeletedSecret(String name) {
-        return withContext(context -> recoverDeletedSecret(name, context));
+    public Mono> recoverDeletedSecretWithResponse(String name) {
+        return withContext(context -> recoverDeletedSecretWithResponse(name, context));
     }
 
-    Mono> recoverDeletedSecret(String name, Context context) {
+    Mono> recoverDeletedSecretWithResponse(String name, Context context) {
         return service.recoverDeletedSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Recovering deleted secret - {}", name))
                 .doOnSuccess(response -> logger.info("Recovered deleted secret - {}", response.value().name()))
@@ -431,9 +540,28 @@ Mono> recoverDeletedSecret(String name, Context context) {
      * the
      * length of the secret's backup byte array returned in the response.

*
-     * secretAsyncClient.backupSecret("secretName").subscribe(secretBackupResponse ->
-     *   System.out.printf("Secret's Backup Byte array's length %s \n", secretBackupResponse.value().length));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.backupSecret#string} + * + * @param name The name of the secret. + * @return A {@link Mono} containing the backed up secret blob. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key + * vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono backupSecret(String name) { + return backupSecretWithResponse(name).flatMap(FluxUtil::toMono); + } + + /** + * Requests a backup of the specified secret be downloaded to the client. All versions of the + * secret will be downloaded. This operation requires the {@code secrets/backup} permission. + * + *

Code Samples

+ *

Backs up the secret from the key vault. Subscribes to the call asynchronously and prints out + * the + * length of the secret's backup byte array returned in the response.

+ * {@codesnippet com.azure.keyvault.secrets.secretclient.backupSecretWithResponse#string} * * @param name The name of the secret. * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} @@ -443,11 +571,11 @@ Mono> recoverDeletedSecret(String name, Context context) { * @throws HttpRequestException when a secret with {@code name} is empty string. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> backupSecret(String name) { - return withContext(context -> backupSecret(name, context)); + public Mono> backupSecretWithResponse(String name) { + return withContext(context -> backupSecretWithResponse(name, context)); } - Mono> backupSecret(String name, Context context) { + Mono> backupSecretWithResponse(String name, Context context) { return service.backupSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context) .doOnRequest(ignored -> logger.info("Backing up secret - {}", name)) .doOnSuccess(response -> logger.info("Backed up secret - {}", name)) @@ -466,9 +594,28 @@ Mono> backupSecret(String name, Context context) { * restored secret details when a response is received.

*
      * //Pass the Secret Backup Byte array to the restore operation.
-     * secretAsyncClient.restoreSecret(secretBackupByteArray).subscribe(secretResponse ->
-     *   System.out.printf("Restored Secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.restoreSecret#byte} + * + * @param backup The backup blob associated with the secret. + * @return A {@link Mono} containing the {@link Secret restored secret}. + * @throws ResourceModifiedException when {@code backup} blob is malformed. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono restoreSecret(byte[] backup) { + return restoreSecretWithResponse(backup).flatMap(FluxUtil::toMono); + } + + /** + * Restores a backed up secret, and all its versions, to a vault. This operation requires the + * {@code secrets/restore} permission. + * + *

Code Samples

+ *

Restores the secret in the key vault from its backup. Subscribes to the call asynchronously + * and prints out the + * restored secret details when a response is received.

+ *
+     * //Pass the Secret Backup Byte array to the restore operation.
+     * {@codesnippet com.azure.keyvault.secrets.secretclient.restoreSecretWithResponse#byte}
      *
      * @param backup The backup blob associated with the secret.
      * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
@@ -476,11 +623,11 @@ Mono> backupSecret(String name, Context context) {
      * @throws ResourceModifiedException when {@code backup} blob is malformed.
      */
     @ServiceMethod(returns = ReturnType.SINGLE)
-    public Mono> restoreSecret(byte[] backup) {
-        return withContext(context -> restoreSecret(backup, context));
+    public Mono> restoreSecretWithResponse(byte[] backup) {
+        return withContext(context -> restoreSecretWithResponse(backup, context));
     }
 
-    Mono> restoreSecret(byte[] backup, Context context) {
+    Mono> restoreSecretWithResponse(byte[] backup, Context context) {
         SecretRestoreRequestParameters parameters = new SecretRestoreRequestParameters().secretBackup(backup);
         return service.restoreSecret(endpoint, API_VERSION, ACCEPT_LANGUAGE, parameters, CONTENT_TYPE_HEADER_VALUE, context)
                 .doOnRequest(ignored -> logger.info("Attempting to restore secret"))
@@ -496,11 +643,7 @@ Mono> restoreSecret(byte[] backup, Context context) {
      * 

Code Samples

*

It is possible to get full Secrets with values from this information. Convert the {@link Flux} containing {@link SecretBase base secret} to * {@link Flux} containing {@link Secret secret} using {@link SecretAsyncClient#getSecret(SecretBase baseSecret)} within {@link Flux#flatMap(Function)}.

- *
-     * Flux<Secret> secrets = secretAsyncClient.listSecrets()
-     *   .flatMap(secretAsyncClient::getSecret)
-     *   .map(Response::value);
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.listSecrets} * * @return A {@link PagedFlux} containing {@link SecretBase secret} of all the secrets in the vault. */ @@ -548,10 +691,7 @@ private Mono> listSecretsFirstPage(Context context) { *

Code Samples

*

Lists the deleted secrets in the key vault. Subscribes to the call asynchronously and prints out the * recovery id of each deleted secret when a response is received.

- *
-     * secretAsyncClient.listDeletedSecrets().subscribe(deletedSecret ->
-     *   System.out.printf("Deleted secret's recovery Id %s \n", deletedSecret.recoveryId()));
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.listDeletedSecrets} * * @return A {@link Flux} containing all of the {@link DeletedSecret deleted secrets} in the vault. */ @@ -601,11 +741,7 @@ private Mono> listDeletedSecretsFirstPage(Context c *

It is possible to get the Secret with value of all the versions from this information. Convert the {@link Flux} * containing {@link SecretBase base secret} to {@link Flux} containing {@link Secret secret} using * {@link SecretAsyncClient#getSecret(SecretBase baseSecret)} within {@link Flux#flatMap(Function)}.

- *
-     * Flux<Secret> secrets = secretAsyncClient.listSecretVersions("secretName")
-     *   .flatMap(secretAsyncClient::getSecret)
-     *   .map(Response::value);
-     * 
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.listSecretVersions#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. @@ -630,7 +766,7 @@ PagedFlux listSecretVersions(String name, Context context) { * {@link SecretAsyncClient#listSecretVersions()}. * * @param continuationToken The {@link PagedResponse#nextLink()} from a previous, successful call to one of the list operations. - * + * * @return A {@link Mono} of {@link PagedResponse} from the next page of results. */ private Mono> listSecretVersionsNextPage(String continuationToken, Context context) { diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java index dab070eda1560..590800600dfb4 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java @@ -9,6 +9,7 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.VoidResponse; import com.azure.core.implementation.annotation.ServiceClient; +import com.azure.core.util.Context; import com.azure.security.keyvault.secrets.models.DeletedSecret; import com.azure.security.keyvault.secrets.models.Secret; import com.azure.security.keyvault.secrets.models.SecretBase; @@ -48,24 +49,16 @@ public final class SecretClient { * set to true by key vault, if not specified.

* *

Code Samples

- *

Creates a new secret which expires in 60 days in the key vault. Prints out the details of the - * newly created secret returned in the response.

- *
-     * Secret secret = new Secret("secretName", "secretValue")
-     *   .expires(OffsetDateTime.now.plusDays(60));
-     *
-     * Secret retSecret = secretClient.setSecret(keySecret).value();
-     * System.out.printf("Secret is created with name %s and value %s \n", retSecret.name(), retSecret.value());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.setSecret#secret} * * @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null. * @throws NullPointerException if {@code secret} is {@code null}. * @throws ResourceModifiedException if {@code secret} is malformed. * @throws HttpRequestException if {@link Secret#name() name} or {@link Secret#value() value} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}. + * @return The {@link Secret created secret}. */ - public Response setSecret(Secret secret) { - return client.setSecret(secret).block(); + public Secret setSecret(Secret secret) { + return setSecretWithResponse(secret, Context.NONE).value(); } /** @@ -74,19 +67,34 @@ public Response setSecret(Secret secret) { * *

Code Samples

*

Creates a new secret in the key vault. Prints out the details of the newly created secret returned in the response.

- *
-     * Secret secret = secretClient.setSecret("secretName", "secretValue").value();
-     * System.out.printf("Secret is created with name %s and value %s \n", secret.name(), secret.value());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.setSecret#string-string} * * @param name The name of the secret. It is required and cannot be null. * @param value The value of the secret. It is required and cannot be null. * @throws ResourceModifiedException if invalid {@code name} or {@code value} is specified. * @throws HttpRequestException if {@code name} or {@code value} is empty string. + * @return The {@link Secret created secret}. + */ + public Secret setSecret(String name, String value) { + return client.setSecretWithResponse(name, value, Context.NONE).block().value(); + } + + /** + * The set operation adds a secret to the Azure Key Vault. If the named secret already exists, Azure Key Vault creates a new version of that secret. + * This operation requires the {@code secrets/set} permission. + * + *

Code Samples

+ *

Creates a new secret in the key vault. Prints out the details of the newly created secret returned in the response.

+ * {@codesnippet com.azure.security.keyvault.secretclient.setSecretWithResponse#secret-Context} + * + * @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceModifiedException if invalid {@code name} or {@code value} is specified. + * @throws HttpRequestException if {@code name} or {@code value} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}. */ - public Response setSecret(String name, String value) { - return client.setSecret(name, value).block(); + public Response setSecretWithResponse(Secret secret, Context context) { + return client.setSecretWithResponse(secret, context).block(); } /** @@ -95,20 +103,36 @@ public Response setSecret(String name, String value) { * *

Code Samples

*

Gets a specific version of the secret in the key vault. Prints out the details of the returned secret.

- *
-     * String secretVersion = "6A385B124DEF4096AF1361A85B16C204";
-     * Secret secretWithVersion = secretClient.getSecret("secretName", secretVersion).value();
-     * System.out.printf("Secret is returned with name %s and value %s \n", secretWithVersion.name(), secretWithVersion.value());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.getSecret#string-string} * * @param name The name of the secret, cannot be null. * @param version The version of the secret to retrieve. If this is an empty String or null, this call is equivalent to calling {@link #getSecret(String)}, with the latest version being retrieved. * @throws ResourceNotFoundException when a secret with {@code name} and {@code version} doesn't exist in the key vault. * @throws HttpRequestException if {@code name} or {@code version} is empty string. + * @return The requested {@link Secret secret}. + */ + public Secret getSecret(String name, String version) { + return getSecretWithResponse(name, version, Context.NONE).value(); + } + + /** + * Get the secret which represents {@link SecretBase secretBase} from the key vault. The get operation is applicable to any + * secret stored in Azure Key Vault. This operation requires the {@code secrets/get} permission. + * + *

The list operations {@link SecretClient#listSecrets()} and {@link SecretClient#listSecretVersions(String)} return + * the {@link List} containing {@link SecretBase base secret} as output excluding the include the value of the secret. + * This operation can then be used to get the full secret with its value from {@code secretBase}.

+ *

Code Samples

+ * {@codesnippet com.azure.security.keyvault.secretclient.getSecretWithResponse#secretBase} + * + * @param secretBase The {@link SecretBase base secret} holding attributes of the secret being requested. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}. */ - public Response getSecret(String name, String version) { - return client.getSecret(name, version).block(); + public Response getSecretWithResponse(SecretBase secretBase, Context context) { + return client.getSecretWithResponse(secretBase, context).block(); } /** @@ -118,15 +142,16 @@ public Response getSecret(String name, String version) { *

The list operations {@link SecretClient#listSecrets()} and {@link SecretClient#listSecretVersions(String)} return * the {@link List} containing {@link SecretBase base secret} as output excluding the include the value of the secret. * This operation can then be used to get the full secret with its value from {@code secretBase}.

+ *

Code Samples

* {@codesnippet com.azure.security.keyvault.secretclient.getSecret#secretBase} * * @param secretBase The {@link SecretBase base secret} holding attributes of the secret being requested. * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault. * @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string. - * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}. + * @return The requested {@link Secret secret}. */ - public Response getSecret(SecretBase secretBase) { - return client.getSecret(secretBase).block(); + public Secret getSecret(SecretBase secretBase) { + return getSecretWithResponse(secretBase, Context.NONE).value(); } /** @@ -135,18 +160,41 @@ public Response getSecret(SecretBase secretBase) { * *

Code Samples

*

Gets the latest version of the secret in the key vault. Prints out the details of the returned secret.

- *
-     * Secret secret = secretClient.getSecret("secretName").value();
-     * System.out.printf("Secret is returned with name %s and value %s \n", secret.name(), secret.value());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.getSecret#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException if {@code name} is empty string. - * @return A {@link Response} whose {@link Response#value()} contains the requested {@link Secret}. + * @return The requested {@link Secret}. */ - public Response getSecret(String name) { - return getSecret(name, ""); + public Secret getSecret(String name) { + return getSecretWithResponse(name, "", Context.NONE).value(); + } + + /** + * Get the specified secret with specified version from the key vault. The get operation is + * applicable to any secret stored in Azure Key Vault. This operation requires the {@code + * secrets/get} permission. + * + *

Code Samples

+ *

Gets a specific version of the secret in the key vault. Subscribes to the call + * asynchronously and prints out the + * returned secret details when a response is received.

+ * {@codesnippet com.azure.security.keyvault.secretclient.getSecretWithResponse#string-string-Context} + * + * @param name The name of the secret, cannot be null + * @param version The version of the secret to retrieve. If this is an empty String or null, this + * call is equivalent to calling {@link #getSecret(String)}, with the latest version being + * retrieved. + * @param context Additional context that is passed through the Http pipeline during the service call. + * + * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret}. + * @throws ResourceNotFoundException when a secret with {@code name} and {@code version} doesn't + * exist in the key vault. + * @throws HttpRequestException if {@code name} name} or {@code version} is empty string. + */ + public Response getSecretWithResponse(String name, String version, Context context) { + return client.getSecretWithResponse(name, version, context).block(); } /** @@ -158,21 +206,38 @@ public Response getSecret(String name) { * *

Code Samples

*

Gets the latest version of the secret, changes its expiry time and the updates the secret in the key vault.

- *
-     * Secret secret = secretClient.getSecret("secretName").value();
-     * secret.expires(OffsetDateTime.now().plusDays(60));
-     * SecretBase updatedSecretBase = secretClient.updateSecret(secret).value();
-     * Secret updatedSecret = secretClient.getSecret(updatedSecretBase.name()).value();
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.updateSecretWithResponse#secretBase-Context} * * @param secret The {@link SecretBase base secret} object with updated properties. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws NullPointerException if {@code secret} is {@code null}. * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault. * @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link SecretBase updated secret}. */ - public Response updateSecret(SecretBase secret) { - return client.updateSecret(secret).block(); + public Response updateSecretWithResponse(SecretBase secret, Context context) { + return client.updateSecretWithResponse(secret, context).block(); + } + + /** + * Updates the attributes associated with the specified secret, but not the value of the specified secret in the key vault. The update + * operation changes specified attributes of an existing stored secret and attributes that are not specified in the request are left unchanged. + * The value of a secret itself cannot be changed. This operation requires the {@code secrets/set} permission. + * + *

The {@code secret} is required and its fields {@link SecretBase#name() name} and {@link SecretBase#version() version} cannot be null.

+ * + *

Code Samples

+ *

Gets the latest version of the secret, changes its expiry time and the updates the secret in the key vault.

+ * {@codesnippet com.azure.security.keyvault.secretclient.updateSecret#secretBase} + * + * @param secret The {@link SecretBase base secret} object with updated properties. + * @throws NullPointerException if {@code secret} is {@code null}. + * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault. + * @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string. + * @return The {@link SecretBase updated secret}. + */ + public SecretBase updateSecret(SecretBase secret) { + return updateSecretWithResponse(secret, Context.NONE).value(); } /** @@ -182,18 +247,53 @@ public Response updateSecret(SecretBase secret) { * *

Code Samples

*

Deletes the secret from the keyvault. Prints out the recovery id of the deleted secret returned in the response.

- *
-     * DeletedSecret deletedSecret = secretClient.deleteSecret("secretName").value();
-     * System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()));
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.deleteSecret#string} * * @param name The name of the secret to be deleted. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a secret with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}. */ - public Response deleteSecret(String name) { - return client.deleteSecret(name).block(); + public DeletedSecret deleteSecret(String name) { + return deleteSecretWithResponse(name, Context.NONE).value(); + } + + /** + * Deletes a secret from the key vault. If soft-delete is enabled on the key vault then the secret is placed in the deleted state + * and requires to be purged for permanent deletion else the secret is permanently deleted. The delete operation applies to any secret stored in Azure Key Vault but + * it cannot be applied to an individual version of a secret. This operation requires the {@code secrets/delete} permission. + * + *

Code Samples

+ *

Deletes the secret from the keyvault. Prints out the recovery id of the deleted secret returned in the response.

+ * {@codesnippet com.azure.security.keyvault.secretclient.deleteSecretWithResponse#string-Context} + * + * @param name The name of the secret to be deleted. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}. + */ + public Response deleteSecretWithResponse(String name, Context context) { + return client.deleteSecretWithResponse(name, context).block(); + } + + /** + * The get deleted secret operation returns the secrets that have been deleted for a vault enabled for soft-delete. + * This operation requires the {@code secrets/list} permission. + * + *

Code Samples

+ *

Gets the deleted secret from the key vault enabled for soft-delete. Prints out the details of the deleted secret + * returned in the response.

+ * //Assuming secret is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.security.keyvault.secretclient.getDeletedSecret#string} + * + * @param name The name of the deleted secret. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return The {@link DeletedSecret deleted secret}. + */ + public DeletedSecret getDeletedSecret(String name) { + return getDeletedSecretWithResponse(name, Context.NONE).value(); } /** @@ -203,19 +303,17 @@ public Response deleteSecret(String name) { *

Code Samples

*

Gets the deleted secret from the key vault enabled for soft-delete. Prints out the details of the deleted secret * returned in the response.

- *
      * //Assuming secret is deleted on a soft-delete enabled key vault.
-     * DeletedSecret deletedSecret = secretClient.getDeletedSecret("secretName").value();
-     * System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecret.recoveryId());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.getDeletedSecretWithResponse#string-Context} * * @param name The name of the deleted secret. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a secret with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}. */ - public Response getDeletedSecret(String name) { - return client.getDeletedSecret(name).block(); + public Response getDeletedSecretWithResponse(String name, Context context) { + return client.getDeletedSecretWithResponse(name, context).block(); } /** @@ -224,11 +322,8 @@ public Response getDeletedSecret(String name) { * *

Code Samples

*

Purges the deleted secret from the key vault enabled for soft-delete. Prints out the status code from the server response.

- *
      * //Assuming secret is deleted on a soft-delete enabled key vault.
-     * VoidResponse purgeResponse = secretClient.purgeDeletedSecret("deletedSecretName");
-     * System.out.printf("Purge Status Code: %d", purgeResponse.statusCode());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.purgeDeletedSecret#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. @@ -236,7 +331,45 @@ public Response getDeletedSecret(String name) { * @return A {@link VoidResponse}. */ public VoidResponse purgeDeletedSecret(String name) { - return client.purgeDeletedSecret(name).block(); + return purgeDeletedSecret(name, Context.NONE); + } + + /** + * The purge deleted secret operation removes the secret permanently, without the possibility of recovery. + * This operation can only be enabled on a soft-delete enabled vault. This operation requires the {@code secrets/purge} permission. + * + *

Code Samples

+ *

Purges the deleted secret from the key vault enabled for soft-delete. Prints out the status code from the server response.

+ * //Assuming secret is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.security.keyvault.secretclient.purgeDeletedSecret#string-Context} + * + * @param name The name of the secret. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link VoidResponse}. + */ + public VoidResponse purgeDeletedSecret(String name, Context context) { + return client.purgeDeletedSecret(name, context).block(); + } + + /** + * Recovers the deleted secret in the key vault to its latest version and can only be performed on a soft-delete enabled vault. + * This operation requires the {@code secrets/recover} permission. + * + *

Code Samples

+ *

Recovers the deleted secret from the key vault enabled for soft-delete. Prints out the details of the recovered secret + * returned in the response.

+ * //Assuming secret is deleted on a soft-delete enabled key vault. + * {@codesnippet com.azure.security.keyvault.secretclient.recoverDeletedSecret#string} + * + * @param name The name of the deleted secret to be recovered. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return The {@link Secret recovered secret}. + */ + public Secret recoverDeletedSecret(String name) { + return recoverDeletedSecretWithResponse(name, Context.NONE).value(); } /** @@ -246,19 +379,17 @@ public VoidResponse purgeDeletedSecret(String name) { *

Code Samples

*

Recovers the deleted secret from the key vault enabled for soft-delete. Prints out the details of the recovered secret * returned in the response.

- *
      * //Assuming secret is deleted on a soft-delete enabled key vault.
-     * Secret recoveredSecret =  secretClient.recoverDeletedSecret("deletedSecretName").value();
-     * System.out.printf("Recovered Secret with name %s", recoveredSecret.name());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.recoverDeletedSecretWithResponse#string-Context} * * @param name The name of the deleted secret to be recovered. + * @param context Additional context that is passed through the Http pipeline during the service call. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a secret with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret recovered secret}. */ - public Response recoverDeletedSecret(String name) { - return client.recoverDeletedSecret(name).block(); + public Response recoverDeletedSecretWithResponse(String name, Context context) { + return client.recoverDeletedSecretWithResponse(name, context).block(); } /** @@ -267,18 +398,33 @@ public Response recoverDeletedSecret(String name) { * *

Code Samples

*

Backs up the secret from the key vault and prints out the length of the secret's backup byte array returned in the response

- *
-     * byte[] secretBackup = secretClient.backupSecret("secretName").value();
-     * System.out.printf("Secret's Backup Byte array's length %s", secretBackup.length);
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.backupSecret#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. * @throws HttpRequestException when a secret with {@code name} is empty string. * @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob. */ - public Response backupSecret(String name) { - return client.backupSecret(name).block(); + public byte[] backupSecret(String name) { + return backupSecretWithResponse(name, Context.NONE).value(); + } + + /** + * Requests a backup of the specified secret be downloaded to the client. All versions of the secret will be downloaded. + * This operation requires the {@code secrets/backup} permission. + * + *

Code Samples

+ *

Backs up the secret from the key vault and prints out the length of the secret's backup byte array returned in the response

+ * {@codesnippet com.azure.security.keyvault.secretclient.backupSecretWithResponse#string-Context} + * + * @param name The name of the secret. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob. + */ + public Response backupSecretWithResponse(String name, Context context) { + return client.backupSecretWithResponse(name, context).block(); } /** @@ -288,18 +434,34 @@ public Response backupSecret(String name) { *

Code Samples

*

Restores the secret in the key vault from its backup byte array. Prints out the details of the restored secret returned * in the response.

- *
      * //Pass the secret backup byte array of the secret to be restored.
-     * Secret restoredSecret = secretClient.restoreSecret(secretBackupByteArray).value();
-     * System.out.printf("Restored Secret with name %s and value %s", restoredSecret.name(), restoredSecret.value());
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.restoreSecret#byte} * * @param backup The backup blob associated with the secret. * @throws ResourceModifiedException when {@code backup} blob is malformed. * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}. */ - public Response restoreSecret(byte[] backup) { - return client.restoreSecret(backup).block(); + public Secret restoreSecret(byte[] backup) { + return restoreSecretWithResponse(backup, Context.NONE).value(); + } + + /** + * Restores a backed up secret, and all its versions, to a vault. + * This operation requires the {@code secrets/restore} permission. + * + *

Code Samples

+ *

Restores the secret in the key vault from its backup byte array. Prints out the details of the restored secret returned + * in the response.

+ * //Pass the secret backup byte array of the secret to be restored. + * {@codesnippet com.azure.security.keyvault.secretclient.restoreSecretWithResponse#byte-Context} + * + * @param backup The backup blob associated with the secret. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceModifiedException when {@code backup} blob is malformed. + * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}. + */ + public Response restoreSecretWithResponse(byte[] backup, Context context) { + return client.restoreSecretWithResponse(backup, context).block(); } /** @@ -309,17 +471,28 @@ public Response restoreSecret(byte[] backup) { * *

It is possible to get full secrets with values from this information. Loop over the {@link SecretBase secret} and * call {@link SecretClient#getSecret(SecretBase baseSecret)} . This will return the {@link Secret secret} with value included of its latest version.

- *
-     * for (SecretBase secret : secretClient.listSecrets()) {
-     *   Secret secretWithValue  = secretClient.getSecret(secret).value();
-     *   System.out.printf("Received secret with name %s and value %s", secretWithValue.name(), secretWithValue.value());
-     * }
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.listSecrets} * * @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value. */ public Iterable listSecrets() { - return client.listSecrets().toIterable(); + return listSecrets(Context.NONE); + } + + /** + * List the secrets in the key vault. The list Secrets operation is applicable to the entire vault. The individual secret response + * in the list is represented by {@link SecretBase} as only the base secret identifier and its attributes are + * provided in the response. The secret values and individual secret versions are not listed in the response. This operation requires the {@code secrets/list} permission. + * + *

It is possible to get full secrets with values from this information. Loop over the {@link SecretBase secret} and + * call {@link SecretClient#getSecret(SecretBase baseSecret)} . This will return the {@link Secret secret} with value included of its latest version.

+ * {@codesnippet com.azure.security.keyvault.secretclient.listSecrets#Context} + * + * @param context Additional context that is passed through the Http pipeline during the service call.* + * @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value. + */ + public Iterable listSecrets(Context context) { + return client.listSecrets(context).toIterable(); } /** @@ -328,16 +501,27 @@ public Iterable listSecrets() { * *

Code Samples

*

Lists the deleted secrets in the key vault and for each deleted secret prints out its recovery id.

- *
-     * for (DeletedSecret deletedSecret : secretClient.listDeletedSecrets()) {
-     *   System.out.printf("Deleted secret's recovery Id %s", deletedSecret.recoveryId());
-     * }
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.listDeletedSecrets#Context} + * + * @param context Additional context that is passed through the Http pipeline during the service call. + * @return A {@link List} containing all of the {@link DeletedSecret deleted secrets} in the vault. + */ + public Iterable listDeletedSecrets(Context context) { + return client.listDeletedSecrets(context).toIterable(); + } + + /** + * Lists {@link DeletedSecret deleted secrets} of the key vault. The get deleted secrets operation returns the secrets that + * have been deleted for a vault enabled for soft-delete. This operation requires the {@code secrets/list} permission. + * + *

Code Samples

+ *

Lists the deleted secrets in the key vault and for each deleted secret prints out its recovery id.

+ * {@codesnippet com.azure.security.keyvault.secretclient.listDeletedSecrets} * * @return A {@link List} containing all of the {@link DeletedSecret deleted secrets} in the vault. */ public Iterable listDeletedSecrets() { - return client.listDeletedSecrets().toIterable(); + return listDeletedSecrets(Context.NONE); } /** @@ -347,12 +531,7 @@ public Iterable listDeletedSecrets() { * *

It is possible to get full Secrets with values for each version from this information. Loop over the {@link SecretBase secret} and * call {@link SecretClient#getSecret(SecretBase)} . This will return the {@link Secret} secrets with values included of the specified versions.

- *
-     * for (SecretBase secret : secretClient.listSecretVersions("secretName")) {
-     *   Secret secretWithValue  = secretClient.getSecret(secret).value();
-     *   System.out.printf("Received secret's version with name %s and value %s", secretWithValue.name(), secretWithValue.value());
-     * }
-     * 
+ * {@codesnippet com.azure.security.keyvault.secretclient.listSecretVersions#string} * * @param name The name of the secret. * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. @@ -360,6 +539,25 @@ public Iterable listDeletedSecrets() { * @return A {@link List} containing {@link SecretBase} of all the versions of the specified secret in the vault. List is empty if secret with {@code name} does not exist in key vault */ public Iterable listSecretVersions(String name) { - return client.listSecretVersions(name).toIterable(); + return listSecretVersions(name, Context.NONE); + } + + /** + * List all versions of the specified secret. The individual secret response in the list is represented by {@link SecretBase} + * as only the base secret identifier and its attributes are provided in the response. The secret values are + * not provided in the response. This operation requires the {@code secrets/list} permission. + * + *

It is possible to get full Secrets with values for each version from this information. Loop over the {@link SecretBase secret} and + * call {@link SecretClient#getSecret(SecretBase)} . This will return the {@link Secret} secrets with values included of the specified versions.

+ * {@codesnippet com.azure.security.keyvault.secretclient.listSecretVersions#string-Context} + * + * @param name The name of the secret. + * @param context Additional context that is passed through the Http pipeline during the service call. + * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault. + * @throws HttpRequestException when a secret with {@code name} is empty string. + * @return A {@link List} containing {@link SecretBase} of all the versions of the specified secret in the vault. List is empty if secret with {@code name} does not exist in key vault + */ + public Iterable listSecretVersions(String name, Context context) { + return client.listSecretVersions(name, context).toIterable(); } } diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java index 2cbd05b7b2607..7b1e561dc44ff 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java @@ -5,6 +5,7 @@ import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.implementation.annotation.ServiceClientBuilder; +import com.azure.core.implementation.http.policy.spi.HttpPolicyProviders; import com.azure.core.util.configuration.ConfigurationManager; import com.azure.core.util.configuration.Configuration; import com.azure.core.credentials.TokenCredential; @@ -32,7 +33,7 @@ *

The minimal configuration options required by {@link SecretClientBuilder secretClientBuilder} to build * {@link SecretAsyncClient} are {@link String endpoint} and {@link TokenCredential credential}.

* - * {@codesnippet com.azure.security.keyvault.secretclient.async.construct} + * {@codesnippet com.azure.security.keyvault.secrets.async.secretclient.construct} * *

Samples to construct the sync client

* {@codesnippet com.azure.security.keyvault.secretclient.sync.construct} @@ -40,12 +41,12 @@ *

The {@link HttpLogDetailLevel log detail level}, multiple custom {@link HttpLoggingPolicy policies} and custom * {@link HttpClient http client} can be optionally configured in the {@link SecretClientBuilder}.

* - * {@codesnippet com.azure.security.keyvault.keys.async.secretclient.withhttpclient.instantiation} + * {@codesnippet com.azure.security.keyvault.secrets.async.secretclient.withhttpclient.instantiation} * *

Alternatively, custom {@link HttpPipeline http pipeline} with custom {@link HttpPipelinePolicy} policies and {@link String endpoint} * can be specified. It provides finer control over the construction of {@link SecretAsyncClient client}

- * {@codesnippet com.azure.security.keyvault.keys.async.secretclient.pipeline.instantiation} + * {@codesnippet com.azure.security.keyvault.secrets.async.secretclient.pipeline.instantiation} * * @see SecretClient * @see SecretAsyncClient @@ -122,9 +123,11 @@ public SecretAsyncClient buildAsyncClient() { // Closest to API goes first, closest to wire goes last. final List policies = new ArrayList<>(); policies.add(new UserAgentPolicy(AzureKeyVaultConfiguration.SDK_NAME, AzureKeyVaultConfiguration.SDK_VERSION, buildConfiguration)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(retryPolicy); policies.add(new BearerTokenAuthenticationPolicy(credential, SecretAsyncClient.KEY_VAULT_SCOPE)); policies.addAll(this.policies); + HttpPolicyProviders.addAfterRetryPolicies(policies); policies.add(new HttpLoggingPolicy(httpLogDetailLevel)); HttpPipeline pipeline = new HttpPipelineBuilder() diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperations.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperations.java index f905fd0cbc38d..2761fae8156ee 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperations.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperations.java @@ -42,7 +42,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // Backups are good to have, if in case secrets get accidentally deleted by you. // For long term storage, it is ideal to write the backup to a file. String backupFilePath = "YOUR_BACKUP_FILE_PATH"; - byte[] secretBackup = client.backupSecret("StorageAccountPassword").value(); + byte[] secretBackup = client.backupSecret("StorageAccountPassword"); writeBackupToFile(secretBackup, backupFilePath); // The storage account secret is no longer in use, so you delete it. @@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // After sometime, the secret is required again. We can use the backup value to restore it in the key vault. byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); - Secret restoredSecret = client.restoreSecret(backupFromFile).value(); + Secret restoredSecret = client.restoreSecret(backupFromFile); } private static void writeBackupToFile(byte[] bytes, String filePath) { diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperationsAsync.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperationsAsync.java index 7b4bebaf5224f..51967100bcc13 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperationsAsync.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/BackupAndRestoreOperationsAsync.java @@ -39,7 +39,7 @@ public static void main(String[] args) throws IOException, InterruptedException, secretAsyncClient.setSecret(new Secret("StorageAccountPassword", "f4G34fMh8v-fdsgjsk2323=-asdsdfsdf") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); @@ -47,7 +47,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // For long term storage, it is ideal to write the backup to a file. String backupFilePath = "YOUR_BACKUP_FILE_PATH"; secretAsyncClient.backupSecret("StorageAccountPassword").subscribe(backupResponse -> { - byte[] backupBytes = backupResponse.value(); + byte[] backupBytes = backupResponse; writeBackupToFile(backupBytes, backupFilePath); }); @@ -55,7 +55,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // The storage account secret is no longer in use, so you delete it. secretAsyncClient.deleteSecret("StorageAccountPassword").subscribe(deletedSecretResponse -> - System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); //To ensure file is deleted on server side. Thread.sleep(30000); @@ -70,7 +70,7 @@ public static void main(String[] args) throws IOException, InterruptedException, // After sometime, the secret is required again. We can use the backup value to restore it in the key vault. byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); secretAsyncClient.restoreSecret(backupFromFile).subscribe(secretResponse -> - System.out.printf("Restored Secret with name %s \n", secretResponse.value().name())); + System.out.printf("Restored Secret with name %s \n", secretResponse.name())); //To ensure secret is restored on server side. Thread.sleep(15000); diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorld.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorld.java index 94f50ed062d15..e1f816fcb1cb1 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorld.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorld.java @@ -36,14 +36,14 @@ public static void main(String[] args) throws InterruptedException, IllegalArgum .expires(OffsetDateTime.now().plusYears(1))); // Let's Get the bank secret from the key vault. - Secret bankSecret = secretClient.getSecret("BankAccountPassword").value(); + Secret bankSecret = secretClient.getSecret("BankAccountPassword"); System.out.printf("Secret is returned with name %s and value %s \n", bankSecret.name(), bankSecret.value()); // After one year, the bank account is still active, we need to update the expiry time of the secret. // The update method can be used to update the expiry attribute of the secret. It cannot be used to update // the value of the secret. bankSecret.expires(bankSecret.expires().plusYears(1)); - SecretBase updatedSecret = secretClient.updateSecret(bankSecret).value(); + SecretBase updatedSecret = secretClient.updateSecret(bankSecret); System.out.printf("Secret's updated expiry time %s \n", updatedSecret.expires()); // Bank forced a password update for security purposes. Let's change the value of the secret in the key vault. diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorldAsync.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorldAsync.java index 9f368c85c576d..17015ed1915c3 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorldAsync.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/HelloWorldAsync.java @@ -32,13 +32,13 @@ public static void main(String[] args) throws InterruptedException { // already exists in the key vault, then a new version of the secret is created. secretAsyncClient.setSecret(new Secret("BankAccountPassword", "f4G34fMh8v") .expires(OffsetDateTime.now().plusYears(1))).subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); // Let's Get the bank secret from the key vault. secretAsyncClient.getSecret("BankAccountPassword").subscribe(secretResponse -> - System.out.printf("Secret returned with name %s , value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret returned with name %s , value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); @@ -46,11 +46,11 @@ public static void main(String[] args) throws InterruptedException { // The update method can be used to update the expiry attribute of the secret. It cannot be used to update // the value of the secret. secretAsyncClient.getSecret("BankAccountPassword").subscribe(secretResponse -> { - Secret secret = secretResponse.value(); + Secret secret = secretResponse; //Update the expiry time of the secret. secret.expires(secret.expires().plusYears(1)); secretAsyncClient.updateSecret(secret).subscribe(updatedSecretResponse -> - System.out.printf("Secret's updated expiry time %s \n", updatedSecretResponse.value().expires().toString())); + System.out.printf("Secret's updated expiry time %s \n", updatedSecretResponse.expires().toString())); }); Thread.sleep(2000); @@ -59,13 +59,13 @@ public static void main(String[] args) throws InterruptedException { // To achieve this, we need to create a new version of the secret in the key vault. The update operation cannot // change the value of the secret. secretAsyncClient.setSecret("BankAccountPassword", "bhjd4DDgsa").subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); // The bank account was closed, need to delete its credentials from the key vault. secretAsyncClient.deleteSecret("BankAccountPassword").subscribe(deletedSecretResponse -> - System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); //To ensure secret is deleted on server side. Thread.sleep(30000); diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperations.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperations.java index f45e97af158f4..44198074dfa7e 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperations.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperations.java @@ -40,7 +40,7 @@ public static void main(String[] args) throws IllegalArgumentException { // You need to check if any of the secrets are sharing same values. Let's list the secrets and print their values. // List operations don't return the secrets with value information. So, for each returned secret we call getSecret to get the secret with its value information. for (SecretBase secret : client.listSecrets()) { - Secret secretWithValue = client.getSecret(secret).value(); + Secret secretWithValue = client.getSecret(secret); System.out.printf("Received secret with name %s and value %s \n", secretWithValue.name(), secretWithValue.value()); } @@ -50,7 +50,7 @@ public static void main(String[] args) throws IllegalArgumentException { // You need to check all the different values your bank account password secret had previously. Lets print all the versions of this secret. for (SecretBase secret : client.listSecretVersions("BankAccountPassword")) { - Secret secretWithValue = client.getSecret(secret).value(); + Secret secretWithValue = client.getSecret(secret); System.out.printf("Received secret's version with name %s and value %s", secretWithValue.name(), secretWithValue.value()); } } diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperationsAsync.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperationsAsync.java index af085d95627b4..f0ad91aa2bdf2 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperationsAsync.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ListOperationsAsync.java @@ -33,14 +33,14 @@ public static void main(String[] args) throws InterruptedException { secretAsyncClient.setSecret(new Secret("BankAccountPassword", "f4G34fMh8v") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); secretAsyncClient.setSecret(new Secret("StorageAccountPassword", "f4G34fMh8v-fdsgjsk2323=-asdsdfsdf") .expires(OffsetDateTime.now().plusYears(1))) .subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); @@ -49,7 +49,7 @@ public static void main(String[] args) throws InterruptedException { secretAsyncClient.listSecrets() .subscribe(secretBase -> secretAsyncClient.getSecret(secretBase).subscribe(secretResponse -> - System.out.printf("Received secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()))); + System.out.printf("Received secret with name %s and value %s \n", secretResponse.name(), secretResponse.value()))); Thread.sleep(15000); @@ -57,14 +57,14 @@ public static void main(String[] args) throws InterruptedException { // Calling setSecret on an existing secret creates a new version of the secret in the key vault with the new value. secretAsyncClient.setSecret(new Secret("BankAccountPassword", "sskdjfsdasdjsd") .expires(OffsetDateTime.now().plusYears(1))).subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); // You need to check all the different values your bank account password secret had previously. Lets print all the versions of this secret. secretAsyncClient.listSecretVersions("BankAccountPassword").subscribe(secretBase -> secretAsyncClient.getSecret(secretBase).subscribe(secretResponse -> - System.out.printf("Received secret's version with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()))); + System.out.printf("Received secret's version with name %s and value %s \n", secretResponse.name(), secretResponse.value()))); Thread.sleep(15000); } diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ManagingDeletedSecretsAsync.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ManagingDeletedSecretsAsync.java index fa9e5a0915fb0..9910f64a20407 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ManagingDeletedSecretsAsync.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/ManagingDeletedSecretsAsync.java @@ -36,19 +36,19 @@ public static void main(String[] args) throws InterruptedException { // already exists in the key vault, then a new version of the secret is created. secretAsyncClient.setSecret(new Secret("BankAccountPassword", "f4G34fMh8v") .expires(OffsetDateTime.now().plusYears(1))).subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); secretAsyncClient.setSecret(new Secret("StorageAccountPassword", "f4G34fMh8v-fdsgjsk2323=-asdsdfsdf") .expires(OffsetDateTime.now().plusYears(1))).subscribe(secretResponse -> - System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())); + System.out.printf("Secret is created with name %s and value %s \n", secretResponse.name(), secretResponse.value())); Thread.sleep(2000); // The storage account was closed, need to delete its credentials from the key vault. secretAsyncClient.deleteSecret("BankAccountPassword").subscribe(deletedSecretResponse -> - System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); //To ensure secret is deleted on server side. Thread.sleep(30000); @@ -56,7 +56,7 @@ public static void main(String[] args) throws InterruptedException { // We accidentally deleted bank account secret. Let's recover it. // A deleted secret can only be recovered if the key vault is soft-delete enabled. secretAsyncClient.recoverDeletedSecret("BankAccountPassword").subscribe(recoveredSecretResponse -> - System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.value().name())); + System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.name())); //To ensure secret is recovered on server side. Thread.sleep(10000); @@ -64,10 +64,10 @@ public static void main(String[] args) throws InterruptedException { // The bank acoount and storage accounts got closed. // Let's delete bank and storage accounts secrets. secretAsyncClient.deleteSecret("BankAccountPassword").subscribe(deletedSecretResponse -> - System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); secretAsyncClient.deleteSecret("StorageAccountPassword").subscribe(deletedSecretResponse -> - System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); // To ensure secret is deleted on server side. Thread.sleep(30000); diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretAsyncClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretAsyncClientJavaDocCodeSnippets.java new file mode 100644 index 0000000000000..38c3d791c8ed5 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretAsyncClientJavaDocCodeSnippets.java @@ -0,0 +1,402 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.security.keyvault.secrets; + +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.test.models.RecordedData; +import com.azure.core.test.policy.RecordNetworkCallPolicy; +import reactor.util.context.Context; +import com.azure.identity.credential.DefaultAzureCredential; +import com.azure.security.keyvault.secrets.models.Secret; +import com.azure.security.keyvault.secrets.models.SecretBase; + +import java.time.OffsetDateTime; + +/** + * This class contains code samples for generating javadocs through doclets for {@link SecretClient} + */ +public final class SecretAsyncClientJavaDocCodeSnippets { + + private String key1 = "key1"; + private String key2 = "key2"; + private String value1 = "val1"; + private String value2 = "val2"; + + /** + * Generates code sample for creating a {@link SecretAsyncClient} + * @return An instance of {@link SecretAsyncClient} + */ + public SecretAsyncClient createAsyncClientWithHttpclient() { + // BEGIN: com.azure.security.keyvault.secrets.async.secretclient.withhttpclient.instantiation + RecordedData networkData = new RecordedData(); + HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); + SecretAsyncClient keyClient = new SecretClientBuilder() + .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) + .endpoint("https://myvault.azure.net/") + .credential(new DefaultAzureCredential()) + .addPolicy(new RecordNetworkCallPolicy(networkData)) + .httpClient(HttpClient.createDefault()) + .buildAsyncClient(); + // END: com.azure.security.keyvault.secrets.async.secretclient.withhttpclient.instantiation + return keyClient; + } + + /** + * Implementation for async SecretAsyncClient + * @return sync SecretAsyncClient + */ + private SecretAsyncClient getAsyncSecretClient() { + + // BEGIN: com.azure.security.keyvault.secrets.async.secretclient.construct + SecretAsyncClient secretAsyncClient = new SecretClientBuilder() + .credential(new DefaultAzureCredential()) + .endpoint("https://myvault.vault.azure.net/") + .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) + .buildAsyncClient(); + // END: com.azure.security.keyvault.secrets.async.secretclient.construct + return secretAsyncClient; + } + + /** + * Generates code sample for creating a {@link SecretAsyncClient} + * @return An instance of {@link SecretAsyncClient} + */ + public SecretAsyncClient createAsyncClientWithPipeline() { + // BEGIN: com.azure.security.keyvault.secrets.async.secretclient.pipeline.instantiation + RecordedData networkData = new RecordedData(); + HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); + SecretAsyncClient secretAsyncClient = new SecretClientBuilder() + .pipeline(pipeline) + .endpoint("https://myvault.azure.net/") + .credential(new DefaultAzureCredential()) + .buildAsyncClient(); + // END: com.azure.security.keyvault.secrets.async.secretclient.pipeline.instantiation + return secretAsyncClient; + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#getSecret(SecretBase)} + */ + public void getSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.getSecret#secretBase + secretAsyncClient.listSecrets() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBase -> secretAsyncClient.getSecret(secretBase) + .subscribe(secretResponse -> + System.out.printf("Secret is returned with name %s and value %s %n", secretResponse.name(), + secretResponse.value()))); + // END: com.azure.keyvault.secrets.secretclient.getSecret#secretBase + + // BEGIN: com.azure.keyvault.secrets.secretclient.getSecret#string-string + String secretVersion = "6A385B124DEF4096AF1361A85B16C204"; + secretAsyncClient.getSecret("secretName", secretVersion) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretWithVersion -> + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithVersion.name(), secretWithVersion.value())); + // END: com.azure.keyvault.secrets.secretclient.getSecret#string-string + + // BEGIN: com.azure.keyvault.secrets.secretclient.getSecret#string + secretAsyncClient.getSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretWithVersion -> + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithVersion.name(), secretWithVersion.value())); + // END: com.azure.keyvault.secrets.secretclient.getSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#getSecretWithResponse(SecretBase)} + */ + public void getSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.getSecretWithResponse#secretBase + secretAsyncClient.listSecrets() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBase -> secretAsyncClient.getSecretWithResponse(secretBase) + .subscribe(secretResponse -> + System.out.printf("Secret is returned with name %s and value %s %n", secretResponse.value().name(), + secretResponse.value().value()))); + // END: com.azure.keyvault.secrets.secretclient.getSecretWithResponse#secretBase + + // BEGIN: com.azure.keyvault.secrets.secretclient.getSecretWithResponse#string-string + String secretVersion = "6A385B124DEF4096AF1361A85B16C204"; + secretAsyncClient.getSecretWithResponse("secretName", secretVersion) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretWithVersion -> + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithVersion.value().name(), secretWithVersion.value().value())); + // END: com.azure.keyvault.secrets.secretclient.getSecretWithResponse#string-string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#setSecret(Secret)} + */ + public void setSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.setSecret#secret + Secret newSecret = new Secret("secretName", "secretValue"). + expires(OffsetDateTime.now().plusDays(60)); + secretAsyncClient.setSecret(newSecret) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponse -> + System.out.printf("Secret is created with name %s and value %s \n", + secretResponse.name(), secretResponse.value())); + // END: com.azure.keyvault.secrets.secretclient.setSecret#secret + + // BEGIN: com.azure.keyvault.secrets.secretclient.setSecret#string-string + secretAsyncClient.setSecret("secretName", "secretValue") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponse -> + System.out.printf("Secret is created with name %s and value %s \n", + secretResponse.name(), secretResponse.value())); + // END: com.azure.keyvault.secrets.secretclient.setSecret#string-string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#setSecretWithResponse(Secret)} + */ + public void setSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.setSecretWithResponse#secret + Secret newSecret = new Secret("secretName", "secretValue"). + expires(OffsetDateTime.now().plusDays(60)); + secretAsyncClient.setSecretWithResponse(newSecret) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponse -> + System.out.printf("Secret is created with name %s and value %s \n", + secretResponse.value().name(), secretResponse.value().value())); + // END: com.azure.keyvault.secrets.secretclient.setSecretWithResponse#secret + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#updateSecret(SecretBase)} + */ + public void updateSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.updateSecret#secretBase + secretAsyncClient.getSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponseValue -> { + Secret secret = secretResponseValue; + //Update the not before time of the secret. + secret.notBefore(OffsetDateTime.now().plusDays(50)); + secretAsyncClient.updateSecret(secret) + .subscribe(secretResponse -> + System.out.printf("Secret's updated not before time %s \n", + secretResponse.notBefore().toString())); + }); + // END: com.azure.keyvault.secrets.secretclient.updateSecret#secretBase + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#updateSecretWithResponse(SecretBase)} + */ + public void updateSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.updateSecretWithResponse#secretBase + secretAsyncClient.getSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponseValue -> { + Secret secret = secretResponseValue; + //Update the not before time of the secret. + secret.notBefore(OffsetDateTime.now().plusDays(50)); + secretAsyncClient.updateSecretWithResponse(secret) + .subscribe(secretResponse -> + System.out.printf("Secret's updated not before time %s \n", + secretResponse.value().notBefore().toString())); + }); + // END: com.azure.keyvault.secrets.secretclient.updateSecretWithResponse#secretBase + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#deleteSecret(String)} + */ + public void deleteSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.deleteSecret#string + secretAsyncClient.deleteSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedSecretResponse -> + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); + // END: com.azure.keyvault.secrets.secretclient.deleteSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#deleteSecretWithResponse(String)} + */ + public void deleteSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.deleteSecretWithResponse#string + secretAsyncClient.deleteSecretWithResponse("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedSecretResponse -> + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + // END: com.azure.keyvault.secrets.secretclient.deleteSecretWithResponse#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#deleteSecret(String)} + */ + public void getDeletedSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.getDeletedSecret#string + secretAsyncClient.getDeletedSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedSecretResponse -> + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.recoveryId())); + // END: com.azure.keyvault.secrets.secretclient.getDeletedSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#getDeletedSecretWithResponse(String)} + */ + public void getDeletedSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.getDeletedSecretWithResponse#string + secretAsyncClient.getDeletedSecretWithResponse("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedSecretResponse -> + System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId())); + // END: com.azure.keyvault.secrets.secretclient.getDeletedSecretWithResponse#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#purgeDeletedSecret(String)} + */ + public void purgeDeletedSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.purgeDeletedSecret#string + secretAsyncClient.purgeDeletedSecret("deletedSecretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(purgeResponse -> + System.out.printf("Purge Status response %d \n", purgeResponse.statusCode())); + // END: com.azure.keyvault.secrets.secretclient.purgeDeletedSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#recoverDeletedSecret(String)} + */ + public void recoverDeletedSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.recoverDeletedSecret#string + secretAsyncClient.recoverDeletedSecret("deletedSecretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(recoveredSecretResponse -> + System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.name())); + // END: com.azure.keyvault.secrets.secretclient.recoverDeletedSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#recoverDeletedSecretWithResponse(String)} + */ + public void recoverDeletedSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.recoverDeletedSecretWithResponse#string + secretAsyncClient.recoverDeletedSecretWithResponse("deletedSecretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(recoveredSecretResponse -> + System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.value().name())); + // END: com.azure.keyvault.secrets.secretclient.recoverDeletedSecretWithResponse#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#backupSecret(String)} + */ + public void backupSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.backupSecret#string + secretAsyncClient.backupSecret("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBackupResponse -> + System.out.printf("Secret's Backup Byte array's length %s \n", secretBackupResponse.length)); + // END: com.azure.keyvault.secrets.secretclient.backupSecret#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#backupSecretWithResponse(String)} + */ + public void backupSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.backupSecretWithResponse#string + secretAsyncClient.backupSecretWithResponse("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBackupResponse -> + System.out.printf("Secret's Backup Byte array's length %s \n", secretBackupResponse.value().length)); + // END: com.azure.keyvault.secrets.secretclient.backupSecretWithResponse#string + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#restoreSecret(byte[])} + */ + public void restoreSecretCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.restoreSecret#byte + byte[] secretBackupByteArray = {}; + secretAsyncClient.restoreSecret(secretBackupByteArray) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponse -> System.out.printf("Restored Secret with name %s and value %s \n", + secretResponse.name(), secretResponse.value())); + // END: com.azure.keyvault.secrets.secretclient.restoreSecret#byte + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#restoreSecretWithResponse(byte[])} + */ + public void restoreSecretWithResponseCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.restoreSecretWithResponse#byte + byte[] secretBackupByteArray = {}; + secretAsyncClient.restoreSecretWithResponse(secretBackupByteArray) + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretResponse -> System.out.printf("Restored Secret with name %s and value %s \n", + secretResponse.value().name(), secretResponse.value().value())); + // END: com.azure.keyvault.secrets.secretclient.restoreSecretWithResponse#byte + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#listSecrets()} + */ + public void listSecretsCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.listSecrets + secretAsyncClient.listSecrets() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBase -> secretAsyncClient.getSecret(secretBase) + .subscribe(secretResponse -> System.out.printf("Received secret with name %s and type %s", + secretResponse.name(), secretResponse.value()))); + // END: com.azure.keyvault.secrets.secretclient.listSecrets + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#listDeletedSecrets()} + */ + public void listDeletedSecretsCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.listDeletedSecrets + secretAsyncClient.listDeletedSecrets() + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(deletedSecretResponse -> System.out.printf("Deleted Secret's Recovery Id %s \n", + deletedSecretResponse.recoveryId())); + // END: com.azure.keyvault.secrets.secretclient.listDeletedSecrets + } + + /** + * Method to insert code snippets for {@link SecretAsyncClient#listSecretVersions(String)} + */ + public void listSecretVersionsCodeSnippets() { + SecretAsyncClient secretAsyncClient = getAsyncSecretClient(); + // BEGIN: com.azure.keyvault.secrets.secretclient.listSecretVersions#string + secretAsyncClient.listSecretVersions("secretName") + .subscriberContext(Context.of(key1, value1, key2, value2)) + .subscribe(secretBase -> secretAsyncClient.getSecret(secretBase) + .subscribe(secretResponse -> System.out.printf("Received secret with name %s and type %s", + secretResponse.name(), secretResponse.value()))); + // END: com.azure.keyvault.secrets.secretclient.listSecretVersions#string + } +} diff --git a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java index 7b92e5986b42e..8b1bea4c6f79b 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java @@ -3,75 +3,334 @@ package com.azure.security.keyvault.secrets; -import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; import com.azure.core.http.policy.HttpLogDetailLevel; -import com.azure.core.test.models.RecordedData; -import com.azure.core.test.policy.RecordNetworkCallPolicy; +import com.azure.core.http.rest.VoidResponse; +import com.azure.core.util.Context; import com.azure.identity.credential.DefaultAzureCredential; +import com.azure.security.keyvault.secrets.models.DeletedSecret; import com.azure.security.keyvault.secrets.models.Secret; import com.azure.security.keyvault.secrets.models.SecretBase; +import java.time.OffsetDateTime; + /** * This class contains code samples for generating javadocs through doclets for {@link SecretClient} */ public final class SecretClientJavaDocCodeSnippets { - /** - * Generates code sample for creating a {@link SecretAsyncClient} - * @return An instance of {@link SecretAsyncClient} - */ - public SecretAsyncClient createAsyncClientWithHttpclient() { - // BEGIN: com.azure.security.keyvault.keys.async.secretclient.withhttpclient.instantiation - RecordedData networkData = new RecordedData(); - HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); - SecretAsyncClient keyClient = new SecretClientBuilder() - .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) - .endpoint("https://myvault.azure.net/") - .credential(new DefaultAzureCredential()) - .addPolicy(new RecordNetworkCallPolicy(networkData)) - .httpClient(HttpClient.createDefault()) - .buildAsyncClient(); - // END: com.azure.security.keyvault.keys.async.secretclient.withhttpclient.instantiation - return keyClient; - } + private String key1 = "key1"; + private String key2 = "key2"; + private String value1 = "val1"; + private String value2 = "val2"; /** * Method to insert code snippets for {@link SecretClient#getSecret(SecretBase)} */ - public void getSecret() { + public void getSecretCodeSnippets() { SecretClient secretClient = getSecretClient(); // BEGIN: com.azure.security.keyvault.secretclient.getSecret#secretBase for (SecretBase secret : secretClient.listSecrets()) { - Secret secretWithValue = secretClient.getSecret(secret).value(); + Secret secretWithValue = secretClient.getSecret(secret); System.out.printf("Secret is returned with name %s and value %s %n", secretWithValue.name(), secretWithValue.value()); } // END: com.azure.security.keyvault.secretclient.getSecret#secretBase + + // BEGIN: com.azure.security.keyvault.secretclient.getSecret#string-string + String secretVersion = "6A385B124DEF4096AF1361A85B16C204"; + Secret secretWithVersion = secretClient.getSecret("secretName", secretVersion); + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithVersion.name(), secretWithVersion.value()); + // END: com.azure.security.keyvault.secretclient.getSecret#string-string + + // BEGIN: com.azure.security.keyvault.secretclient.getSecret#string + Secret secretWithoutVersion = secretClient.getSecret("secretName", secretVersion); + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithoutVersion.name(), secretWithoutVersion.value()); + // END: com.azure.security.keyvault.secretclient.getSecret#string } /** - * Implementation for async SecretAsyncClient - * @return sync SecretAsyncClient + * Method to insert code snippets for {@link SecretClient#getSecretWithResponse(String, String, Context)} */ - private SecretAsyncClient getAsyncSecretClient() { + public void getSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.getSecretWithResponse#secretBase + for (SecretBase secret : secretClient.listSecrets()) { + Secret secretWithValue = secretClient.getSecretWithResponse(secret, new Context(key2, value2)).value(); + System.out.printf("Secret is returned with name %s and value %s %n", secretWithValue.name(), + secretWithValue.value()); + } + // END: com.azure.security.keyvault.secretclient.getSecretWithResponse#secretBase - // BEGIN: com.azure.security.keyvault.secretclient.async.construct - SecretAsyncClient secretClient = new SecretClientBuilder() - .credential(new DefaultAzureCredential()) - .endpoint("https://myvault.vault.azure.net/") - .httpLogDetailLevel(HttpLogDetailLevel.BODY_AND_HEADERS) - .buildAsyncClient(); - // END: com.azure.security.keyvault.secretclient.async.construct - return secretClient; + // BEGIN: com.azure.security.keyvault.secretclient.getSecretWithResponse#string-string-Context + String secretVersion = "6A385B124DEF4096AF1361A85B16C204"; + Secret secretWithVersion = secretClient.getSecretWithResponse("secretName", secretVersion, + new Context(key2, value2)).value(); + System.out.printf("Secret is returned with name %s and value %s \n", + secretWithVersion.name(), secretWithVersion.value()); + // END: com.azure.security.keyvault.secretclient.getSecretWithResponse#string-string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#setSecret(Secret)} + */ + public void setSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.setSecret#secret + Secret newSecret = new Secret("secretName", "secretValue").expires(OffsetDateTime.now().plusDays(60)); + Secret returnedSecret = secretClient.setSecret(newSecret); + System.out.printf("Secret is created with name %s and value %s \n", returnedSecret.name(), returnedSecret.value()); + // END: com.azure.security.keyvault.secretclient.setSecret#secret + + // BEGIN: com.azure.security.keyvault.secretclient.setSecret#string-string + Secret secret = secretClient.setSecret("secretName", "secretValue"); + System.out.printf("Secret is created with name %s and value %s \n", secret.name(), secret.value()); + // END: com.azure.security.keyvault.secretclient.setSecret#string-string + } + + /** + * Method to insert code snippets for {@link SecretClient#setSecretWithResponse(Secret Context)} + */ + public void setSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.setSecretWithResponse#secret-Context + Secret newSecret = new Secret("secretName", "secretValue").expires(OffsetDateTime.now().plusDays(60)); + Secret secret = secretClient.setSecretWithResponse(newSecret, new Context(key1, value1)).value(); + System.out.printf("Secret is created with name %s and value %s \n", secret.name(), secret.value()); + // END: com.azure.security.keyvault.secretclient.setSecretWithResponse#secret-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#updateSecret(SecretBase)} + */ + public void updateSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.updateSecret#secretBase + Secret secret = secretClient.getSecret("secretName"); + secret.expires(OffsetDateTime.now().plusDays(60)); + SecretBase updatedSecretBase = secretClient.updateSecret(secret); + Secret updatedSecret = secretClient.getSecret(updatedSecretBase.name()); + System.out.printf("Updated Secret is returned with name %s, value %s and expires %s \n", + updatedSecret.name(), updatedSecret.value(), updatedSecret.expires()); + // END: com.azure.security.keyvault.secretclient.updateSecret#secretBase + } + + /** + * Method to insert code snippets for {@link SecretClient#updateSecretWithResponse(SecretBase, Context)} + */ + public void updateSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.updateSecretWithResponse#secretBase-Context + Secret secret = secretClient.getSecret("secretName"); + secret.expires(OffsetDateTime.now().plusDays(60)); + SecretBase updatedSecretBase = secretClient.updateSecretWithResponse(secret, new Context(key2, value2)).value(); + Secret updatedSecret = secretClient.getSecret(updatedSecretBase.name()); + System.out.printf("Updated Secret is returned with name %s, value %s and expires %s \n", + updatedSecret.name(), updatedSecret.value(), updatedSecret.expires()); + // END: com.azure.security.keyvault.secretclient.updateSecretWithResponse#secretBase-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#deleteSecret(String)} + */ + public void deleteSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.deleteSecret#string + DeletedSecret deletedSecret = secretClient.deleteSecret("secretName"); + System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()); + // END: com.azure.security.keyvault.secretclient.deleteSecret#string + } + + /** + * Method to insert code snippets for {@link SecretClient#deleteSecretWithResponse(String, Context)} + */ + public void deleteSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.deleteSecretWithResponse#string-Context + DeletedSecret deletedSecret = secretClient.deleteSecretWithResponse("secretName", + new Context(key2, value2)).value(); + System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()); + // END: com.azure.security.keyvault.secretclient.deleteSecretWithResponse#string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#deleteSecret(String)} + */ + public void getDeletedSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.getDeletedSecret#string + DeletedSecret deletedSecret = secretClient.getDeletedSecret("secretName"); + System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()); + // END: com.azure.security.keyvault.secretclient.getDeletedSecret#string + } + + /** + * Method to insert code snippets for {@link SecretClient#getDeletedSecretWithResponse(String, Context)} + */ + public void getDeletedSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.getDeletedSecretWithResponse#string-Context + DeletedSecret deletedSecret = secretClient.getDeletedSecretWithResponse("secretName", + new Context(key2, value2)).value(); + System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()); + // END: com.azure.security.keyvault.secretclient.getDeletedSecretWithResponse#string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#purgeDeletedSecret(String)} + */ + public void purgeDeletedSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.purgeDeletedSecret#string + VoidResponse purgeResponse = secretClient.purgeDeletedSecret("secretName"); + System.out.printf("Purge Status Code: %d", purgeResponse.statusCode()); + // END: com.azure.security.keyvault.secretclient.purgeDeletedSecret#string + + // BEGIN: com.azure.security.keyvault.secretclient.purgeDeletedSecret#string-Context + VoidResponse purgedResponse = secretClient.purgeDeletedSecret("secretName", new Context(key2, value2)); + System.out.printf("Purge Status Code: %d", purgedResponse.statusCode()); + // END: com.azure.security.keyvault.secretclient.purgeDeletedSecret#string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#recoverDeletedSecret(String)} + */ + public void recoverDeletedSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.recoverDeletedSecret#string + Secret recoveredSecret = secretClient.recoverDeletedSecret("secretName"); + System.out.printf("Recovered Secret with name %s", recoveredSecret.name()); + // END: com.azure.security.keyvault.secretclient.recoverDeletedSecret#string + } + + /** + * Method to insert code snippets for {@link SecretClient#recoverDeletedSecretWithResponse(String, Context)} + */ + public void recoverDeletedSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.recoverDeletedSecretWithResponse#string-Context + Secret recoveredSecret = secretClient.recoverDeletedSecretWithResponse("secretName", + new Context(key1, value1)).value(); + System.out.printf("Recovered Secret with name %s", recoveredSecret.name()); + // END: com.azure.security.keyvault.secretclient.recoverDeletedSecretWithResponse#string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#backupSecret(String)} + */ + public void backupSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.backupSecret#string + byte[] secretBackup = secretClient.backupSecret("secretName"); + System.out.printf("Secret's Backup Byte array's length %s", secretBackup.length); + // END: com.azure.security.keyvault.secretclient.backupSecret#string + } + + /** + * Method to insert code snippets for {@link SecretClient#backupSecretWithResponse(String, Context)} + */ + public void backupSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.backupSecretWithResponse#string-Context + byte[] secretBackup = secretClient.backupSecretWithResponse("secretName", + new Context(key1, value1)).value(); + System.out.printf("Secret's Backup Byte array's length %s", secretBackup.length); + // END: com.azure.security.keyvault.secretclient.backupSecretWithResponse#string-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#restoreSecret(byte[])} + */ + public void restoreSecretCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.restoreSecret#byte + byte[] secretBackupByteArray = {}; + Secret restoredSecret = secretClient.restoreSecret(secretBackupByteArray); + System.out.printf("Restored Secret with name %s and value %s", restoredSecret.name(), restoredSecret.value()); + // END: com.azure.security.keyvault.secretclient.restoreSecret#byte + } + + /** + * Method to insert code snippets for {@link SecretClient#restoreSecretWithResponse(byte[], Context)} + */ + public void restoreSecretWithResponseCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.restoreSecretWithResponse#byte-Context + byte[] secretBackupByteArray = {}; + Secret restoredSecret = secretClient.restoreSecretWithResponse(secretBackupByteArray, + new Context(key2, value2)).value(); + System.out.printf("Restored Secret with name %s and value %s", restoredSecret.name(), restoredSecret.value()); + // END: com.azure.security.keyvault.secretclient.restoreSecretWithResponse#byte-Context + } + + /** + * Method to insert code snippets for {@link SecretClient#listSecrets()} + */ + public void listSecretsCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.listSecrets + for (SecretBase secret : secretClient.listSecrets()) { + Secret secretWithValue = secretClient.getSecret(secret); + System.out.printf("Received secret with name %s and value %s", + secretWithValue.name(), secretWithValue.value()); + } + // END: com.azure.security.keyvault.secretclient.listSecrets + + // BEGIN: com.azure.security.keyvault.secretclient.listSecrets#Context + for (SecretBase secret : secretClient.listSecrets(new Context(key1, value2))) { + Secret secretWithValue = secretClient.getSecret(secret); + System.out.printf("Received secret with name %s and value %s", + secretWithValue.name(), secretWithValue.value()); + } + // END: com.azure.security.keyvault.secretclient.listSecrets#Context + } + + /** + * Method to insert code snippets for {@link SecretClient#listDeletedSecrets()} + */ + public void listDeletedSecretsCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.listDeletedSecrets + for (DeletedSecret deletedSecret : secretClient.listDeletedSecrets()) { + System.out.printf("Deleted secret's recovery Id %s", deletedSecret.recoveryId()); + } + // END: com.azure.security.keyvault.secretclient.listDeletedSecrets + + // BEGIN: com.azure.security.keyvault.secretclient.listDeletedSecrets#Context + for (DeletedSecret deletedSecret : secretClient.listDeletedSecrets(new Context(key1, value2))) { + System.out.printf("Deleted secret's recovery Id %s", deletedSecret.recoveryId()); + } + // END: com.azure.security.keyvault.secretclient.listDeletedSecrets#Context + } + + /** + * Method to insert code snippets for {@link SecretClient#listSecretVersions(String)} + */ + public void listSecretVersionsCodeSnippets() { + SecretClient secretClient = getSecretClient(); + // BEGIN: com.azure.security.keyvault.secretclient.listSecretVersions#string + for (SecretBase secret : secretClient.listSecretVersions("secretName")) { + Secret secretWithValue = secretClient.getSecret(secret); + System.out.printf("Received secret's version with name %s and value %s", + secretWithValue.name(), secretWithValue.value()); + } + // END: com.azure.security.keyvault.secretclient.listSecretVersions#string + + // BEGIN: com.azure.security.keyvault.secretclient.listSecretVersions#string-Context + for (SecretBase secret : secretClient.listSecretVersions("secretName", new Context(key1, value2))) { + Secret secretWithValue = secretClient.getSecret(secret); + System.out.printf("Received secret's version with name %s and value %s", + secretWithValue.name(), secretWithValue.value()); + } + // END: com.azure.security.keyvault.secretclient.listSecretVersions#string-Context } /** * Implementation for sync SecretClient * @return sync SecretClient */ - private SecretClient getSyncSecretClient() { + private SecretClient getSyncSecretClientCodeSnippets() { // BEGIN: com.azure.security.keyvault.secretclient.sync.construct SecretClient secretClient = new SecretClientBuilder() @@ -83,23 +342,6 @@ private SecretClient getSyncSecretClient() { return secretClient; } - /** - * Generates code sample for creating a {@link SecretAsyncClient} - * @return An instance of {@link SecretAsyncClient} - */ - public SecretAsyncClient createAsyncClientWithPipeline() { - // BEGIN: com.azure.security.keyvault.keys.async.secretclient.pipeline.instantiation - RecordedData networkData = new RecordedData(); - HttpPipeline pipeline = new HttpPipelineBuilder().policies(new RecordNetworkCallPolicy(networkData)).build(); - SecretAsyncClient keyClient = new SecretClientBuilder() - .pipeline(pipeline) - .endpoint("https://myvault.azure.net/") - .credential(new DefaultAzureCredential()) - .buildAsyncClient(); - // END: com.azure.security.keyvault.keys.async.secretclient.pipeline.instantiation - return keyClient; - } - /** * Implementation not provided for this method * @return {@code null} diff --git a/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretAsyncClientTest.java b/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretAsyncClientTest.java index 1f47223f0b406..3c56735a1e9e0 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretAsyncClientTest.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretAsyncClientTest.java @@ -100,12 +100,12 @@ public void updateSecret() { StepVerifier.create(client.setSecret(original)) .assertNext(response -> assertSecretEquals(original, response)) .verifyComplete(); - Secret secretToUpdate = client.getSecret(original.name()).block().value(); + Secret secretToUpdate = client.getSecret(original.name()).block(); StepVerifier.create(client.updateSecret(secretToUpdate.expires(updated.expires()))) .assertNext(response -> { - assertNotNull(response.value()); - Assert.assertEquals(original.name(), response.value().name()); + assertNotNull(response); + Assert.assertEquals(original.name(), response.name()); }).verifyComplete(); StepVerifier.create(client.getSecret(original.name())) @@ -146,8 +146,8 @@ public void getSecret() { */ public void getSecretSpecificVersion() { getSecretSpecificVersionRunner((secret, secretWithNewVal) -> { - final Secret secretVersionOne = client.setSecret(secret).block().value(); - final Secret secretVersionTwo = client.setSecret(secretWithNewVal).block().value(); + final Secret secretVersionOne = client.setSecret(secret).block(); + final Secret secretVersionTwo = client.setSecret(secretWithNewVal).block(); StepVerifier.create(client.getSecret(secret.name(), secretVersionOne.version())) .assertNext(response -> assertSecretEquals(secret, response)) @@ -175,16 +175,15 @@ public void deleteSecret() { deleteSecretRunner((secretToDelete) -> { StepVerifier.create(client.setSecret(secretToDelete)) .assertNext(secretResponse -> { - assertSecretEquals(secretToDelete, secretResponse.value()); + assertSecretEquals(secretToDelete, secretResponse); }).verifyComplete(); StepVerifier.create(client.deleteSecret(secretToDelete.name())) .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret.deletedDate()); - assertNotNull(deletedSecret.recoveryId()); - assertNotNull(deletedSecret.scheduledPurgeDate()); - Assert.assertEquals(secretToDelete.name(), deletedSecret.name()); + assertNotNull(deletedSecretResponse.deletedDate()); + assertNotNull(deletedSecretResponse.recoveryId()); + assertNotNull(deletedSecretResponse.scheduledPurgeDate()); + Assert.assertEquals(secretToDelete.name(), deletedSecretResponse.name()); }).verifyComplete(); sleepInRecordMode(30000); @@ -208,24 +207,22 @@ public void getDeletedSecret() { getDeletedSecretRunner((secretToDeleteAndGet) -> { StepVerifier.create(client.setSecret(secretToDeleteAndGet)) .assertNext(secretResponse -> { - assertSecretEquals(secretToDeleteAndGet, secretResponse.value()); + assertSecretEquals(secretToDeleteAndGet, secretResponse); }).verifyComplete(); StepVerifier.create(client.deleteSecret(secretToDeleteAndGet.name())) .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret); + assertNotNull(deletedSecretResponse); }).verifyComplete(); pollOnSecretDeletion(secretToDeleteAndGet.name()); sleepInRecordMode(30000); StepVerifier.create(client.getDeletedSecret(secretToDeleteAndGet.name())) .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret.deletedDate()); - assertNotNull(deletedSecret.recoveryId()); - assertNotNull(deletedSecret.scheduledPurgeDate()); - Assert.assertEquals(secretToDeleteAndGet.name(), deletedSecret.name()); + assertNotNull(deletedSecretResponse.deletedDate()); + assertNotNull(deletedSecretResponse.recoveryId()); + assertNotNull(deletedSecretResponse.scheduledPurgeDate()); + Assert.assertEquals(secretToDeleteAndGet.name(), deletedSecretResponse.name()); }).verifyComplete(); StepVerifier.create(client.purgeDeletedSecret(secretToDeleteAndGet.name())) @@ -252,22 +249,18 @@ public void recoverDeletedSecret() { recoverDeletedSecretRunner((secretToDeleteAndRecover) -> { StepVerifier.create(client.setSecret(secretToDeleteAndRecover)) .assertNext(secretResponse -> { - assertSecretEquals(secretToDeleteAndRecover, secretResponse.value()); + assertSecretEquals(secretToDeleteAndRecover, secretResponse); }).verifyComplete(); StepVerifier.create(client.deleteSecret(secretToDeleteAndRecover.name())) - .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); sleepInRecordMode(30000); StepVerifier.create(client.recoverDeletedSecret(secretToDeleteAndRecover.name())) .assertNext(secretResponse -> { - Secret recoveredSecret = secretResponse.value(); - Assert.assertEquals(secretToDeleteAndRecover.name(), recoveredSecret.name()); - Assert.assertEquals(secretToDeleteAndRecover.notBefore(), recoveredSecret.notBefore()); - Assert.assertEquals(secretToDeleteAndRecover.expires(), recoveredSecret.expires()); + Assert.assertEquals(secretToDeleteAndRecover.name(), secretResponse.name()); + Assert.assertEquals(secretToDeleteAndRecover.notBefore(), secretResponse.notBefore()); + Assert.assertEquals(secretToDeleteAndRecover.expires(), secretResponse.expires()); }).verifyComplete(); }); } @@ -287,12 +280,12 @@ public void backupSecret() { backupSecretRunner((secretToBackup) -> { StepVerifier.create(client.setSecret(secretToBackup)) .assertNext(secretResponse -> { - assertSecretEquals(secretToBackup, secretResponse.value()); + assertSecretEquals(secretToBackup, secretResponse); }).verifyComplete(); StepVerifier.create(client.backupSecret(secretToBackup.name())) .assertNext(response -> { - byte[] backupBytes = response.value(); + byte[] backupBytes = response; assertNotNull(backupBytes); assertTrue(backupBytes.length > 0); }).verifyComplete(); @@ -314,15 +307,12 @@ public void restoreSecret() { restoreSecretRunner((secretToBackupAndRestore) -> { StepVerifier.create(client.setSecret(secretToBackupAndRestore)) .assertNext(secretResponse -> { - assertSecretEquals(secretToBackupAndRestore, secretResponse.value()); + assertSecretEquals(secretToBackupAndRestore, secretResponse); }).verifyComplete(); - byte[] backup = client.backupSecret(secretToBackupAndRestore.name()).block().value(); + byte[] backup = client.backupSecret(secretToBackupAndRestore.name()).block(); StepVerifier.create(client.deleteSecret(secretToBackupAndRestore.name())) - .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnSecretDeletion(secretToBackupAndRestore.name()); StepVerifier.create(client.purgeDeletedSecret(secretToBackupAndRestore.name())) @@ -335,10 +325,9 @@ public void restoreSecret() { StepVerifier.create(client.restoreSecret(backup)) .assertNext(response -> { - Secret restoredSecret = response.value(); - Assert.assertEquals(secretToBackupAndRestore.name(), restoredSecret.name()); - Assert.assertEquals(secretToBackupAndRestore.notBefore(), restoredSecret.notBefore()); - Assert.assertEquals(secretToBackupAndRestore.expires(), restoredSecret.expires()); + Assert.assertEquals(secretToBackupAndRestore.name(), response.name()); + Assert.assertEquals(secretToBackupAndRestore.notBefore(), response.notBefore()); + Assert.assertEquals(secretToBackupAndRestore.expires(), response.expires()); }).verifyComplete(); }); } @@ -358,23 +347,19 @@ public void restoreSecretFromMalformedBackup() { @Override public void listDeletedSecrets() { listDeletedSecretsRunner((secrets) -> { - HashMap secretsToDelete = secrets; List deletedSecrets = new ArrayList<>(); - for (Secret secret : secretsToDelete.values()) { + for (Secret secret : secrets.values()) { StepVerifier.create(client.setSecret(secret)) .assertNext(secretResponse -> { - assertSecretEquals(secret, secretResponse.value()); + assertSecretEquals(secret, secretResponse); }).verifyComplete(); } sleepInRecordMode(10000); - for (Secret secret : secretsToDelete.values()) { + for (Secret secret : secrets.values()) { StepVerifier.create(client.deleteSecret(secret.name())) - .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnSecretDeletion(secret.name()); } @@ -383,14 +368,14 @@ public void listDeletedSecrets() { sleepInRecordMode(30000); for (DeletedSecret actualSecret : deletedSecrets) { - if (secretsToDelete.containsKey(actualSecret.name())) { + if (secrets.containsKey(actualSecret.name())) { assertNotNull(actualSecret.deletedDate()); assertNotNull(actualSecret.recoveryId()); - secretsToDelete.remove(actualSecret.name()); + secrets.remove(actualSecret.name()); } } - assertEquals(0, secretsToDelete.size()); + assertEquals(0, secrets.size()); for (DeletedSecret deletedSecret : deletedSecrets) { StepVerifier.create(client.purgeDeletedSecret(deletedSecret.name())) @@ -408,25 +393,21 @@ public void listDeletedSecrets() { @Override public void listSecretVersions() { listSecretVersionsRunner((secrets) -> { - List secretVersions = secrets; List output = new ArrayList<>(); String secretName = null; - for (Secret secret : secretVersions) { + for (Secret secret : secrets) { secretName = secret.name(); - client.setSecret(secret).subscribe(secretResponse -> assertSecretEquals(secret, secretResponse.value())); + client.setSecret(secret).subscribe(secretResponse -> assertSecretEquals(secret, secretResponse)); sleepInRecordMode(1000); } sleepInRecordMode(30000); client.listSecretVersions(secretName).subscribe(output::add); sleepInRecordMode(30000); - assertEquals(secretVersions.size(), output.size()); + assertEquals(secrets.size(), output.size()); StepVerifier.create(client.deleteSecret(secretName)) - .assertNext(deletedSecretResponse -> { - DeletedSecret deletedSecret = deletedSecretResponse.value(); - assertNotNull(deletedSecret); - }).verifyComplete(); + .assertNext(Assert::assertNotNull).verifyComplete(); pollOnSecretDeletion(secretName); @@ -447,7 +428,7 @@ public void listSecrets() { HashMap secretsToList = secrets; List output = new ArrayList<>(); for (Secret secret : secretsToList.values()) { - client.setSecret(secret).subscribe(secretResponse -> assertSecretEquals(secret, secretResponse.value())); + client.setSecret(secret).subscribe(secretResponse -> assertSecretEquals(secret, secretResponse)); sleepInRecordMode(1000); } sleepInRecordMode(30000); @@ -466,43 +447,39 @@ public void listSecrets() { }); } - private DeletedSecret pollOnSecretDeletion(String secretName) { + private void pollOnSecretDeletion(String secretName) { int pendingPollCount = 0; while (pendingPollCount < 30) { DeletedSecret deletedSecret = null; try { - deletedSecret = client.getDeletedSecret(secretName).block().value(); + deletedSecret = client.getDeletedSecret(secretName).block(); } catch (ResourceNotFoundException e) { } if (deletedSecret == null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedSecret; + return; } } System.err.printf("Deleted Secret %s not found \n", secretName); - return null; } - private DeletedSecret pollOnSecretPurge(String secretName) { + private void pollOnSecretPurge(String secretName) { int pendingPollCount = 0; while (pendingPollCount < 10) { DeletedSecret deletedSecret = null; try { - deletedSecret = client.getDeletedSecret(secretName).block().value(); + deletedSecret = client.getDeletedSecret(secretName).block(); } catch (ResourceNotFoundException e) { } if (deletedSecret != null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedSecret; + return; } } System.err.printf("Deleted Secret %s was not purged \n", secretName); - return null; } } diff --git a/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretClientTest.java b/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretClientTest.java index 3500c5dec3c7c..12cfe2a3b84fb 100644 --- a/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretClientTest.java +++ b/sdk/keyvault/azure-keyvault-secrets/src/test/java/com/azure/security/keyvault/secrets/SecretClientTest.java @@ -14,7 +14,6 @@ import io.netty.handler.codec.http.HttpResponseStatus; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import static org.junit.Assert.assertEquals; @@ -85,7 +84,7 @@ public void setSecretNull() { public void updateSecret() { updateSecretRunner((original, updated) -> { assertSecretEquals(original, client.setSecret(original)); - Secret secretToUpdate = client.getSecret(original.name()).value(); + Secret secretToUpdate = client.getSecret(original.name()); client.updateSecret(secretToUpdate.expires(updated.expires())); assertSecretEquals(updated, client.getSecret(original.name())); }); @@ -116,8 +115,8 @@ public void getSecret() { */ public void getSecretSpecificVersion() { getSecretSpecificVersionRunner((secret, secretWithNewVal) -> { - Secret secretVersionOne = client.setSecret(secret).value(); - Secret secretVersionTwo = client.setSecret(secretWithNewVal).value(); + Secret secretVersionOne = client.setSecret(secret); + Secret secretVersionTwo = client.setSecret(secretWithNewVal); assertSecretEquals(secret, client.getSecret(secretVersionOne.name(), secretVersionOne.version())); assertSecretEquals(secretWithNewVal, client.getSecret(secretVersionTwo.name(), secretVersionTwo.version())); }); @@ -136,7 +135,7 @@ public void getSecretNotFound() { public void deleteSecret() { deleteSecretRunner((secretToDelete) -> { assertSecretEquals(secretToDelete, client.setSecret(secretToDelete)); - DeletedSecret deletedSecret = client.deleteSecret(secretToDelete.name()).value(); + DeletedSecret deletedSecret = client.deleteSecret(secretToDelete.name()); pollOnSecretDeletion(secretToDelete.name()); assertNotNull(deletedSecret.deletedDate()); assertNotNull(deletedSecret.recoveryId()); @@ -157,10 +156,10 @@ public void deleteSecretNotFound() { public void getDeletedSecret() { getDeletedSecretRunner((secretToDeleteAndGet) -> { assertSecretEquals(secretToDeleteAndGet, client.setSecret(secretToDeleteAndGet)); - assertNotNull(client.deleteSecret(secretToDeleteAndGet.name()).value()); + assertNotNull(client.deleteSecret(secretToDeleteAndGet.name())); pollOnSecretDeletion(secretToDeleteAndGet.name()); sleepInRecordMode(30000); - DeletedSecret deletedSecret = client.getDeletedSecret(secretToDeleteAndGet.name()).value(); + DeletedSecret deletedSecret = client.getDeletedSecret(secretToDeleteAndGet.name()); assertNotNull(deletedSecret.deletedDate()); assertNotNull(deletedSecret.recoveryId()); assertNotNull(deletedSecret.scheduledPurgeDate()); @@ -185,9 +184,9 @@ public void getDeletedSecretNotFound() { public void recoverDeletedSecret() { recoverDeletedSecretRunner((secretToDeleteAndRecover) -> { assertSecretEquals(secretToDeleteAndRecover, client.setSecret(secretToDeleteAndRecover)); - assertNotNull(client.deleteSecret(secretToDeleteAndRecover.name()).value()); + assertNotNull(client.deleteSecret(secretToDeleteAndRecover.name())); pollOnSecretDeletion(secretToDeleteAndRecover.name()); - Secret recoveredSecret = client.recoverDeletedSecret(secretToDeleteAndRecover.name()).value(); + Secret recoveredSecret = client.recoverDeletedSecret(secretToDeleteAndRecover.name()); assertEquals(secretToDeleteAndRecover.name(), recoveredSecret.name()); assertEquals(secretToDeleteAndRecover.notBefore(), recoveredSecret.notBefore()); assertEquals(secretToDeleteAndRecover.expires(), recoveredSecret.expires()); @@ -207,7 +206,7 @@ public void recoverDeletedSecretNotFound() { public void backupSecret() { backupSecretRunner((secretToBackup) -> { assertSecretEquals(secretToBackup, client.setSecret(secretToBackup)); - byte[] backupBytes = (client.backupSecret(secretToBackup.name()).value()); + byte[] backupBytes = (client.backupSecret(secretToBackup.name())); assertNotNull(backupBytes); assertTrue(backupBytes.length > 0); }); @@ -226,7 +225,7 @@ public void backupSecretNotFound() { public synchronized void restoreSecret() { restoreSecretRunner((secretToBackupAndRestore) -> { assertSecretEquals(secretToBackupAndRestore, client.setSecret(secretToBackupAndRestore)); - byte[] backupBytes = (client.backupSecret(secretToBackupAndRestore.name()).value()); + byte[] backupBytes = (client.backupSecret(secretToBackupAndRestore.name())); assertNotNull(backupBytes); assertTrue(backupBytes.length > 0); client.deleteSecret(secretToBackupAndRestore.name()); @@ -234,7 +233,7 @@ public synchronized void restoreSecret() { client.purgeDeletedSecret(secretToBackupAndRestore.name()); pollOnSecretPurge(secretToBackupAndRestore.name()); sleepInRecordMode(60000); - Secret restoredSecret = client.restoreSecret(backupBytes).value(); + Secret restoredSecret = client.restoreSecret(backupBytes); assertEquals(secretToBackupAndRestore.name(), restoredSecret.name()); assertEquals(secretToBackupAndRestore.expires(), restoredSecret.expires()); }); @@ -253,13 +252,12 @@ public void restoreSecretFromMalformedBackup() { */ public void listSecrets() { listSecretsRunner((secrets) -> { - HashMap secretsToList = secrets; - for (Secret secret : secretsToList.values()) { + for (Secret secret : secrets.values()) { assertSecretEquals(secret, client.setSecret(secret)); } for (SecretBase actualSecret : client.listSecrets()) { - if (secretsToList.containsKey(actualSecret.name())) { + if (secrets.containsKey(actualSecret.name())) { Secret expectedSecret = secrets.get(actualSecret.name()); assertEquals(expectedSecret.expires(), actualSecret.expires()); assertEquals(expectedSecret.notBefore(), actualSecret.notBefore()); @@ -277,12 +275,11 @@ public void listSecrets() { public void listDeletedSecrets() { listDeletedSecretsRunner((secrets) -> { - HashMap secretsToDelete = secrets; - for (Secret secret : secretsToDelete.values()) { + for (Secret secret : secrets.values()) { assertSecretEquals(secret, client.setSecret(secret)); } - for (Secret secret : secretsToDelete.values()) { + for (Secret secret : secrets.values()) { client.deleteSecret(secret.name()); pollOnSecretDeletion(secret.name()); } @@ -290,14 +287,14 @@ public void listDeletedSecrets() { sleepInRecordMode(60000); Iterable deletedSecrets = client.listDeletedSecrets(); for (DeletedSecret actualSecret : deletedSecrets) { - if (secretsToDelete.containsKey(actualSecret.name())) { + if (secrets.containsKey(actualSecret.name())) { assertNotNull(actualSecret.deletedDate()); assertNotNull(actualSecret.recoveryId()); - secretsToDelete.remove(actualSecret.name()); + secrets.remove(actualSecret.name()); } } - assertEquals(0, secretsToDelete.size()); + assertEquals(0, secrets.size()); for (DeletedSecret deletedSecret : deletedSecrets) { client.purgeDeletedSecret(deletedSecret.name()); @@ -334,43 +331,39 @@ public void listSecretVersions() { } - private DeletedSecret pollOnSecretDeletion(String secretName) { + private void pollOnSecretDeletion(String secretName) { int pendingPollCount = 0; while (pendingPollCount < 30) { DeletedSecret deletedSecret = null; try { - deletedSecret = client.getDeletedSecret(secretName).value(); + deletedSecret = client.getDeletedSecret(secretName); } catch (ResourceNotFoundException e) { } if (deletedSecret == null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedSecret; + return; } } System.err.printf("Deleted Secret %s not found \n", secretName); - return null; } - private DeletedSecret pollOnSecretPurge(String secretName) { + private void pollOnSecretPurge(String secretName) { int pendingPollCount = 0; while (pendingPollCount < 10) { DeletedSecret deletedSecret = null; try { - deletedSecret = client.getDeletedSecret(secretName).value(); + deletedSecret = client.getDeletedSecret(secretName); } catch (ResourceNotFoundException e) { } if (deletedSecret != null) { sleepInRecordMode(2000); pendingPollCount += 1; - continue; } else { - return deletedSecret; + return; } } System.err.printf("Deleted Secret %s was not purged \n", secretName); - return null; } }