From 426f09d0896b38e98ec3ed75a27b44561c56749e Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Sun, 21 Jul 2019 23:59:44 -0700
Subject: [PATCH 01/15] sync updates'
---
.../keyvault/secrets/SecretAsyncClient.java | 33 ++
.../keyvault/secrets/SecretClient.java | 335 ++++++++++++++++--
.../keyvault/secrets/SecretClientBuilder.java | 3 +
3 files changed, 346 insertions(+), 25 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 836e32d0ebfc2..3ecac3ae5ce80 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -65,6 +65,39 @@ public final class SecretAsyncClient {
this.service = RestProxy.create(SecretService.class, pipeline);
}
+ /**
+ * The set operation adds a secret to the key vault. If the named secret already exists, Azure Key Vault creates
+ * a new version of that secret. This operation requires the {@code secrets/set} permission.
+ *
+ * The {@link Secret} is required. The {@link Secret#expires() expires}, {@link Secret#contentType() contentType} and
+ * {@link Secret#notBefore() notBefore} values in {@code secret} are optional. The {@link Secret#enabled() enabled} field is
+ * set to true by key vault, if not specified.
+ *
+ * Code Samples
+ * Creates a new secret which activates in 1 day and expires in 1 year in the Azure Key Vault. Subscribes to the call asynchronously and
+ * prints out the newly created secret details when a response is received.
+ *
+ * Secret secret = new Secret("secretName", "secretValue")
+ * .notBefore(OffsetDateTime.now().plusDays(1))
+ * .expires(OffsetDateTime.now().plusDays(365));
+ *
+ * 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.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws NullPointerException if {@code secret} is {@code null}.
+ * @throws ResourceModifiedException if {@code secret} is malformed.
+ * @throws HttpRequestException if {@link Secret#name() name} or {@link Secret#value() value} is empty string.
+ * @return A {@link Mono} containing the {@link Secret created secret}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono setSecret(Secret secret, Context context) {
+ return withContext(context -> setSecret(secret, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
+ }
+
/**
* The set operation adds a secret to the key vault. If the named secret already exists, Azure Key Vault creates
* a new version of that secret. This operation requires the {@code secrets/set} permission.
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..88e2ec0cd9a27 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;
@@ -62,10 +63,10 @@ public final class SecretClient {
* @throws NullPointerException if {@code secret} is {@code null}.
* @throws ResourceModifiedException if {@code secret} is malformed.
* @throws HttpRequestException if {@link Secret#name() name} or {@link Secret#value() value} is empty string.
- * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}.
+ * @return The {@link Secret created secret}.
*/
- public Response setSecret(Secret secret) {
- return client.setSecret(secret).block();
+ public Secret setSecret(Secret secret) {
+ return client.setSecret(secret, Context.NONE).block().value();
}
/**
@@ -83,10 +84,32 @@ public Response setSecret(Secret secret) {
* @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.setSecret(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.
+ *
+ * Secret secret = secretClient.setSecret("secretName", "secretValue").value();
+ * System.out.printf("Secret is created with name %s and value %s \n", secret.name(), secret.value());
+ *
+ *
+ * @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.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceModifiedException if invalid {@code name} or {@code value} is specified.
+ * @throws HttpRequestException if {@code name} or {@code value} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}.
*/
- public Response setSecret(String name, String value) {
- return client.setSecret(name, value).block();
+ public Response setSecretWithResponse(String name, String value, Context context) {
+ return client.setSecret(name, value, context).block();
}
/**
@@ -105,10 +128,10 @@ public Response setSecret(String name, String value) {
* @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 A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
+ * @return The requested {@link Secret secret}.
*/
- public Response getSecret(String name, String version) {
- return client.getSecret(name, version).block();
+ public Secret getSecret(String name, String version) {
+ return client.getSecret(name, version, Context.NONE).block().value();
}
/**
@@ -121,12 +144,31 @@ public Response getSecret(String name, String version) {
* {@codesnippet com.azure.security.keyvault.secretclient.getSecret#secretBase}
*
* @param secretBase The {@link SecretBase base secret} holding attributes of the secret being requested.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
* @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault.
* @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
*/
- public Response getSecret(SecretBase secretBase) {
- return client.getSecret(secretBase).block();
+ public Response getSecretWithResponse(SecretBase secretBase, Context context) {
+ return client.getSecret(secretBase, context).block();
+ }
+
+ /**
+ * 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}.
+ * {@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 The requested {@link Secret secret}.
+ */
+ public Secret getSecret(SecretBase secretBase) {
+ return client.getSecret(secretBase, Context.NONE).block().value();
}
/**
@@ -143,12 +185,33 @@ public Response getSecret(SecretBase secretBase) {
* @param name The name of the secret.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
* @throws HttpRequestException if {@code name} is empty string.
- * @return A {@link Response} whose {@link Response#value()} contains the requested {@link Secret}.
+ * @return The requested {@link Secret}.
*/
- public Response getSecret(String name) {
+ public Secret getSecret(String name) {
return getSecret(name, "");
}
+ /**
+ * Get the latest version of the specified secret from the key vault. The get operation is applicable to any secret stored in Azure Key Vault.
+ * This operation requires the {@code secrets/get} permission.
+ *
+ * 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());
+ *
+ *
+ * @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 if {@code name} is empty string.
+ * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret}.
+ */
+ public Response getSecretWithResponse(String name, Context context) {
+ return client.getSecret(name, "", 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.
@@ -166,13 +229,40 @@ public Response getSecret(String name) {
*
*
* @param secret The {@link SecretBase base secret} object with updated properties.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
* @throws NullPointerException if {@code secret} is {@code null}.
* @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault.
* @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link SecretBase updated secret}.
*/
- public Response updateSecret(SecretBase secret) {
- return client.updateSecret(secret).block();
+ public Response updateSecretWithResponse(SecretBase secret, Context context) {
+ return client.updateSecret(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.
+ *
+ * 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();
+ *
+ *
+ * @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 client.updateSecret(secret, Context.NONE).block().value();
}
/**
@@ -192,8 +282,52 @@ public Response updateSecret(SecretBase secret) {
* @throws HttpRequestException when a secret with {@code name} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
- public Response deleteSecret(String name) {
- return client.deleteSecret(name).block();
+ public DeletedSecret deleteSecret(String name) {
+ return client.deleteSecret(name, Context.NONE).block().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.
+ *
+ * DeletedSecret deletedSecret = secretClient.deleteSecret("secretName").value();
+ * System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()));
+ *
+ *
+ * @param name The name of the secret to be deleted.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ * @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
+ */
+ public Response deleteSecretWithResponse(String name, Context context) {
+ return client.deleteSecret(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.
+ * DeletedSecret deletedSecret = secretClient.getDeletedSecret("secretName").value();
+ * System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecret.recoveryId());
+ *
+ *
+ * @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 client.getDeletedSecret(name, Context.NONE).block().value();
}
/**
@@ -210,12 +344,13 @@ public Response deleteSecret(String name) {
*
*
* @param name The name of the deleted secret.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
* @throws HttpRequestException when a secret with {@code name} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
- public Response getDeletedSecret(String name) {
- return client.getDeletedSecret(name).block();
+ public Response getDeletedSecretWithResponse(String name, Context context) {
+ return client.getDeletedSecret(name, context).block();
}
/**
@@ -236,7 +371,29 @@ public Response getDeletedSecret(String name) {
* @return A {@link VoidResponse}.
*/
public VoidResponse purgeDeletedSecret(String name) {
- return client.purgeDeletedSecret(name).block();
+ return client.purgeDeletedSecret(name, Context.NONE).block();
+ }
+
+ /**
+ * 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.
+ * VoidResponse purgeResponse = secretClient.purgeDeletedSecret("deletedSecretName");
+ * System.out.printf("Purge Status Code: %d", purgeResponse.statusCode());
+ *
+ *
+ * @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();
}
/**
@@ -255,10 +412,33 @@ public VoidResponse purgeDeletedSecret(String name) {
* @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 client.recoverDeletedSecret(name, Context.NONE).block().value();
+ }
+
+ /**
+ * 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.
+ * Secret recoveredSecret = secretClient.recoverDeletedSecret("deletedSecretName").value();
+ * System.out.printf("Recovered Secret with name %s", recoveredSecret.name());
+ *
+ *
+ * @param name The name of the deleted secret to be recovered.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret recovered secret}.
*/
- public Response recoverDeletedSecret(String name) {
- return client.recoverDeletedSecret(name).block();
+ public Response recoverDeletedSecretWithResponse(String name, Context context) {
+ return client.recoverDeletedSecret(name, context).block();
}
/**
@@ -277,7 +457,28 @@ public Response recoverDeletedSecret(String name) {
* @throws HttpRequestException when a secret with {@code name} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
*/
- public Response backupSecret(String name) {
+ public byte[] backupSecret(String name) {
+ return client.backupSecret(name, Context.NONE).block().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
+ *
+ * byte[] secretBackup = secretClient.backupSecret("secretName").value();
+ * System.out.printf("Secret's Backup Byte array's length %s", secretBackup.length);
+ *
+ *
+ * @param name The name of the secret.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ * @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
+ */
+ public Response backupSecretWithResponse(String name, Context context) {
return client.backupSecret(name).block();
}
@@ -298,8 +499,30 @@ public Response backupSecret(String name) {
* @throws ResourceModifiedException when {@code backup} blob is malformed.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}.
*/
- public Response restoreSecret(byte[] backup) {
- return client.restoreSecret(backup).block();
+ public Secret restoreSecret(byte[] backup) {
+ return client.restoreSecret(backup, Context.NONE).block().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.
+ * Secret restoredSecret = secretClient.restoreSecret(secretBackupByteArray).value();
+ * System.out.printf("Restored Secret with name %s and value %s", restoredSecret.name(), restoredSecret.value());
+ *
+ *
+ * @param backup The backup blob associated with the secret.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceModifiedException when {@code backup} blob is malformed.
+ * @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}.
+ */
+ public Response restoreSecretWithResponse(byte[] backup, Context context) {
+ return client.restoreSecret(backup, context).block();
}
/**
@@ -315,13 +538,51 @@ public Response restoreSecret(byte[] backup) {
* System.out.printf("Received secret with name %s and value %s", secretWithValue.name(), secretWithValue.value());
* }
*
- *
* @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value.
*/
public Iterable listSecrets() {
return client.listSecrets().toIterable();
}
+ /**
+ * 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.
+ *
+ * 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());
+ * }
+ *
+ * @param context Additional context that is passed through the Http pipeline during the service call.*
+ * @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value.
+ */
+ public Iterable listSecrets(Context context) {
+ return client.listSecrets(context).toIterable();
+ }
+
+ /**
+ * 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.
+ *
+ * for (DeletedSecret deletedSecret : secretClient.listDeletedSecrets()) {
+ * System.out.printf("Deleted secret's recovery Id %s", deletedSecret.recoveryId());
+ * }
+ *
+ *
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @return A {@link List} containing all of the {@link DeletedSecret deleted secrets} in the vault.
+ */
+ public Iterable listDeletedSecrets(Context context) {
+ return client.listDeletedSecrets(context).toIterable();
+ }
+
/**
* Lists {@link DeletedSecret deleted secrets} of the key vault. The get deleted secrets operation returns the secrets that
* have been deleted for a vault enabled for soft-delete. This operation requires the {@code secrets/list} permission.
@@ -362,4 +623,28 @@ public Iterable listDeletedSecrets() {
public Iterable listSecretVersions(String name) {
return client.listSecretVersions(name).toIterable();
}
+
+ /**
+ * 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.
+ *
+ * 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());
+ * }
+ *
+ *
+ * @param name The name of the secret.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ * @return A {@link List} containing {@link SecretBase} of all the versions of the specified secret in the vault. List is empty if secret with {@code name} does not exist in key vault
+ */
+ public Iterable listSecretVersions(String name, Context context) {
+ return client.listSecretVersions(name, context).toIterable();
+ }
}
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClientBuilder.java
index 2cbd05b7b2607..f70b417b9512e 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;
@@ -122,9 +123,11 @@ public SecretAsyncClient buildAsyncClient() {
// Closest to API goes first, closest to wire goes last.
final List policies = new ArrayList<>();
policies.add(new UserAgentPolicy(AzureKeyVaultConfiguration.SDK_NAME, AzureKeyVaultConfiguration.SDK_VERSION, buildConfiguration));
+ HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy);
policies.add(new BearerTokenAuthenticationPolicy(credential, SecretAsyncClient.KEY_VAULT_SCOPE));
policies.addAll(this.policies);
+ HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogDetailLevel));
HttpPipeline pipeline = new HttpPipelineBuilder()
From 30ac19cb15c4a9ebc3b4c268ec607a5b16aa38d6 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Mon, 22 Jul 2019 15:24:40 -0700
Subject: [PATCH 02/15] till getSecret
---
.../keyvault/secrets/SecretAsyncClient.java | 80 +++++++++++++++++--
1 file changed, 73 insertions(+), 7 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 3ecac3ae5ce80..7748fbeaf311a 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -86,14 +86,13 @@ public final class SecretAsyncClient {
*
*
* @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 NullPointerException if {@code secret} is {@code null}.
* @throws ResourceModifiedException if {@code secret} is malformed.
* @throws HttpRequestException if {@link Secret#name() name} or {@link Secret#value() value} is empty string.
* @return A {@link Mono} containing the {@link Secret created secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono setSecret(Secret secret, Context context) {
+ public Mono setSecret(Secret secret) {
return withContext(context -> setSecret(secret, context))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -125,7 +124,7 @@ public Mono setSecret(Secret secret, Context context) {
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> setSecret(Secret secret) {
+ public Mono> setSecretWithResponse(Secret secret) {
return withContext(context -> setSecret(secret, context));
}
@@ -203,13 +202,45 @@ Mono> setSecret(String name, String value, Context context) {
* @throws HttpRequestException if {@code name} name} or {@code version} is empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> getSecret(String name, String version) {
+ public Mono getSecret(String name, String version) {
+ return withContext(context -> getSecret(name, version, context))
+ .flatMap(secretResponse -> Mono.justOrEmpty(secretResponse.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.
+ *
+ * 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()));
+ *
+ *
+ * @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> getSecretWithResponse(String name, String version) {
return withContext(context -> getSecret(name, version, context));
}
Mono> getSecret(String name, String version, Context context) {
if (version == null) {
- return getSecret(name);
+ return getSecretWithResponse(name, "");
}
return service.getSecret(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
@@ -244,7 +275,7 @@ Mono> getSecret(String name, String version, Context context) {
* version} is empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> getSecret(SecretBase secretBase) {
+ public Mono getSecret(SecretBase secretBase) {
Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
if (secretBase.version() == null) {
return getSecret(secretBase.name());
@@ -252,6 +283,40 @@ public Mono> getSecret(SecretBase secretBase) {
return getSecret(secretBase.name(), secretBase.version());
}
+ /**
+ * Get the secret which represents {@link SecretBase secretBase} from the key vault. The get
+ * operation is applicable to any secret stored in Azure Key Vault. This operation requires the
+ * {@code secrets/get} permission.
+ *
+ * The list operations {@link SecretAsyncClient#listSecrets()} and {@link
+ * SecretAsyncClient#listSecretVersions(String)} return
+ * the {@link Flux} containing {@link SecretBase base secret} as output. This operation can then be used to get
+ * the full secret with its value from {@code secretBase}.
+ * Code Samples
+ *
+ * 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())));
+ *
+ *
+ * @param secretBase The {@link SecretBase base secret} secret base holding attributes of the
+ * secret being requested.
+ * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link
+ * Secret secret}.
+ * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link
+ * SecretBase#version() version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version()
+ * version} is empty string.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono> getSecretWithResponse(SecretBase secretBase) {
+ Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
+ if (secretBase.version() == null) {
+ return getSecretWithResponse(secretBase.name(), "");
+ }
+ return getSecretWithResponse(secretBase.name(), secretBase.version());
+ }
+
Mono> getSecret(SecretBase secretBase, Context context) {
Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
if (secretBase.version() == null) {
@@ -259,6 +324,7 @@ Mono> getSecret(SecretBase secretBase, Context context) {
}
return getSecret(secretBase.name(), secretBase.version(), context);
}
+
/**
* Get the latest version of the specified secret from the key vault. The get operation is applicable to any secret stored in Azure Key Vault.
* This operation requires the {@code secrets/get} permission.
@@ -278,7 +344,7 @@ Mono> getSecret(SecretBase secretBase, Context context) {
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> getSecret(String name) {
+ public Mono getSecret(String name) {
return getSecret(name, "");
}
From 4c480349cfe7d785006f8b78ed26b4cd3d3267d0 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Tue, 23 Jul 2019 10:50:42 -0700
Subject: [PATCH 03/15] updated with Response, passing tests
---
.../keyvault/secrets/SecretAsyncClient.java | 170 +++++++++++++++++-
.../keyvault/secrets/SecretClient.java | 2 +-
.../secrets/BackupAndRestoreOperations.java | 4 +-
.../BackupAndRestoreOperationsAsync.java | 8 +-
.../security/keyvault/secrets/HelloWorld.java | 4 +-
.../keyvault/secrets/HelloWorldAsync.java | 10 +-
.../keyvault/secrets/ListOperations.java | 4 +-
.../keyvault/secrets/ListOperationsAsync.java | 10 +-
.../secrets/ManagingDeletedSecretsAsync.java | 12 +-
.../SecretClientJavaDocCodeSnippets.java | 2 +-
.../secrets/SecretAsyncClientTest.java | 117 +++++-------
.../keyvault/secrets/SecretClientTest.java | 55 +++---
12 files changed, 261 insertions(+), 137 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 7748fbeaf311a..afea84cac5fa0 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -204,7 +204,7 @@ Mono> setSecret(String name, String value, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name, String version) {
return withContext(context -> getSecret(name, version, context))
- .flatMap(secretResponse -> Mono.justOrEmpty(secretResponse.value()));
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
}
/**
@@ -352,6 +352,37 @@ Mono> getSecret(String name, Context context) {
return getSecret(name, "", context);
}
+ /**
+ * Updates the attributes associated with the specified secret, but not the value of the specified secret in the key vault. The update
+ * operation changes specified attributes of an existing stored secret and attributes that are not specified in the request are left unchanged.
+ * The value of a secret itself cannot be changed. This operation requires the {@code secrets/set} permission.
+ *
+ * Code Samples
+ * Gets latest version of the secret, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
+ * returned secret details when a response is received.
+ *
+ * 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()));
+ * });
+ *
+ * The {@code secret} is required and its fields {@link SecretBase#name() name} and {@link SecretBase#version() version} cannot be null.
+ *
+ * @param secret The {@link SecretBase base secret} object with updated properties.
+ * @throws NullPointerException if {@code secret} is {@code null}.
+ * @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link SecretBase#version() version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version() version} is empty string.
+ * @return A {@link Mono} containing the {@link SecretBase updated secret}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono updateSecret(SecretBase secret) {
+ return withContext(context -> updateSecret(secret, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
+ }
+
/**
* 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.
@@ -378,7 +409,7 @@ Mono> getSecret(String name, Context context) {
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link SecretBase updated secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> updateSecret(SecretBase secret) {
+ public Mono> updateSecretWithResponse(SecretBase secret) {
return withContext(context -> updateSecret(secret, context));
}
@@ -395,6 +426,30 @@ Mono> updateSecret(SecretBase secret, Context context) {
.doOnError(error -> logger.warning("Failed to update secret - {}", secret.name(), error));
}
+ /**
+ * Deletes a secret from the key vault. If soft-delete is enabled on the key vault then the secret is placed in the deleted state
+ * and requires to be purged for permanent deletion else the secret is permanently deleted. The delete operation applies to any secret stored in Azure Key Vault but
+ * it cannot be applied to an individual version of a secret. This operation requires the {@code secrets/delete} permission.
+ *
+ * Code Samples
+ * Deletes the secret in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
+ * deleted secret details when a response is received.
+ *
+ * secretAsyncClient.deleteSecret("secretName").subscribe(deletedSecretResponse ->
+ * System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
+ *
+ *
+ * @param name The name of the secret to be deleted.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link DeletedSecret deleted secret}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono deleteSecret(String name) {
+ return withContext(context -> deleteSecret(name, context))
+ .flatMap(response -> Mono.justOrEmpty(response.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
@@ -414,7 +469,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> deleteSecret(String name) {
+ public Mono> deleteSecretWithResponse(String name) {
return withContext(context -> deleteSecret(name, context));
}
@@ -425,6 +480,32 @@ Mono> deleteSecret(String name, Context context) {
.doOnError(error -> logger.warning("Failed to delete secret - {}", name, error));
}
+ /**
+ * The get deleted secret operation returns the secrets that have been deleted for a vault enabled
+ * for soft-delete. This operation requires the {@code secrets/list} permission.
+ *
+ * Code Samples
+ * Gets the deleted secret from the key vault enabled for soft-delete. Subscribes to the call
+ * asynchronously and prints out the
+ * deleted secret details when a response is received.
+ *
+ * //Assuming secret is deleted on a soft-delete enabled vault.
+ * secretAsyncClient.getDeletedSecret("secretName").subscribe(deletedSecretResponse ->
+ * System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
+ *
+ *
+ * @param name The name of the deleted secret.
+ * @return A {@link Mono} containing the {@link DeletedSecret deleted secret}.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key
+ * vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono getDeletedSecret(String name) {
+ return withContext(context -> getDeletedSecret(name, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
+ }
+
/**
* 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.
@@ -447,7 +528,7 @@ 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) {
+ public Mono> getDeletedSecretWithResponse(String name) {
return withContext(context -> getDeletedSecret(name, context));
}
@@ -491,6 +572,30 @@ Mono purgeDeletedSecret(String name, Context context) {
.doOnError(error -> logger.warning("Failed to purge deleted secret - {}", name, error));
}
+ /**
+ * 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.
+ * secretAsyncClient.recoverDeletedSecret("deletedSecretName").subscribe(recoveredSecretResponse ->
+ * System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.value().name()));
+ *
+ *
+ * @param name The name of the deleted secret to be recovered.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ * @return A {@link Mono} containing the {@link Secret recovered secret}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono recoverDeletedSecret(String name) {
+ return withContext(context -> recoverDeletedSecret(name, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
+ }
+
/**
* 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.
@@ -510,7 +615,7 @@ Mono purgeDeletedSecret(String name, Context context) {
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link Secret recovered secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> recoverDeletedSecret(String name) {
+ public Mono> recoverDeletedSecretWithResponse(String name) {
return withContext(context -> recoverDeletedSecret(name, context));
}
@@ -521,6 +626,31 @@ Mono> recoverDeletedSecret(String name, Context context) {
.doOnError(error -> logger.warning("Failed to recover deleted secret - {}", name, error));
}
+ /**
+ * 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.
+ *
+ * secretAsyncClient.backupSecret("secretName").subscribe(secretBackupResponse ->
+ * System.out.printf("Secret's Backup Byte array's length %s \n", secretBackupResponse.value().length));
+ *
+ *
+ * @param name The name of the secret.
+ * @return A {@link Mono} containing the backed up secret blob.
+ * @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key
+ * vault.
+ * @throws HttpRequestException when a secret with {@code name} is empty string.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono backupSecret(String name) {
+ return withContext(context -> backupSecret(name, context))
+ .flatMap(response -> Mono.justOrEmpty(response.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.
@@ -542,7 +672,7 @@ 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) {
+ public Mono> backupSecretWithResponse(String name) {
return withContext(context -> backupSecret(name, context));
}
@@ -555,6 +685,30 @@ Mono> backupSecret(String name, Context context) {
base64URLResponse.statusCode(), base64URLResponse.headers(), base64URLResponse.value().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. 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.
+ * secretAsyncClient.restoreSecret(secretBackupByteArray).subscribe(secretResponse ->
+ * System.out.printf("Restored Secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
+ *
+ *
+ * @param backup The backup blob associated with the secret.
+ * @return A {@link Mono} containing the {@link Secret restored secret}.
+ * @throws ResourceModifiedException when {@code backup} blob is malformed.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono restoreSecret(byte[] backup) {
+ return withContext(context -> restoreSecret(backup, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
+ }
+
/**
* Restores a backed up secret, and all its versions, to a vault. This operation requires the
* {@code secrets/restore} permission.
@@ -575,7 +729,7 @@ Mono> backupSecret(String name, Context context) {
* @throws ResourceModifiedException when {@code backup} blob is malformed.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> restoreSecret(byte[] backup) {
+ public Mono> restoreSecretWithResponse(byte[] backup) {
return withContext(context -> restoreSecret(backup, context));
}
@@ -729,7 +883,7 @@ PagedFlux listSecretVersions(String name, Context context) {
* {@link SecretAsyncClient#listSecretVersions()}.
*
* @param continuationToken The {@link PagedResponse#nextLink()} from a previous, successful call to one of the list operations.
- *
+ *
* @return A {@link Mono} of {@link PagedResponse} from the next page of results.
*/
private Mono> listSecretVersionsNextPage(String continuationToken, Context context) {
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretClient.java
index 88e2ec0cd9a27..1f545781d08d0 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
@@ -479,7 +479,7 @@ public byte[] backupSecret(String name) {
* @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
*/
public Response backupSecretWithResponse(String name, Context context) {
- return client.backupSecret(name).block();
+ return client.backupSecret(name, context).block();
}
/**
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..7f1738b791538 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);
@@ -65,7 +65,7 @@ public static void main(String[] args) throws InterruptedException {
// 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/SecretClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretClientJavaDocCodeSnippets.java
index 7b92e5986b42e..74dc452913c27 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
@@ -44,7 +44,7 @@ public void getSecret() {
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());
}
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;
}
}
From 6785cc515a5d1f3799982c2c1d7b8d502be94418 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Tue, 23 Jul 2019 14:40:31 -0700
Subject: [PATCH 04/15] add code snippets
---
.../keyvault/secrets/SecretAsyncClient.java | 143 ++-----
.../keyvault/secrets/SecretClient.java | 156 ++-----
.../keyvault/secrets/SecretClientBuilder.java | 6 +-
.../SecretAsyncClientJavaDocCodeSnippets.java | 402 ++++++++++++++++++
.../SecretClientJavaDocCodeSnippets.java | 344 ++++++++++++---
5 files changed, 757 insertions(+), 294 deletions(-)
create mode 100644 sdk/keyvault/azure-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/SecretAsyncClientJavaDocCodeSnippets.java
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index afea84cac5fa0..a08d51cb1a66c 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -36,7 +36,7 @@
* also supports listing {@link DeletedSecret deleted secrets} for a soft-delete enabled Azure Key Vault.
*
* Samples to construct the async client
- * {@codesnippet com.azure.security.keyvault.secretclient.async.construct}
+ * {@codesnippet com.azure.security.keyvault.secrets.async.secretclient.construct}
*
* @see SecretClientBuilder
* @see PagedFlux
@@ -76,14 +76,7 @@ public final class SecretAsyncClient {
* Code Samples
* Creates a new secret which activates in 1 day and expires in 1 year in the Azure Key Vault. Subscribes to the call asynchronously and
* prints out the newly created secret details when a response is received.
- *
- * Secret secret = new Secret("secretName", "secretValue")
- * .notBefore(OffsetDateTime.now().plusDays(1))
- * .expires(OffsetDateTime.now().plusDays(365));
- *
- * secretAsyncClient.setSecret(secret).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#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}.
@@ -108,14 +101,7 @@ public Mono setSecret(Secret secret) {
* Code Samples
* Creates a new secret which activates in 1 day and expires in 1 year in the Azure Key Vault. Subscribes to the call asynchronously and
* prints out the newly created secret details when a response is received.
- *
- * Secret secret = new Secret("secretName", "secretValue")
- * .notBefore(OffsetDateTime.now().plusDays(1))
- * .expires(OffsetDateTime.now().plusDays(365));
- *
- * secretAsyncClient.setSecret(secret).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.setSecretWithResponse#secret}
*
* @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null.
* @throws NullPointerException if {@code secret} is {@code null}.
@@ -150,10 +136,7 @@ Mono> setSecret(Secret secret, Context context) {
* Code Samples
* Creates a new secret in the key vault. Subscribes to the call asynchronously and prints out
* the newly created secret details when a response is received.
- *
- * secretAsyncClient.setSecret("secretName", "secretValue").subscribe(secretResponse ->
- * System.out.printf("Secret is created with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.setSecret#string-string}
*
* @param name The name of the secret. It is required and cannot be null.
* @param value The value of the secret. It is required and cannot be null.
@@ -184,12 +167,7 @@ Mono> setSecret(String name, String value, Context context) {
* Gets a specific version of the secret in the key vault. Subscribes to the call
* asynchronously and prints out the
* returned secret details when a response is received.
- *
- * String secretVersion = "6A385B124DEF4096AF1361A85B16C204";
- * secretAsyncClient.getSecret("secretName", secretVersion).subscribe(secretResponse ->
- * System.out.printf("Secret with name %s, value %s and version %s", secretResponse.value().name(),
- * secretResponse.value().value(), secretResponse.value().version()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#string-string}
*
* @param name The name of the secret, cannot be null
* @param version The version of the secret to retrieve. If this is an empty String or null, this
@@ -216,12 +194,7 @@ public Mono getSecret(String name, String version) {
* Gets a specific version of the secret in the key vault. Subscribes to the call
* asynchronously and prints out the
* returned secret details when a response is received.
- *
- * String secretVersion = "6A385B124DEF4096AF1361A85B16C204";
- * secretAsyncClient.getSecret("secretName", secretVersion).subscribe(secretResponse ->
- * System.out.printf("Secret with name %s, value %s and version %s", secretResponse.value().name(),
- * secretResponse.value().value(), secretResponse.value().version()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecretWithResponse#string-string}
*
* @param name The name of the secret, cannot be null
* @param version The version of the secret to retrieve. If this is an empty String or null, this
@@ -259,11 +232,7 @@ Mono> getSecret(String name, String version, Context context) {
* the {@link Flux} containing {@link SecretBase base secret} as output. This operation can then be used to get
* the full secret with its value from {@code secretBase}.
* Code Samples
- *
- * secretAsyncClient.listSecrets().subscribe(secretBase ->
- * client.getSecret(secretBase).subscribe(secretResponse ->
- * System.out.printf("Secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#secretBase}
*
* @param secretBase The {@link SecretBase base secret} secret base holding attributes of the
* secret being requested.
@@ -293,11 +262,7 @@ public Mono getSecret(SecretBase secretBase) {
* the {@link Flux} containing {@link SecretBase base secret} as output. This operation can then be used to get
* the full secret with its value from {@code secretBase}.
* Code Samples
- *
- * secretAsyncClient.listSecrets().subscribe(secretBase ->
- * client.getSecret(secretBase).subscribe(secretResponse ->
- * System.out.printf("Secret with name %s and value %s \n", secretResponse.value().name(), secretResponse.value().value())));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecretWithResponse#secretBase}
*
* @param secretBase The {@link SecretBase base secret} secret base holding attributes of the
* secret being requested.
@@ -332,11 +297,7 @@ Mono> getSecret(SecretBase secretBase, Context context) {
* Code Samples
* Gets latest version of the secret in the key vault. Subscribes to the call asynchronously and prints out the
* returned secret details when a response is received.
- *
- * secretAsyncClient.getSecret("secretName").subscribe(secretResponse ->
- * System.out.printf("Secret with name %s , value %s \n", secretResponse.value().name(),
- * secretResponse.value().value()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getSecret#string}
*
* @param name The name of the secret.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
@@ -360,15 +321,8 @@ Mono> getSecret(String name, Context context) {
* Code Samples
* Gets latest version of the secret, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* returned secret details when a response is received.
- *
- * secretAsyncClient.getSecret("secretName").subscribe(secretResponse -> {
- * Secret secret = secretResponse.value();
- * //Update the not before time of the secret.
- * secret.notBefore(OffsetDateTime.now().plusDays(50));
- * secretAsyncClient.updateSecret(secret).subscribe(secretResponse ->
- * System.out.printf("Secret's updated not before time %s \n", secretResponse.value().notBefore().toString()));
- * });
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.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.
@@ -391,15 +345,8 @@ public Mono updateSecret(SecretBase secret) {
* Code Samples
* Gets latest version of the secret, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* returned secret details when a response is received.
- *
- * secretAsyncClient.getSecret("secretName").subscribe(secretResponse -> {
- * Secret secret = secretResponse.value();
- * //Update the not before time of the secret.
- * secret.notBefore(OffsetDateTime.now().plusDays(50));
- * secretAsyncClient.updateSecret(secret).subscribe(secretResponse ->
- * System.out.printf("Secret's updated not before time %s \n", secretResponse.value().notBefore().toString()));
- * });
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.updateSecretWithResponse#secretBase}
+ *
* The {@code secret} is required and its fields {@link SecretBase#name() name} and {@link SecretBase#version() version} cannot be null.
*
* @param secret The {@link SecretBase base secret} object with updated properties.
@@ -434,10 +381,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
* Code Samples
* Deletes the secret in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* deleted secret details when a response is received.
- *
- * secretAsyncClient.deleteSecret("secretName").subscribe(deletedSecretResponse ->
- * System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.deleteSecret#string}
*
* @param name The name of the secret to be deleted.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
@@ -458,10 +402,7 @@ public Mono deleteSecret(String name) {
* Code Samples
* Deletes the secret in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
* deleted secret details when a response is received.
- *
- * secretAsyncClient.deleteSecret("secretName").subscribe(deletedSecretResponse ->
- * System.out.printf("Deleted Secret's Recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.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.
@@ -490,9 +431,7 @@ Mono> deleteSecret(String name, Context context) {
* deleted secret details when a response is received.
*
* //Assuming secret is deleted on a soft-delete enabled vault.
- * secretAsyncClient.getDeletedSecret("secretName").subscribe(deletedSecretResponse ->
- * System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getDeletedSecret#string}
*
* @param name The name of the deleted secret.
* @return A {@link Mono} containing the {@link DeletedSecret deleted secret}.
@@ -516,9 +455,7 @@ public Mono getDeletedSecret(String name) {
* deleted secret details when a response is received.
*
* //Assuming secret is deleted on a soft-delete enabled vault.
- * secretAsyncClient.getDeletedSecret("secretName").subscribe(deletedSecretResponse ->
- * System.out.printf("Deleted Secret with recovery Id %s \n", deletedSecretResponse.value().recoveryId()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.getDeletedSecretWithResponse#string}
*
* @param name The name of the deleted secret.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
@@ -550,9 +487,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}.
@@ -581,9 +516,7 @@ Mono purgeDeletedSecret(String name, Context context) {
* recovered secret details when a response is received.
*
* //Assuming secret is deleted on a soft-delete enabled vault.
- * secretAsyncClient.recoverDeletedSecret("deletedSecretName").subscribe(recoveredSecretResponse ->
- * System.out.printf("Recovered Secret with name %s \n", recoveredSecretResponse.value().name()));
- *
+ * {@codesnippet com.azure.keyvault.secrets.secretclient.recoverDeletedSecret#string}
*
* @param name The name of the deleted secret to be recovered.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
@@ -605,9 +538,7 @@ public Mono recoverDeletedSecret(String name) {
* 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.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.
@@ -635,9 +566,7 @@ 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.
@@ -659,10 +588,7 @@ public Mono backupSecret(String name) {
* 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.
- *
- * 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.backupSecretWithResponse#string}
*
* @param name The name of the secret.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
@@ -695,9 +621,7 @@ 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}.
@@ -719,9 +643,7 @@ public Mono restoreSecret(byte[] backup) {
* 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.restoreSecretWithResponse#byte}
*
* @param backup The backup blob associated with the secret.
* @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
@@ -749,11 +671,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.
*/
@@ -801,10 +719,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.
*/
@@ -854,11 +769,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.
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 1f545781d08d0..2894982afc1a8 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
@@ -49,15 +49,7 @@ 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#secretBase}
*
* @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}.
@@ -75,10 +67,7 @@ public Secret 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.
@@ -96,10 +85,7 @@ public Secret setSecret(String name, String value) {
*
* 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-Context}
*
* @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.
@@ -118,11 +104,7 @@ public Response setSecretWithResponse(String name, String value, Context
*
* 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.
@@ -141,7 +123,8 @@ public Secret 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}.
- * {@codesnippet com.azure.security.keyvault.secretclient.getSecret#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.
@@ -160,6 +143,7 @@ public Response getSecretWithResponse(SecretBase secretBase, Context con
* 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.
@@ -177,10 +161,7 @@ public Secret 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.
@@ -197,10 +178,7 @@ public Secret getSecret(String name) {
*
* 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.getSecretWithResponse#string-Context}
*
* @param name The name of the secret.
* @param context Additional context that is passed through the Http pipeline during the service call.
@@ -221,12 +199,7 @@ public Response getSecretWithResponse(String name, Context context) {
*
* 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.
@@ -248,12 +221,7 @@ public Response updateSecretWithResponse(SecretBase secret, Context
*
* 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.updateSecret#secretBase}
*
* @param secret The {@link SecretBase base secret} object with updated properties.
* @throws NullPointerException if {@code secret} is {@code null}.
@@ -272,10 +240,7 @@ public SecretBase updateSecret(SecretBase secret) {
*
* Code Samples
* Deletes the secret from the keyvault. Prints out the recovery id of the deleted secret returned in the response.
- *
- * DeletedSecret deletedSecret = secretClient.deleteSecret("secretName").value();
- * System.out.printf("Deleted Secret's Recovery Id %s", deletedSecret.recoveryId()));
- *
+ * {@codesnippet com.azure.security.keyvault.secretclient.deleteSecret#string}
*
* @param name The name of the secret to be deleted.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
@@ -293,10 +258,7 @@ public DeletedSecret deleteSecret(String name) {
*
* 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.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.
@@ -315,11 +277,8 @@ public Response deleteSecretWithResponse(String name, Context con
* 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.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.
@@ -337,11 +296,8 @@ public DeletedSecret getDeletedSecret(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.
@@ -359,11 +315,8 @@ public Response getDeletedSecretWithResponse(String name, Context
*
* 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.
@@ -380,11 +333,8 @@ public VoidResponse purgeDeletedSecret(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-Context}
*
* @param name The name of the secret.
* @param context Additional context that is passed through the Http pipeline during the service call.
@@ -403,11 +353,8 @@ public VoidResponse purgeDeletedSecret(String name, Context context) {
* 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.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.
@@ -425,11 +372,8 @@ public Secret recoverDeletedSecret(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.
@@ -447,10 +391,7 @@ public Response recoverDeletedSecretWithResponse(String name, Context co
*
* 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.
@@ -467,10 +408,7 @@ public byte[] backupSecret(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.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.
@@ -489,11 +427,8 @@ public Response backupSecretWithResponse(String name, Context context) {
* 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.
@@ -510,11 +445,8 @@ public Secret restoreSecret(byte[] backup) {
* 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.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.
@@ -532,12 +464,8 @@ public Response restoreSecretWithResponse(byte[] backup, Context context
*
* It is possible to get full secrets with values from this information. Loop over the {@link SecretBase secret} and
* call {@link SecretClient#getSecret(SecretBase baseSecret)} . This will return the {@link Secret secret} with value included of its latest version.
- *
- * for (SecretBase secret : secretClient.listSecrets()) {
- * Secret secretWithValue = secretClient.getSecret(secret).value();
- * System.out.printf("Received secret with name %s and value %s", secretWithValue.name(), secretWithValue.value());
- * }
- *
+ * {@codesnippet com.azure.security.keyvault.secretclient.listSecrets}
+ *
* @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value.
*/
public Iterable listSecrets() {
@@ -551,12 +479,8 @@ public Iterable listSecrets() {
*
* 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#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.
*/
@@ -570,11 +494,7 @@ public Iterable listSecrets(Context context) {
*
* 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.
@@ -589,11 +509,7 @@ public Iterable listDeletedSecrets(Context context) {
*
* 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}
*
* @return A {@link List} containing all of the {@link DeletedSecret deleted secrets} in the vault.
*/
@@ -608,12 +524,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.
@@ -631,12 +542,7 @@ public Iterable listSecretVersions(String name) {
*
* 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-Context}
*
* @param name The name of the secret.
* @param context Additional context that is passed through the Http pipeline during the service call.
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 f70b417b9512e..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
@@ -33,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}
@@ -41,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
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..b61bea72ad50e
--- /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.value().name(), secretResponse.value().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 74dc452913c27..c01aaec75542c 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
@@ -7,40 +7,29 @@
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()) {
@@ -49,29 +38,301 @@ public void getSecret() {
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, 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-Context
+ Secret secretWithVersion = secretClient.getSecretWithResponse("secretName",
+ 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-Context
+ }
+
+ /**
+ * Method to insert code snippets for {@link SecretClient#setSecret(Secret)}
+ */
+ public void setSecretCodeSnippets() {
+ SecretClient secretClient = getSecretClient();
+ // BEGIN: com.azure.security.keyvault.secretclient.setSecret#secretBase
+ 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#secretBase
+
+ // 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(String, String, Context)}
+ */
+ public void setSecretWithResponseCodeSnippets() {
+ SecretClient secretClient = getSecretClient();
+ // BEGIN: com.azure.security.keyvault.secretclient.setSecret#string-string-Context
+ Secret secret = secretClient.setSecretWithResponse("secretName", "secretValue",
+ 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.setSecret#string-string-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 +344,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}
From fc1f242b433078588ad79cb0e6fa5db7900284f4 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Wed, 24 Jul 2019 16:13:46 -0700
Subject: [PATCH 05/15] adding withResponse
---
.../resources/spotbugs/spotbugs-exclude.xml | 10 ++++++
.../keyvault/secrets/SecretAsyncClient.java | 35 ++++++++++---------
.../keyvault/secrets/HelloWorldAsync.java | 2 +-
.../SecretAsyncClientJavaDocCodeSnippets.java | 2 +-
4 files changed, 30 insertions(+), 19 deletions(-)
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..8604d7a0f679e 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
@@ -455,6 +455,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index a08d51cb1a66c..25a7775cec376 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -86,7 +86,7 @@ public final class SecretAsyncClient {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono setSecret(Secret secret) {
- return withContext(context -> setSecret(secret, context))
+ return withContext(context -> setSecretWithResponse(secret))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -140,14 +140,14 @@ Mono> setSecret(Secret secret, Context context) {
*
* @param name The name of the secret. It is required and cannot be null.
* @param value The value of the secret. It is required and cannot be null.
- * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value}
- * contains the {@link Secret created secret}.
+ * @return A {@link Mono} containing the {@link Secret created secret}.
* @throws ResourceModifiedException if invalid {@code name} or {@code value} are specified.
* @throws HttpRequestException if {@code name} or {@code value} is empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> setSecret(String name, String value) {
- return withContext(context -> setSecret(name, value, context));
+ public Mono setSecret(String name, String value) {
+ return withContext(context -> setSecret(name, value, context))
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
}
Mono> setSecret(String name, String value, Context context) {
@@ -181,7 +181,7 @@ Mono> setSecret(String name, String value, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name, String version) {
- return withContext(context -> getSecret(name, version, context))
+ return withContext(context -> getSecretWithResponse(name, version))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -236,8 +236,7 @@ Mono> getSecret(String name, String version, Context context) {
*
* @param secretBase The {@link SecretBase base secret} secret base holding attributes of the
* secret being requested.
- * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link
- * Secret secret}.
+ * @return A {@link Mono} containing the requested {@link Secret secret}.
* @throws ResourceNotFoundException when a secret with {@link SecretBase#name() name} and {@link
* SecretBase#version() version} doesn't exist in the key vault.
* @throws HttpRequestException if {@link SecretBase#name()} name} or {@link SecretBase#version()
@@ -249,7 +248,8 @@ public Mono getSecret(SecretBase secretBase) {
if (secretBase.version() == null) {
return getSecret(secretBase.name());
}
- return getSecret(secretBase.name(), secretBase.version());
+ return getSecretWithResponse(secretBase.name(), secretBase.version())
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
}
/**
@@ -302,11 +302,12 @@ Mono> getSecret(SecretBase secretBase, Context context) {
* @param name The name of the secret.
* @throws ResourceNotFoundException when a secret with {@code name} doesn't exist in the key vault.
* @throws HttpRequestException if {@code name} is empty string.
- * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
+ * @return A {@link Mono} containing the requested {@link Secret secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name) {
- return getSecret(name, "");
+ return getSecretWithResponse(name, "")
+ .flatMap(response -> Mono.justOrEmpty(response.value()));
}
Mono> getSecret(String name, Context context) {
@@ -333,7 +334,7 @@ Mono> getSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateSecret(SecretBase secret) {
- return withContext(context -> updateSecret(secret, context))
+ return withContext(context -> updateSecretWithResponse(secret))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -390,7 +391,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono deleteSecret(String name) {
- return withContext(context -> deleteSecret(name, context))
+ return withContext(context -> deleteSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -441,7 +442,7 @@ Mono> deleteSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getDeletedSecret(String name) {
- return withContext(context -> getDeletedSecret(name, context))
+ return withContext(context -> getDeletedSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -525,7 +526,7 @@ Mono purgeDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recoverDeletedSecret(String name) {
- return withContext(context -> recoverDeletedSecret(name, context))
+ return withContext(context -> recoverDeletedSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -576,7 +577,7 @@ Mono> recoverDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono backupSecret(String name) {
- return withContext(context -> backupSecret(name, context))
+ return withContext(context -> backupSecretWithResponse(name))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
@@ -629,7 +630,7 @@ Mono> backupSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono restoreSecret(byte[] backup) {
- return withContext(context -> restoreSecret(backup, context))
+ return withContext(context -> restoreSecretWithResponse(backup))
.flatMap(response -> Mono.justOrEmpty(response.value()));
}
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 7f1738b791538..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
@@ -59,7 +59,7 @@ 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);
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
index b61bea72ad50e..38c3d791c8ed5 100644
--- 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
@@ -154,7 +154,7 @@ public void setSecretCodeSnippets() {
.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()));
+ secretResponse.name(), secretResponse.value()));
// END: com.azure.keyvault.secrets.secretclient.setSecret#string-string
}
From 7d8f835f99cdc564a17c0c6dc994e34ecf77e31c Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Fri, 26 Jul 2019 10:11:47 -0700
Subject: [PATCH 06/15] adding withResponse in sync client
---
.../security/keyvault/secrets/SecretClient.java | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
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 2894982afc1a8..20a8fb1d71c3f 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
@@ -76,7 +76,7 @@ public Secret setSecret(Secret secret) {
* @return The {@link Secret created secret}.
*/
public Secret setSecret(String name, String value) {
- return client.setSecret(name, value, Context.NONE).block().value();
+ return this.setSecretWithResponse(name, value, Context.NONE).value();
}
/**
@@ -152,7 +152,7 @@ public Response getSecretWithResponse(SecretBase secretBase, Context con
* @return The requested {@link Secret secret}.
*/
public Secret getSecret(SecretBase secretBase) {
- return client.getSecret(secretBase, Context.NONE).block().value();
+ return this.getSecretWithResponse(secretBase, Context.NONE).value();
}
/**
@@ -230,7 +230,7 @@ public Response updateSecretWithResponse(SecretBase secret, Context
* @return The {@link SecretBase updated secret}.
*/
public SecretBase updateSecret(SecretBase secret) {
- return client.updateSecret(secret, Context.NONE).block().value();
+ return this.updateSecretWithResponse(secret, Context.NONE).value();
}
/**
@@ -248,7 +248,7 @@ public SecretBase updateSecret(SecretBase secret) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
public DeletedSecret deleteSecret(String name) {
- return client.deleteSecret(name, Context.NONE).block().value();
+ return this.deleteSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -286,7 +286,7 @@ public Response deleteSecretWithResponse(String name, Context con
* @return The {@link DeletedSecret deleted secret}.
*/
public DeletedSecret getDeletedSecret(String name) {
- return client.getDeletedSecret(name, Context.NONE).block().value();
+ return this.getDeletedSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -362,7 +362,7 @@ public VoidResponse purgeDeletedSecret(String name, Context context) {
* @return The {@link Secret recovered secret}.
*/
public Secret recoverDeletedSecret(String name) {
- return client.recoverDeletedSecret(name, Context.NONE).block().value();
+ return this.recoverDeletedSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -399,7 +399,7 @@ public Response recoverDeletedSecretWithResponse(String name, Context co
* @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
*/
public byte[] backupSecret(String name) {
- return client.backupSecret(name, Context.NONE).block().value();
+ return this.backupSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -435,7 +435,7 @@ public Response backupSecretWithResponse(String name, Context context) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}.
*/
public Secret restoreSecret(byte[] backup) {
- return client.restoreSecret(backup, Context.NONE).block().value();
+ return this.restoreSecretWithResponse(backup, Context.NONE).value();
}
/**
From 02894d19c0a1b2f4f0c1b190f6534643dea9fac2 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Fri, 26 Jul 2019 15:08:02 -0700
Subject: [PATCH 07/15] addint toMono
---
.../keyvault/secrets/SecretAsyncClient.java | 23 ++++++++++---------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 25a7775cec376..e6630fdeaafa6 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -13,6 +13,7 @@
import com.azure.core.implementation.annotation.ReturnType;
import com.azure.core.implementation.annotation.ServiceClient;
import com.azure.core.implementation.annotation.ServiceMethod;
+import com.azure.core.implementation.util.FluxUtil;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.security.keyvault.secrets.models.DeletedSecret;
@@ -87,7 +88,7 @@ public final class SecretAsyncClient {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono setSecret(Secret secret) {
return withContext(context -> setSecretWithResponse(secret))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -147,7 +148,7 @@ Mono> setSecret(Secret secret, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono setSecret(String name, String value) {
return withContext(context -> setSecret(name, value, context))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
Mono> setSecret(String name, String value, Context context) {
@@ -182,7 +183,7 @@ Mono> setSecret(String name, String value, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name, String version) {
return withContext(context -> getSecretWithResponse(name, version))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -249,7 +250,7 @@ public Mono getSecret(SecretBase secretBase) {
return getSecret(secretBase.name());
}
return getSecretWithResponse(secretBase.name(), secretBase.version())
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -307,7 +308,7 @@ Mono> getSecret(SecretBase secretBase, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name) {
return getSecretWithResponse(name, "")
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
Mono> getSecret(String name, Context context) {
@@ -335,7 +336,7 @@ Mono> getSecret(String name, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateSecret(SecretBase secret) {
return withContext(context -> updateSecretWithResponse(secret))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -392,7 +393,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono deleteSecret(String name) {
return withContext(context -> deleteSecretWithResponse(name))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -443,7 +444,7 @@ Mono> deleteSecret(String name, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getDeletedSecret(String name) {
return withContext(context -> getDeletedSecretWithResponse(name))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -527,7 +528,7 @@ Mono purgeDeletedSecret(String name, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recoverDeletedSecret(String name) {
return withContext(context -> recoverDeletedSecretWithResponse(name))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -578,7 +579,7 @@ Mono> recoverDeletedSecret(String name, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono backupSecret(String name) {
return withContext(context -> backupSecretWithResponse(name))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
@@ -631,7 +632,7 @@ Mono> backupSecret(String name, Context context) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono restoreSecret(byte[] backup) {
return withContext(context -> restoreSecretWithResponse(backup))
- .flatMap(response -> Mono.justOrEmpty(response.value()));
+ .flatMap(FluxUtil::toMono);
}
/**
From 329be81e30c2a95599369061bfeba8f09b2d106f Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Fri, 26 Jul 2019 15:11:50 -0700
Subject: [PATCH 08/15] adding NPE spoptbugs
---
.../src/main/resources/spotbugs/spotbugs-exclude.xml | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
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 8604d7a0f679e..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,17 +450,7 @@
-
-
-
-
-
-
-
-
-
-
+
From 2cc5a9743afee346b02f6d36618027dd624b6319 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Mon, 29 Jul 2019 11:50:09 -0700
Subject: [PATCH 09/15] standardise naming and removing duplication
---
.../keyvault/keys/KeyAsyncClient.java | 99 ++++---------------
.../security/keyvault/keys/KeyClient.java | 27 ++++-
.../KeyAsyncClientJavaDocCodeSnippets.java | 23 ++---
.../keys/KeyClientJavaDocCodeSnippets.java | 20 ++--
.../keyvault/keys/ListOperationsAsync.java | 4 +-
.../keyvault/secrets/SecretAsyncClient.java | 45 +++------
.../keyvault/secrets/SecretClient.java | 47 +++++----
.../SecretClientJavaDocCodeSnippets.java | 26 +++--
8 files changed, 113 insertions(+), 178 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
index 49aa98f54e3fb..000f9c806c4c5 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
@@ -155,8 +155,7 @@ Mono> createKey(String name, KeyType keyType, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono createKey(KeyCreateOptions keyCreateOptions) {
- return withContext(context -> createKeyWithResponse(keyCreateOptions))
- .flatMap(FluxUtil::toMono);
+ return this.createKeyWithResponse(keyCreateOptions).flatMap(FluxUtil::toMono);
}
Mono> createKey(KeyCreateOptions keyCreateOptions, Context context) {
@@ -196,8 +195,7 @@ Mono> createKey(KeyCreateOptions keyCreateOptions, Context context
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) {
- return withContext(context -> createRsaKeyWithResponse(rsaKeyCreateOptions))
- .flatMap(FluxUtil::toMono);
+ return this.createRsaKeyWithResponse(rsaKeyCreateOptions).flatMap(FluxUtil::toMono);
}
/**
@@ -262,8 +260,7 @@ Mono> createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions, Contex
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono createEcKey(EcKeyCreateOptions ecKeyCreateOptions) {
- return withContext(context -> createEcKeyWithResponse(ecKeyCreateOptions))
- .flatMap(FluxUtil::toMono);
+ return this.createEcKeyWithResponse(ecKeyCreateOptions).flatMap(FluxUtil::toMono);
}
/**
@@ -366,8 +363,7 @@ Mono> importKey(String name, JsonWebKey keyMaterial, Context conte
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono importKey(KeyImportOptions keyImportOptions) {
- return withContext(context -> importKeyWithResponse(keyImportOptions))
- .flatMap(FluxUtil::toMono);
+ return this.importKeyWithResponse(keyImportOptions).flatMap(FluxUtil::toMono);
}
/**
@@ -430,12 +426,7 @@ Mono> importKey(KeyImportOptions keyImportOptions, Context context
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getKey(String name, String version) {
- if (version == null) {
- return getKeyWithResponse(name)
- .flatMap(FluxUtil::toMono);
- }
- return withContext(context -> getKeyWithResponse(name, version))
- .flatMap(FluxUtil::toMono);
+ return this.getKeyWithResponse(name, version).flatMap(FluxUtil::toMono);
}
/**
@@ -456,7 +447,7 @@ public Mono getKey(String name, String version) {
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> getKeyWithResponse(String name, String version) {
if (version == null) {
- return getKeyWithResponse(name);
+ return withContext(context -> getKey(name, "", context));
}
return withContext(context -> getKey(name, version, context));
}
@@ -485,28 +476,7 @@ Mono> getKey(String name, String version, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getKey(String name) {
- return getKeyWithResponse(name, "")
- .flatMap(FluxUtil::toMono);
- }
-
- /**
- * Get the public part of the latest version of the specified key from the key vault. The get key operation is applicable to
- * all key types and it requires the {@code keys/get} permission.
- *
- * Code Samples
- * Gets latest version of the key in the key vault. Subscribes to the call asynchronously and prints out the
- * returned key details when a response has been received.
- *
- * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string}
- *
- * @param name The name of the key.
- * @throws ResourceNotFoundException when a key with {@code name} doesn't exist in the key vault.
- * @throws HttpRequestException if {@code name} is empty string.
- * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}.
- */
- @ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> getKeyWithResponse(String name) {
- return getKeyWithResponse(name, "");
+ return this.getKeyWithResponse(name, "").flatMap(FluxUtil::toMono);
}
/**
@@ -526,13 +496,7 @@ public Mono> getKeyWithResponse(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getKey(KeyBase keyBase) {
- Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null.");
- if (keyBase.version() == null) {
- return getKeyWithResponse(keyBase.name())
- .flatMap(FluxUtil::toMono);
- }
- return getKeyWithResponse(keyBase.name(), keyBase.version())
- .flatMap(FluxUtil::toMono);
+ return this.getKeyWithResponse(keyBase).flatMap(FluxUtil::toMono);
}
/**
@@ -554,9 +518,9 @@ public Mono getKey(KeyBase keyBase) {
public Mono> getKeyWithResponse(KeyBase keyBase) {
Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null.");
if (keyBase.version() == null) {
- return getKeyWithResponse(keyBase.name());
+ return withContext(context -> getKey(keyBase.name(), "", context));
}
- return getKeyWithResponse(keyBase.name(), keyBase.version());
+ return withContext(context -> getKey(keyBase.name(), keyBase.version(), context));
}
/**
@@ -578,30 +542,7 @@ public Mono> getKeyWithResponse(KeyBase keyBase) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateKey(KeyBase key) {
- return withContext(context -> updateKeyWithResponse(key))
- .flatMap(FluxUtil::toMono);
- }
-
- /**
- * Updates the attributes associated with the specified key, but not the cryptographic key material of the specified key in the key vault. The update
- * operation changes specified attributes of an existing stored key and attributes that are not specified in the request are left unchanged.
- * The cryptographic key material of a key itself cannot be changed. This operation requires the {@code keys/set} permission.
- *
- * Code Samples
- * Gets latest version of the key, changes its notBefore time and then updates it in the Azure Key Vault. Subscribes to the call asynchronously and prints out the
- * returned key details when a response has been received.
- *
- * {@codesnippet com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase}
- *
- * @param key The {@link KeyBase base key} object with updated properties.
- * @throws NullPointerException if {@code key} is {@code null}.
- * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault.
- * @throws HttpRequestException if {@link KeyBase#name() name} or {@link KeyBase#version() version} is empty string.
- * @return A {@link Mono} containing a {@link Response} whose {@link Response#value() value} contains the {@link KeyBase updated key}.
- */
- @ServiceMethod(returns = ReturnType.SINGLE)
- public Mono> updateKeyWithResponse(KeyBase key) {
- return withContext(context -> updateKey(key, context));
+ return withContext(context -> this.updateKey(key, context).flatMap(FluxUtil::toMono));
}
Mono> updateKey(KeyBase key, Context context) {
@@ -658,8 +599,7 @@ public Mono> updateKeyWithResponse(KeyBase key, KeyOperation... ke
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateKey(KeyBase key, KeyOperation... keyOperations) {
- return withContext(context -> updateKeyWithResponse(key, keyOperations))
- .flatMap(FluxUtil::toMono);
+ return this.updateKeyWithResponse(key, keyOperations).flatMap(FluxUtil::toMono);
}
Mono> updateKey(KeyBase key, Context context, KeyOperation... keyOperations) {
@@ -694,8 +634,7 @@ Mono> updateKey(KeyBase key, Context context, KeyOperation... keyO
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono deleteKey(String name) {
- return withContext(context -> deleteKeyWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.deleteKeyWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -747,8 +686,7 @@ Mono> deleteKey(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getDeletedKey(String name) {
- return withContext(context -> getDeletedKeyWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.getDeletedKeyWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -826,8 +764,7 @@ Mono purgeDeletedKey(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recoverDeletedKey(String name) {
- return withContext(context -> recoverDeletedKeyWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.recoverDeletedKeyWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -882,8 +819,7 @@ Mono> recoverDeletedKey(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono backupKey(String name) {
- return withContext(context -> backupKeyWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.backupKeyWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -944,8 +880,7 @@ Mono> backupKey(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono restoreKey(byte[] backup) {
- return withContext(context -> restoreKeyWithResponse(backup))
- .flatMap(FluxUtil::toMono);
+ return this.restoreKeyWithResponse(backup).flatMap(FluxUtil::toMono);
}
/**
diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
index 517883dd328fb..5865a276c3fdc 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyClient.java
@@ -156,7 +156,7 @@ public Key createRsaKey(RsaKeyCreateOptions rsaKeyCreateOptions) {
*
* Code Samples
* Creates a new RSA key with size 2048 which activates in one day and expires in one year. Prints out the details of the created key.
- * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions}
+ * {@codesnippet com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context}
*
* @param rsaKeyCreateOptions The key options object containing information about the rsa key being created.
* @param context Additional context that is passed through the Http pipeline during the service call.
@@ -209,7 +209,7 @@ public Key createEcKey(EcKeyCreateOptions ecKeyCreateOptions) {
* Code Samples
* Creates a new EC key with P-384 web key curve. The key activates in one day and expires in one year. Prints out
* the details of the created key.
- * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions}
+ * {@codesnippet com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context}
*
* @param ecKeyCreateOptions The key options object containing information about the ec key being created.
* @param context Additional context that is passed through the Http pipeline during the service call.
@@ -368,11 +368,30 @@ public Key getKey(String name) {
* @return The requested {@link Key key}.
*/
public Key getKey(KeyBase keyBase) {
+ return this.getKeyWithResponse(keyBase, Context.NONE).value();
+ }
+
+ /**
+ * Get public part of the key which represents {@link KeyBase keyBase} from the key vault. The get key operation is applicable
+ * to all key types and it requires the {@code keys/get} permission.
+ *
+ * The list operations {@link KeyClient#listKeys()} and {@link KeyClient#listKeyVersions(String)} return
+ * the {@link List} containing {@link KeyBase base key} as output excluding the key material of the key.
+ * This operation can then be used to get the full key with its key material from {@code keyBase}.
+ * {@codesnippet com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context}
+ *
+ * @param keyBase The {@link KeyBase base key} holding attributes of the key being requested.
+ * @param context Additional context that is passed through the Http pipeline during the service call.
+ * @throws ResourceNotFoundException when a key with {@link KeyBase#name() name} and {@link KeyBase#version() version} doesn't exist in the key vault.
+ * @throws HttpRequestException if {@link KeyBase#name()} name} or {@link KeyBase#version() version} is empty string.
+ * @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Key key}.
+ */
+ public Response getKeyWithResponse(KeyBase keyBase, Context context) {
Objects.requireNonNull(keyBase, "The Key Base parameter cannot be null.");
if (keyBase.version() == null) {
- return getKey(keyBase.name());
+ return client.getKey(keyBase.name(), "", context).block();
}
- return getKeyWithResponse(keyBase.name(), keyBase.version(), Context.NONE).value();
+ return client.getKey(keyBase.name(), keyBase.version(), context).block();
}
/**
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
index 12eacca66a16d..1ecb1479fd7ff 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyAsyncClientJavaDocCodeSnippets.java
@@ -12,7 +12,6 @@
import com.azure.core.test.policy.RecordNetworkCallPolicy;
import com.azure.identity.credential.DefaultAzureCredential;
import com.azure.security.keyvault.keys.models.EcKeyCreateOptions;
-import com.azure.security.keyvault.keys.models.Key;
import com.azure.security.keyvault.keys.models.KeyBase;
import com.azure.security.keyvault.keys.models.KeyCreateOptions;
import com.azure.security.keyvault.keys.models.RsaKeyCreateOptions;
@@ -209,14 +208,6 @@ public void getKeyWithResponseSnippets() {
keyResponse.value().name(), keyResponse.value().id()));
// END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string-string
- // BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string
- keyAsyncClient.getKeyWithResponse("keyName")
- .subscriberContext(Context.of(key1, value1, key2, value2))
- .subscribe(keyResponse ->
- System.out.printf("Key is created with name %s and id %s \n",
- keyResponse.value().name(), keyResponse.value().id()));
- // END: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#string
-
// BEGIN: com.azure.security.keyvault.keys.async.keyclient.getKeyWithResponse#KeyBase
keyAsyncClient.listKeys().subscribe(keyBase ->
keyAsyncClient.getKeyWithResponse(keyBase)
@@ -263,12 +254,11 @@ public void updateKeyWithResponseSnippets() {
KeyAsyncClient keyAsyncClient = createAsyncClient();
// BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations
- keyAsyncClient.getKeyWithResponse("keyName")
+ keyAsyncClient.getKey("keyName")
.subscribe(keyResponse -> {
- Key key = keyResponse.value();
//Update the not before time of the key.
- key.notBefore(OffsetDateTime.now().plusDays(50));
- keyAsyncClient.updateKeyWithResponse(key, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
+ keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
+ keyAsyncClient.updateKeyWithResponse(keyResponse, KeyOperation.ENCRYPT, KeyOperation.DECRYPT)
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(updatedKeyResponse ->
System.out.printf("Key's updated not before time %s \n",
@@ -277,12 +267,11 @@ public void updateKeyWithResponseSnippets() {
// END: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase-keyOperations
// BEGIN: com.azure.security.keyvault.keys.async.keyclient.updateKeyWithResponse#KeyBase
- keyAsyncClient.getKeyWithResponse("keyName")
+ keyAsyncClient.getKey("keyName")
.subscribe(keyResponse -> {
- Key key = keyResponse.value();
//Update the not before time of the key.
- key.notBefore(OffsetDateTime.now().plusDays(50));
- keyAsyncClient.updateKeyWithResponse(key)
+ keyResponse.notBefore(OffsetDateTime.now().plusDays(50));
+ keyAsyncClient.updateKeyWithResponse(keyResponse)
.subscriberContext(Context.of(key1, value1, key2, value2))
.subscribe(updatedKeyResponse ->
System.out.printf("Key's updated not before time %s \n",
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
index c2e2caedfee11..6288ff490aa5a 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/KeyClientJavaDocCodeSnippets.java
@@ -4,10 +4,6 @@
package com.azure.security.keyvault.keys;
import com.azure.core.credentials.TokenCredential;
-import com.azure.core.http.HttpClient;
-import com.azure.core.http.HttpPipeline;
-import com.azure.core.http.HttpPipelineBuilder;
-import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.VoidResponse;
import com.azure.core.util.Context;
@@ -123,23 +119,23 @@ public void createKeyWithResponses() {
System.out.printf("Key is created with name %s and id %s \n", optionsKey.name(), optionsKey.id());
// END: com.azure.keyvault.keys.keyclient.createKeyWithResponse#keyCreateOptions-Context
- // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
+ // BEGIN: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context
RsaKeyCreateOptions rsaKeyCreateOptions = new RsaKeyCreateOptions("keyName")
.keySize(2048)
.notBefore(OffsetDateTime.now().plusDays(1))
.expires(OffsetDateTime.now().plusYears(1));
Key rsaKey = keyClient.createRsaKeyWithResponse(rsaKeyCreateOptions, new Context(key1, value1)).value();
System.out.printf("Key is created with name %s and id %s \n", rsaKey.name(), rsaKey.id());
- // END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions
+ // END: com.azure.keyvault.keys.keyclient.createRsaKeyWithResponse#keyOptions-Context
- // BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
+ // BEGIN: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
EcKeyCreateOptions ecKeyCreateOptions = new EcKeyCreateOptions("keyName")
.curve(KeyCurveName.P_384)
.notBefore(OffsetDateTime.now().plusDays(1))
.expires(OffsetDateTime.now().plusYears(1));
Key ecKey = keyClient.createEcKeyWithResponse(ecKeyCreateOptions, new Context(key1, value1)).value();
System.out.printf("Key is created with name %s and id %s \n", ecKey.name(), ecKey.id());
- // END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions
+ // END: com.azure.keyvault.keys.keyclient.createEcKeyWithResponse#keyOptions-Context
}
/**
@@ -153,6 +149,14 @@ public void getKeyWithResponseSnippets() {
new Context(key1, value1)).value();
System.out.printf("Key is returned with name %s and id %s \n", keyWithVersion.name(), keyWithVersion.id());
// END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#string-string-Context
+
+ // BEGIN: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
+ for (KeyBase key : keyClient.listKeys()) {
+ Key keyResponse = keyClient.getKeyWithResponse(key, new Context(key1, value1)).value();
+ System.out.printf("Received key with name %s and type %s", keyResponse.name(),
+ keyResponse.keyMaterial().kty());
+ }
+ // END: com.azure.keyvault.keys.keyclient.getKeyWithResponse#KeyBase-Context
}
/**
diff --git a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
index 35ab9c7b1902f..74ff3fa9fbcfa 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/samples/java/com/azure/security/keyvault/keys/ListOperationsAsync.java
@@ -39,10 +39,10 @@ public static void main(String[] args) throws InterruptedException {
Thread.sleep(2000);
- keyAsyncClient.createRsaKeyWithResponse(new RsaKeyCreateOptions("CloudRsaKey")
+ keyAsyncClient.createRsaKey(new RsaKeyCreateOptions("CloudRsaKey")
.expires(OffsetDateTime.now().plusYears(1)))
.subscribe(keyResponse ->
- System.out.printf("Key is created with name %s and type %s \n", keyResponse.value().name(), keyResponse.value().keyMaterial().kty()));
+ System.out.printf("Key is created with name %s and type %s \n", keyResponse.name(), keyResponse.keyMaterial().kty()));
Thread.sleep(2000);
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index e6630fdeaafa6..0a5d502e80051 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -87,8 +87,7 @@ public final class SecretAsyncClient {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono setSecret(Secret secret) {
- return withContext(context -> setSecretWithResponse(secret))
- .flatMap(FluxUtil::toMono);
+ return setSecretWithResponse(secret).flatMap(FluxUtil::toMono);
}
/**
@@ -182,8 +181,7 @@ Mono> setSecret(String name, String value, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name, String version) {
- return withContext(context -> getSecretWithResponse(name, version))
- .flatMap(FluxUtil::toMono);
+ return this.getSecretWithResponse(name, version).flatMap(FluxUtil::toMono);
}
/**
@@ -214,13 +212,13 @@ public Mono> getSecretWithResponse(String name, String version)
Mono> getSecret(String name, String version, Context context) {
if (version == null) {
- return getSecretWithResponse(name, "");
+ return this.getSecretWithResponse(name, "");
}
return service.getSecret(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
- .doOnRequest(ignoredValue -> logger.info("Retrieving secret - {}", name))
- .doOnSuccess(response -> logger.info("Retrieved secret - {}", response.value().name()))
- .doOnError(error -> logger.warning("Failed to get secret - {}", name, error));
+ .doOnRequest(ignoredValue -> logger.info("Retrieving secret - {}", name))
+ .doOnSuccess(response -> logger.info("Retrieved secret - {}", response.value().name()))
+ .doOnError(error -> logger.warning("Failed to get secret - {}", name, error));
}
/**
@@ -245,12 +243,7 @@ Mono> getSecret(String name, String version, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(SecretBase secretBase) {
- Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
- if (secretBase.version() == null) {
- return getSecret(secretBase.name());
- }
- return getSecretWithResponse(secretBase.name(), secretBase.version())
- .flatMap(FluxUtil::toMono);
+ return this.getSecretWithResponse(secretBase).flatMap(FluxUtil::toMono);
}
/**
@@ -276,11 +269,7 @@ public Mono getSecret(SecretBase secretBase) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> getSecretWithResponse(SecretBase secretBase) {
- Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
- if (secretBase.version() == null) {
- return getSecretWithResponse(secretBase.name(), "");
- }
- return getSecretWithResponse(secretBase.name(), secretBase.version());
+ return withContext(context -> this.getSecret(secretBase, context));
}
Mono> getSecret(SecretBase secretBase, Context context) {
@@ -335,8 +324,7 @@ Mono> getSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateSecret(SecretBase secret) {
- return withContext(context -> updateSecretWithResponse(secret))
- .flatMap(FluxUtil::toMono);
+ return this.updateSecretWithResponse(secret).flatMap(FluxUtil::toMono);
}
/**
@@ -392,8 +380,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono deleteSecret(String name) {
- return withContext(context -> deleteSecretWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.deleteSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -443,8 +430,7 @@ Mono> deleteSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getDeletedSecret(String name) {
- return withContext(context -> getDeletedSecretWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.getDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -527,8 +513,7 @@ Mono purgeDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recoverDeletedSecret(String name) {
- return withContext(context -> recoverDeletedSecretWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.recoverDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -578,8 +563,7 @@ Mono> recoverDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono backupSecret(String name) {
- return withContext(context -> backupSecretWithResponse(name))
- .flatMap(FluxUtil::toMono);
+ return this.backupSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -631,8 +615,7 @@ Mono> backupSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono restoreSecret(byte[] backup) {
- return withContext(context -> restoreSecretWithResponse(backup))
- .flatMap(FluxUtil::toMono);
+ return this.restoreSecretWithResponse(backup).flatMap(FluxUtil::toMono);
}
/**
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 20a8fb1d71c3f..fbf43ea1baca8 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
@@ -49,7 +49,7 @@ public final class SecretClient {
* set to true by key vault, if not specified.
*
* Code Samples
- * {@codesnippet com.azure.security.keyvault.secretclient.setSecret#secretBase}
+ * {@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}.
@@ -58,7 +58,7 @@ public final class SecretClient {
* @return The {@link Secret created secret}.
*/
public Secret setSecret(Secret secret) {
- return client.setSecret(secret, Context.NONE).block().value();
+ return this.setSecretWithResponse(secret, Context.NONE).value();
}
/**
@@ -76,7 +76,7 @@ public Secret setSecret(Secret secret) {
* @return The {@link Secret created secret}.
*/
public Secret setSecret(String name, String value) {
- return this.setSecretWithResponse(name, value, Context.NONE).value();
+ return client.setSecret(name, value, Context.NONE).block().value();
}
/**
@@ -85,17 +85,16 @@ public Secret setSecret(String name, String value) {
*
* 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.setSecret#string-string-Context}
+ * {@codesnippet com.azure.security.keyvault.secretclient.setSecretWithResponse#secret-Context}
*
- * @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.
+ * @param secret The Secret object containing information about the secret and its properties. The properties secret.name and secret.value must be non null.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @throws ResourceModifiedException if invalid {@code name} or {@code value} is specified.
* @throws HttpRequestException if {@code name} or {@code value} is empty string.
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}.
*/
- public Response setSecretWithResponse(String name, String value, Context context) {
- return client.setSecret(name, value, context).block();
+ public Response setSecretWithResponse(Secret secret, Context context) {
+ return client.setSecret(secret, context).block();
}
/**
@@ -113,7 +112,7 @@ public Response setSecretWithResponse(String name, String value, Context
* @return The requested {@link Secret secret}.
*/
public Secret getSecret(String name, String version) {
- return client.getSecret(name, version, Context.NONE).block().value();
+ return this.getSecretWithResponse(name, version, Context.NONE).value();
}
/**
@@ -169,25 +168,33 @@ public Secret getSecret(SecretBase secretBase) {
* @return The requested {@link Secret}.
*/
public Secret getSecret(String name) {
- return getSecret(name, "");
+ return this.getSecretWithResponse(name, "", Context.NONE).value();
}
/**
- * Get the latest version of the specified secret from the key vault. The get operation is applicable to any secret stored in Azure Key Vault.
- * This operation requires the {@code secrets/get} permission.
+ * 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 the latest version of the secret in the key vault. Prints out the details of the returned secret.
- * {@codesnippet com.azure.security.keyvault.secretclient.getSecretWithResponse#string-Context}
- *
- * @param name The name of the secret.
+ * 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.
- * @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() value} contains the requested {@link Secret}.
+ * @throws ResourceNotFoundException when a secret with {@code name} and {@code version} doesn't
+ * exist in the key vault.
+ * @throws HttpRequestException if {@code name} name} or {@code version} is empty string.
*/
- public Response getSecretWithResponse(String name, Context context) {
- return client.getSecret(name, "", context).block();
+ public Response getSecretWithResponse(String name, String version, Context context) {
+ return client.getSecret(name, version, context).block();
}
/**
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 c01aaec75542c..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,9 +3,6 @@
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.http.rest.VoidResponse;
import com.azure.core.util.Context;
@@ -54,7 +51,7 @@ public void getSecretCodeSnippets() {
}
/**
- * Method to insert code snippets for {@link SecretClient#getSecretWithResponse(String, Context)}
+ * Method to insert code snippets for {@link SecretClient#getSecretWithResponse(String, String, Context)}
*/
public void getSecretWithResponseCodeSnippets() {
SecretClient secretClient = getSecretClient();
@@ -66,12 +63,13 @@ public void getSecretWithResponseCodeSnippets() {
}
// END: com.azure.security.keyvault.secretclient.getSecretWithResponse#secretBase
- // BEGIN: com.azure.security.keyvault.secretclient.getSecretWithResponse#string-Context
- Secret secretWithVersion = secretClient.getSecretWithResponse("secretName",
+ // 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-Context
+ // END: com.azure.security.keyvault.secretclient.getSecretWithResponse#string-string-Context
}
/**
@@ -79,11 +77,11 @@ public void getSecretWithResponseCodeSnippets() {
*/
public void setSecretCodeSnippets() {
SecretClient secretClient = getSecretClient();
- // BEGIN: com.azure.security.keyvault.secretclient.setSecret#secretBase
+ // 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#secretBase
+ // END: com.azure.security.keyvault.secretclient.setSecret#secret
// BEGIN: com.azure.security.keyvault.secretclient.setSecret#string-string
Secret secret = secretClient.setSecret("secretName", "secretValue");
@@ -92,15 +90,15 @@ public void setSecretCodeSnippets() {
}
/**
- * Method to insert code snippets for {@link SecretClient#setSecretWithResponse(String, String, Context)}
+ * Method to insert code snippets for {@link SecretClient#setSecretWithResponse(Secret Context)}
*/
public void setSecretWithResponseCodeSnippets() {
SecretClient secretClient = getSecretClient();
- // BEGIN: com.azure.security.keyvault.secretclient.setSecret#string-string-Context
- Secret secret = secretClient.setSecretWithResponse("secretName", "secretValue",
- new Context(key1, value1)).value();
+ // 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.setSecret#string-string-Context
+ // END: com.azure.security.keyvault.secretclient.setSecretWithResponse#secret-Context
}
/**
From 67f73d75fde121adef7bafb52046454b14396bc6 Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Mon, 29 Jul 2019 11:59:26 -0700
Subject: [PATCH 10/15] adding context
---
.../com/azure/security/keyvault/secrets/SecretAsyncClient.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index 0a5d502e80051..d8799ef38281a 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -212,7 +212,7 @@ public Mono> getSecretWithResponse(String name, String version)
Mono> getSecret(String name, String version, Context context) {
if (version == null) {
- return this.getSecretWithResponse(name, "");
+ return this.getSecret(name, "", context);
}
return service.getSecret(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
From ca514236c714fc7e94fde850c40bbfaf1260b3fd Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Tue, 30 Jul 2019 11:50:57 -0700
Subject: [PATCH 11/15] updating secret client with naming changes
---
.../keyvault/secrets/SecretAsyncClient.java | 81 ++++++++-----------
.../keyvault/secrets/SecretClient.java | 58 ++++++-------
2 files changed, 57 insertions(+), 82 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
index d8799ef38281a..f9e661f8850bf 100644
--- a/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-secrets/src/main/java/com/azure/security/keyvault/secrets/SecretAsyncClient.java
@@ -86,9 +86,7 @@ public final class SecretAsyncClient {
* @return A {@link Mono} containing the {@link Secret created secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono setSecret(Secret secret) {
- return setSecretWithResponse(secret).flatMap(FluxUtil::toMono);
- }
+ public Mono setSecret(Secret secret) { return setSecretWithResponse(secret).flatMap(FluxUtil::toMono); }
/**
* The set operation adds a secret to the key vault. If the named secret already exists, Azure Key Vault creates
@@ -111,10 +109,10 @@ public Mono setSecret(Secret secret) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> setSecretWithResponse(Secret secret) {
- return withContext(context -> setSecret(secret, context));
+ return withContext(context -> setSecretWithResponse(secret, context));
}
- Mono> setSecret(Secret secret, Context context) {
+ Mono> setSecretWithResponse(Secret secret, Context context) {
Objects.requireNonNull(secret, "The Secret input parameter cannot be null.");
SecretRequestParameters parameters = new SecretRequestParameters()
.value(secret.value())
@@ -146,11 +144,10 @@ Mono> setSecret(Secret secret, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono setSecret(String name, String value) {
- return withContext(context -> setSecret(name, value, context))
- .flatMap(FluxUtil::toMono);
+ return withContext(context -> setSecretWithResponse(name, value, context)).flatMap(FluxUtil::toMono);
}
- Mono> setSecret(String name, String value, Context context) {
+ Mono> setSecretWithResponse(String name, String value, Context context) {
SecretRequestParameters parameters = new SecretRequestParameters().value(value);
return service.setSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, parameters, CONTENT_TYPE_HEADER_VALUE, context)
.doOnRequest(ignored -> logger.info("Setting secret - {}", name))
@@ -181,7 +178,7 @@ Mono> setSecret(String name, String value, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(String name, String version) {
- return this.getSecretWithResponse(name, version).flatMap(FluxUtil::toMono);
+ return getSecretWithResponse(name, version).flatMap(FluxUtil::toMono);
}
/**
@@ -207,15 +204,11 @@ public Mono getSecret(String name, String version) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> getSecretWithResponse(String name, String version) {
- return withContext(context -> getSecret(name, version, context));
+ return withContext(context -> getSecretWithResponse(name, version, context));
}
- Mono> getSecret(String name, String version, Context context) {
- if (version == null) {
- return this.getSecret(name, "", context);
- }
-
- return service.getSecret(endpoint, name, version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
+ Mono> getSecretWithResponse(String name, String version, Context context) {
+ return service.getSecret(endpoint, name, version == null ? "" : version, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
.doOnRequest(ignoredValue -> logger.info("Retrieving secret - {}", name))
.doOnSuccess(response -> logger.info("Retrieved secret - {}", response.value().name()))
.doOnError(error -> logger.warning("Failed to get secret - {}", name, error));
@@ -243,7 +236,7 @@ Mono> getSecret(String name, String version, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getSecret(SecretBase secretBase) {
- return this.getSecretWithResponse(secretBase).flatMap(FluxUtil::toMono);
+ return getSecretWithResponse(secretBase).flatMap(FluxUtil::toMono);
}
/**
@@ -269,15 +262,12 @@ public Mono getSecret(SecretBase secretBase) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> getSecretWithResponse(SecretBase secretBase) {
- return withContext(context -> this.getSecret(secretBase, context));
+ return withContext(context -> getSecretWithResponse(secretBase, context));
}
- Mono> getSecret(SecretBase secretBase, Context context) {
+ Mono> getSecretWithResponse(SecretBase secretBase, Context context) {
Objects.requireNonNull(secretBase, "The Secret Base parameter cannot be null.");
- if (secretBase.version() == null) {
- return getSecret(secretBase.name(), context);
- }
- return getSecret(secretBase.name(), secretBase.version(), context);
+ return getSecretWithResponse(secretBase.name(), secretBase.version() == null ? "" : secretBase.version(), context);
}
/**
@@ -295,14 +285,7 @@ Mono> getSecret(SecretBase secretBase, Context context) {
* @return A {@link Mono} containing the requested {@link Secret secret}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- public Mono getSecret(String name) {
- return getSecretWithResponse(name, "")
- .flatMap(FluxUtil::toMono);
- }
-
- Mono> getSecret(String name, Context context) {
- return getSecret(name, "", context);
- }
+ public Mono getSecret(String name) { return getSecretWithResponse(name, "").flatMap(FluxUtil::toMono); }
/**
* Updates the attributes associated with the specified secret, but not the value of the specified secret in the key vault. The update
@@ -324,7 +307,7 @@ Mono> getSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono updateSecret(SecretBase secret) {
- return this.updateSecretWithResponse(secret).flatMap(FluxUtil::toMono);
+ return updateSecretWithResponse(secret).flatMap(FluxUtil::toMono);
}
/**
@@ -347,10 +330,10 @@ public Mono updateSecret(SecretBase secret) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> updateSecretWithResponse(SecretBase secret) {
- return withContext(context -> updateSecret(secret, context));
+ return withContext(context -> updateSecretWithResponse(secret, context));
}
- Mono> updateSecret(SecretBase secret, Context context) {
+ Mono> updateSecretWithResponse(SecretBase secret, Context context) {
Objects.requireNonNull(secret, "The secret input parameter cannot be null.");
SecretRequestParameters parameters = new SecretRequestParameters()
.tags(secret.tags())
@@ -380,7 +363,7 @@ Mono> updateSecret(SecretBase secret, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono deleteSecret(String name) {
- return this.deleteSecretWithResponse(name).flatMap(FluxUtil::toMono);
+ return deleteSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -400,10 +383,10 @@ public Mono deleteSecret(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> deleteSecretWithResponse(String name) {
- return withContext(context -> deleteSecret(name, context));
+ return withContext(context -> deleteSecretWithResponse(name, context));
}
- Mono> deleteSecret(String name, Context context) {
+ Mono> deleteSecretWithResponse(String name, Context context) {
return service.deleteSecret(endpoint, name, API_VERSION, ACCEPT_LANGUAGE, CONTENT_TYPE_HEADER_VALUE, context)
.doOnRequest(ignored -> logger.info("Deleting secret - {}", name))
.doOnSuccess(response -> logger.info("Deleted secret - {}", response.value().name()))
@@ -430,7 +413,7 @@ Mono> deleteSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono getDeletedSecret(String name) {
- return this.getDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
+ return getDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -454,10 +437,10 @@ public Mono getDeletedSecret(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> getDeletedSecretWithResponse(String name) {
- return withContext(context -> getDeletedSecret(name, context));
+ 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()))
@@ -513,7 +496,7 @@ Mono purgeDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recoverDeletedSecret(String name) {
- return this.recoverDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
+ return recoverDeletedSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -534,10 +517,10 @@ public Mono recoverDeletedSecret(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> recoverDeletedSecretWithResponse(String name) {
- return withContext(context -> recoverDeletedSecret(name, context));
+ 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()))
@@ -563,7 +546,7 @@ Mono> recoverDeletedSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono backupSecret(String name) {
- return this.backupSecretWithResponse(name).flatMap(FluxUtil::toMono);
+ return backupSecretWithResponse(name).flatMap(FluxUtil::toMono);
}
/**
@@ -585,10 +568,10 @@ public Mono backupSecret(String name) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> backupSecretWithResponse(String name) {
- return withContext(context -> backupSecret(name, context));
+ 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))
@@ -615,7 +598,7 @@ Mono> backupSecret(String name, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono restoreSecret(byte[] backup) {
- return this.restoreSecretWithResponse(backup).flatMap(FluxUtil::toMono);
+ return restoreSecretWithResponse(backup).flatMap(FluxUtil::toMono);
}
/**
@@ -637,10 +620,10 @@ public Mono restoreSecret(byte[] backup) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> restoreSecretWithResponse(byte[] backup) {
- return withContext(context -> restoreSecret(backup, context));
+ 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"))
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 fbf43ea1baca8..e57063daf2e4c 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
@@ -58,7 +58,7 @@ public final class SecretClient {
* @return The {@link Secret created secret}.
*/
public Secret setSecret(Secret secret) {
- return this.setSecretWithResponse(secret, Context.NONE).value();
+ return setSecretWithResponse(secret, Context.NONE).value();
}
/**
@@ -76,7 +76,7 @@ public Secret setSecret(Secret secret) {
* @return The {@link Secret created secret}.
*/
public Secret setSecret(String name, String value) {
- return client.setSecret(name, value, Context.NONE).block().value();
+ return client.setSecretWithResponse(name, value, Context.NONE).block().value();
}
/**
@@ -94,7 +94,7 @@ public Secret setSecret(String name, String value) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret created secret}.
*/
public Response setSecretWithResponse(Secret secret, Context context) {
- return client.setSecret(secret, context).block();
+ return client.setSecretWithResponse(secret, context).block();
}
/**
@@ -112,7 +112,7 @@ public Response setSecretWithResponse(Secret secret, Context context) {
* @return The requested {@link Secret secret}.
*/
public Secret getSecret(String name, String version) {
- return this.getSecretWithResponse(name, version, Context.NONE).value();
+ return getSecretWithResponse(name, version, Context.NONE).value();
}
/**
@@ -132,7 +132,7 @@ public Secret getSecret(String name, String version) {
* @return A {@link Response} whose {@link Response#value() value} contains the requested {@link Secret secret}.
*/
public Response getSecretWithResponse(SecretBase secretBase, Context context) {
- return client.getSecret(secretBase, context).block();
+ return client.getSecretWithResponse(secretBase, context).block();
}
/**
@@ -150,9 +150,7 @@ public Response getSecretWithResponse(SecretBase secretBase, Context con
* @throws HttpRequestException if {@link SecretBase#name() name} or {@link SecretBase#version() version} is empty string.
* @return The requested {@link Secret secret}.
*/
- public Secret getSecret(SecretBase secretBase) {
- return this.getSecretWithResponse(secretBase, Context.NONE).value();
- }
+ public Secret getSecret(SecretBase secretBase) { return getSecretWithResponse(secretBase, Context.NONE).value(); }
/**
* Get the latest version of the specified secret from the key vault. The get operation is applicable to any secret stored in Azure Key Vault.
@@ -168,7 +166,7 @@ public Secret getSecret(SecretBase secretBase) {
* @return The requested {@link Secret}.
*/
public Secret getSecret(String name) {
- return this.getSecretWithResponse(name, "", Context.NONE).value();
+ return getSecretWithResponse(name, "", Context.NONE).value();
}
/**
@@ -194,7 +192,7 @@ public Secret getSecret(String name) {
* @throws HttpRequestException if {@code name} name} or {@code version} is empty string.
*/
public Response getSecretWithResponse(String name, String version, Context context) {
- return client.getSecret(name, version, context).block();
+ return client.getSecretWithResponse(name, version, context).block();
}
/**
@@ -216,7 +214,7 @@ public Response getSecretWithResponse(String name, String version, Conte
* @return A {@link Response} whose {@link Response#value() value} contains the {@link SecretBase updated secret}.
*/
public Response updateSecretWithResponse(SecretBase secret, Context context) {
- return client.updateSecret(secret, context).block();
+ return client.updateSecretWithResponse(secret, context).block();
}
/**
@@ -237,7 +235,7 @@ public Response updateSecretWithResponse(SecretBase secret, Context
* @return The {@link SecretBase updated secret}.
*/
public SecretBase updateSecret(SecretBase secret) {
- return this.updateSecretWithResponse(secret, Context.NONE).value();
+ return updateSecretWithResponse(secret, Context.NONE).value();
}
/**
@@ -255,7 +253,7 @@ public SecretBase updateSecret(SecretBase secret) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
public DeletedSecret deleteSecret(String name) {
- return this.deleteSecretWithResponse(name, Context.NONE).value();
+ return deleteSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -274,7 +272,7 @@ public DeletedSecret deleteSecret(String name) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
public Response deleteSecretWithResponse(String name, Context context) {
- return client.deleteSecret(name, context).block();
+ return client.deleteSecretWithResponse(name, context).block();
}
/**
@@ -293,7 +291,7 @@ public Response deleteSecretWithResponse(String name, Context con
* @return The {@link DeletedSecret deleted secret}.
*/
public DeletedSecret getDeletedSecret(String name) {
- return this.getDeletedSecretWithResponse(name, Context.NONE).value();
+ return getDeletedSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -313,7 +311,7 @@ public DeletedSecret getDeletedSecret(String name) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link DeletedSecret deleted secret}.
*/
public Response getDeletedSecretWithResponse(String name, Context context) {
- return client.getDeletedSecret(name, context).block();
+ return client.getDeletedSecretWithResponse(name, context).block();
}
/**
@@ -331,7 +329,7 @@ public Response getDeletedSecretWithResponse(String name, Context
* @return A {@link VoidResponse}.
*/
public VoidResponse purgeDeletedSecret(String name) {
- return client.purgeDeletedSecret(name, Context.NONE).block();
+ return purgeDeletedSecret(name, Context.NONE);
}
/**
@@ -369,7 +367,7 @@ public VoidResponse purgeDeletedSecret(String name, Context context) {
* @return The {@link Secret recovered secret}.
*/
public Secret recoverDeletedSecret(String name) {
- return this.recoverDeletedSecretWithResponse(name, Context.NONE).value();
+ return recoverDeletedSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -389,7 +387,7 @@ public Secret recoverDeletedSecret(String name) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret recovered secret}.
*/
public Response recoverDeletedSecretWithResponse(String name, Context context) {
- return client.recoverDeletedSecret(name, context).block();
+ return client.recoverDeletedSecretWithResponse(name, context).block();
}
/**
@@ -406,7 +404,7 @@ public Response recoverDeletedSecretWithResponse(String name, Context co
* @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
*/
public byte[] backupSecret(String name) {
- return this.backupSecretWithResponse(name, Context.NONE).value();
+ return backupSecretWithResponse(name, Context.NONE).value();
}
/**
@@ -424,7 +422,7 @@ public byte[] backupSecret(String name) {
* @return A {@link Response} whose {@link Response#value() value} contains the backed up secret blob.
*/
public Response backupSecretWithResponse(String name, Context context) {
- return client.backupSecret(name, context).block();
+ return client.backupSecretWithResponse(name, context).block();
}
/**
@@ -442,7 +440,7 @@ public Response backupSecretWithResponse(String name, Context context) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}.
*/
public Secret restoreSecret(byte[] backup) {
- return this.restoreSecretWithResponse(backup, Context.NONE).value();
+ return restoreSecretWithResponse(backup, Context.NONE).value();
}
/**
@@ -461,7 +459,7 @@ public Secret restoreSecret(byte[] backup) {
* @return A {@link Response} whose {@link Response#value() value} contains the {@link Secret restored secret}.
*/
public Response restoreSecretWithResponse(byte[] backup, Context context) {
- return client.restoreSecret(backup, context).block();
+ return client.restoreSecretWithResponse(backup, context).block();
}
/**
@@ -475,9 +473,7 @@ public Response restoreSecretWithResponse(byte[] backup, Context context
*
* @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value.
*/
- public Iterable listSecrets() {
- return client.listSecrets().toIterable();
- }
+ public Iterable listSecrets() { 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
@@ -491,9 +487,7 @@ public Iterable listSecrets() {
* @param context Additional context that is passed through the Http pipeline during the service call.*
* @return A {@link List} containing {@link SecretBase} of all the secrets in the vault. The {@link SecretBase} contains all the information about the secret, except its value.
*/
- public Iterable listSecrets(Context context) {
- return client.listSecrets(context).toIterable();
- }
+ public Iterable listSecrets(Context context) { return client.listSecrets(context).toIterable(); }
/**
* Lists {@link DeletedSecret deleted secrets} of the key vault. The get deleted secrets operation returns the secrets that
@@ -521,7 +515,7 @@ public Iterable listDeletedSecrets(Context context) {
* @return A {@link List} containing all of the {@link DeletedSecret deleted secrets} in the vault.
*/
public Iterable listDeletedSecrets() {
- return client.listDeletedSecrets().toIterable();
+ return listDeletedSecrets(Context.NONE);
}
/**
@@ -538,9 +532,7 @@ public Iterable listDeletedSecrets() {
* @throws HttpRequestException when a secret with {@code name} is empty string.
* @return A {@link List} containing {@link SecretBase} of all the versions of the specified secret in the vault. List is empty if secret with {@code name} does not exist in key vault
*/
- public Iterable listSecretVersions(String name) {
- return client.listSecretVersions(name).toIterable();
- }
+ public Iterable listSecretVersions(String name) { return listSecretVersions(name, Context.NONE); }
/**
* List all versions of the specified secret. The individual secret response in the list is represented by {@link SecretBase}
From 6456392e2c81c58b441d0723161bada9ebf3756d Mon Sep 17 00:00:00 2001
From: Sameeksha Vaity
Date: Tue, 30 Jul 2019 14:27:34 -0700
Subject: [PATCH 12/15] updating key client with name changes
---
.../keyvault/keys/KeyAsyncClient.java | 99 ++++++++-----------
.../security/keyvault/keys/KeyClient.java | 95 ++++++++++--------
.../keys/KeyClientJavaDocCodeSnippets.java | 9 ++
3 files changed, 103 insertions(+), 100 deletions(-)
diff --git a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
index 000f9c806c4c5..4f3ccce61ea45 100644
--- a/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
+++ b/sdk/keyvault/azure-keyvault-keys/src/main/java/com/azure/security/keyvault/keys/KeyAsyncClient.java
@@ -97,8 +97,7 @@ public final class KeyAsyncClient {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono createKey(String name, KeyType keyType) {
- return withContext(context -> createKey(name, keyType, context))
- .flatMap(FluxUtil::toMono);
+ return withContext(context -> createKeyWithResponse(name, keyType, context)).flatMap(FluxUtil::toMono);
}
/**
@@ -120,10 +119,10 @@ public Mono createKey(String name, KeyType keyType) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> createKeyWithResponse(KeyCreateOptions keyCreateOptions) {
- return withContext(context -> createKey(keyCreateOptions, context));
+ return withContext(context -> createKeyWithResponse(keyCreateOptions, context));
}
- Mono