Search in sources :

Example 1 with UpdateSecretRequest

use of com.microsoft.azure.keyvault.requests.UpdateSecretRequest in project azure-sdk-for-java by Azure.

the class AsyncOperationsTest method secretAsync.

@Test
public void secretAsync() throws Exception {
    String vault = getVaultUri();
    String secretname = "mySecret";
    String password = "password";
    SetSecretRequest setSecretRequest = new SetSecretRequest.Builder(vault, secretname, password).build();
    SecretBundle secretBundle = keyVaultClient.setSecretAsync(setSecretRequest, null).get();
    Assert.assertNotNull(secretBundle);
    UpdateSecretRequest updateSecretRequest = new UpdateSecretRequest.Builder(secretBundle.id()).build();
    secretBundle = keyVaultClient.updateSecretAsync(updateSecretRequest, null).get();
    Assert.assertNotNull(secretBundle);
    secretBundle = keyVaultClient.getSecretAsync(secretBundle.id(), null).get();
    Assert.assertNotNull(secretBundle);
    List<SecretItem> secretItems = keyVaultClient.listSecretsAsync(vault, 2, null).get();
    Assert.assertNotNull(secretItems);
    List<SecretItem> secretVersionItems = keyVaultClient.listSecretVersionsAsync(vault, secretname, 2, null).get();
    Assert.assertNotNull(secretVersionItems);
    secretBundle = keyVaultClient.deleteSecretAsync(vault, secretname, null).get();
    Assert.assertNotNull(secretBundle);
    try {
        keyVaultClient.deleteSecretAsync(vault, secretname, null).get();
    } catch (ExecutionException ex) {
        Throwable t = ex.getCause();
        if (t instanceof KeyVaultErrorException) {
            Assert.assertEquals("SecretNotFound", ((KeyVaultErrorException) t).body().error().code());
        } else
            throw ex;
    }
}
Also used : SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) SecretItem(com.microsoft.azure.keyvault.models.SecretItem) SetSecretRequest(com.microsoft.azure.keyvault.requests.SetSecretRequest) ExecutionException(java.util.concurrent.ExecutionException) UpdateSecretRequest(com.microsoft.azure.keyvault.requests.UpdateSecretRequest) Test(org.junit.Test)

Aggregations

KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)1 SecretBundle (com.microsoft.azure.keyvault.models.SecretBundle)1 SecretItem (com.microsoft.azure.keyvault.models.SecretItem)1 SetSecretRequest (com.microsoft.azure.keyvault.requests.SetSecretRequest)1 UpdateSecretRequest (com.microsoft.azure.keyvault.requests.UpdateSecretRequest)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1