From 0c8c38a005de4269b597719d53326b0241df791d Mon Sep 17 00:00:00 2001 From: Sameeksha Vaity Date: Tue, 23 Jul 2019 10:50:42 -0700 Subject: [PATCH] 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 3b71f4e882ccc..16e8100e88995 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 @@ -43,7 +43,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; } }