Search in sources :

Example 1 with SecretAttributes

use of com.microsoft.azure.keyvault.models.SecretAttributes in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method updateSecretWithServiceResponseAsync.

/**
     * Updates the attributes associated with a specified secret in a given key vault.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param secretName The name of the secret.
     * @param secretVersion The version of the secret.
     * @return the observable to the SecretBundle object
     */
public Observable<ServiceResponse<SecretBundle>> updateSecretWithServiceResponseAsync(String vaultBaseUrl, String secretName, String secretVersion) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (secretName == null) {
        throw new IllegalArgumentException("Parameter secretName is required and cannot be null.");
    }
    if (secretVersion == null) {
        throw new IllegalArgumentException("Parameter secretVersion is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    final String contentType = null;
    final SecretAttributes secretAttributes = null;
    final Map<String, String> tags = null;
    SecretUpdateParameters parameters = new SecretUpdateParameters();
    parameters.withContentType(null);
    parameters.withSecretAttributes(null);
    parameters.withTags(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.updateSecret(secretName, secretVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SecretBundle>>>() {

        @Override
        public Observable<ServiceResponse<SecretBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<SecretBundle> clientResponse = updateSecretDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : SecretUpdateParameters(com.microsoft.azure.keyvault.models.SecretUpdateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretAttributes(com.microsoft.azure.keyvault.models.SecretAttributes)

Example 2 with SecretAttributes

use of com.microsoft.azure.keyvault.models.SecretAttributes in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method setSecretWithServiceResponseAsync.

/**
     * Sets a secret in a specified key vault.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param secretName The name of the secret.
     * @param value The value of the secret.
     * @return the observable to the SecretBundle object
     */
public Observable<ServiceResponse<SecretBundle>> setSecretWithServiceResponseAsync(String vaultBaseUrl, String secretName, String value) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (secretName == null) {
        throw new IllegalArgumentException("Parameter secretName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    final Map<String, String> tags = null;
    final String contentType = null;
    final SecretAttributes secretAttributes = null;
    SecretSetParameters parameters = new SecretSetParameters();
    parameters.withValue(value);
    parameters.withTags(null);
    parameters.withContentType(null);
    parameters.withSecretAttributes(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.setSecret(secretName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SecretBundle>>>() {

        @Override
        public Observable<ServiceResponse<SecretBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<SecretBundle> clientResponse = setSecretDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : SecretSetParameters(com.microsoft.azure.keyvault.models.SecretSetParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretAttributes(com.microsoft.azure.keyvault.models.SecretAttributes)

Example 3 with SecretAttributes

use of com.microsoft.azure.keyvault.models.SecretAttributes in project azure-sdk-for-java by Azure.

the class SecretOperationsTest method disabledSecretGet.

@Test
public // verifies the inner error on disabled secret
void disabledSecretGet() throws Exception {
    String secretName = "disabledsecret";
    SecretBundle secret = keyVaultClient.setSecret(new SetSecretRequest.Builder(getVaultUri(), secretName, SECRET_VALUE).withAttributes(new SecretAttributes().withEnabled(false)).build());
    try {
        keyVaultClient.getSecret(secret.id());
        Assert.fail("Should throw exception for disabled secret.");
    } catch (KeyVaultErrorException e) {
        Assert.assertEquals(e.body().error().code(), "Forbidden");
        Assert.assertNotNull(e.body().error().message());
        Assert.assertNotNull(e.body().error().innerError());
        Assert.assertEquals(e.body().error().innerError().code(), "SecretDisabled");
    } catch (Exception e) {
        Assert.fail("Should throw KeyVaultErrorException for disabled secret.");
    }
    keyVaultClient.deleteSecret(getVaultUri(), secretName);
}
Also used : SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) SecretAttributes(com.microsoft.azure.keyvault.models.SecretAttributes) SetSecretRequest(com.microsoft.azure.keyvault.requests.SetSecretRequest) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) Test(org.junit.Test)

Aggregations

SecretAttributes (com.microsoft.azure.keyvault.models.SecretAttributes)3 SecretBundle (com.microsoft.azure.keyvault.models.SecretBundle)3 ServiceResponse (com.microsoft.rest.ServiceResponse)2 ResponseBody (okhttp3.ResponseBody)2 Response (retrofit2.Response)2 Observable (rx.Observable)2 KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)1 SecretSetParameters (com.microsoft.azure.keyvault.models.SecretSetParameters)1 SecretUpdateParameters (com.microsoft.azure.keyvault.models.SecretUpdateParameters)1 SetSecretRequest (com.microsoft.azure.keyvault.requests.SetSecretRequest)1 Test (org.junit.Test)1