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 @@
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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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}. 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. 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. Samples to construct the async client 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. 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. 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. 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. 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. 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
* //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
* //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
* //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
* //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
* //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
* //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
* //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
* //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
* //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
- * 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
- * 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
- * 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
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
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
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 MonoCode 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 @@ MonoCode 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
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* //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
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 @@ MonopurgeDeletedSecret(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 MonorecoverDeletedSecret(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 @@ MonopurgeDeletedSecret(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 MonobackupSecret(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 MonorestoreSecret(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 @@ PagedFluxlistSecretVersions(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 ResponsesetSecret(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 ResponsesetSecret(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 ResponsegetSecret(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 ResponsegetSecret(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 ResponsegetSecret(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 ResponsegetSecretWithResponse(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 ResponseupdateSecret(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 ResponseupdateSecret(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 ResponsedeleteSecret(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 ResponsedeleteSecretWithResponse(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 ResponsedeleteSecret(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 ResponsegetDeletedSecret(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 ResponsegetDeletedSecret(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 ResponserecoverDeletedSecret(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 ResponsebackupSecret(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 ResponsebackupSecretWithResponse(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 ResponserestoreSecret(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 ResponserestoreSecretWithResponse(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 IterablelistSecrets() { - 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 IterablelistSecrets(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 IterablelistDeletedSecrets(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 IterablelistDeletedSecrets() { - 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 IterablelistDeletedSecrets() { * @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 IterablelistSecretVersions(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 Listpolicies = 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; } }