Search in sources :

Example 1 with KeyImportParameters

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

the class KeyVaultClientImpl method importKeyWithServiceResponseAsync.

/**
     * Imports an externally created key, stores it, and returns key parameters and attributes to the client. The import key operation may be used to import any key type into an Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. Authorization: requires the keys/import permission.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName Name for the imported key.
     * @param key The Json web key
     * @param hsm Whether to import as a hardware key (HSM) or software key.
     * @param keyAttributes The key management attributes.
     * @param tags Application specific metadata in the form of key-value pairs.
     * @return the observable to the KeyBundle object
     */
public Observable<ServiceResponse<KeyBundle>> importKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, JsonWebKey key, Boolean hsm, KeyAttributes keyAttributes, Map<String, String> tags) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (key == null) {
        throw new IllegalArgumentException("Parameter key is required and cannot be null.");
    }
    Validator.validate(key);
    Validator.validate(keyAttributes);
    Validator.validate(tags);
    KeyImportParameters parameters = new KeyImportParameters();
    parameters.withHsm(hsm);
    parameters.withKey(key);
    parameters.withKeyAttributes(keyAttributes);
    parameters.withTags(tags);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.importKey(keyName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {

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

Example 2 with KeyImportParameters

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

the class KeyVaultClientImpl method importKeyWithServiceResponseAsync.

/**
     * Imports an externally created key, stores it, and returns key parameters and attributes to the client. The import key operation may be used to import any key type into an Azure Key Vault. If the named key already exists, Azure Key Vault creates a new version of the key. Authorization: requires the keys/import permission.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName Name for the imported key.
     * @param key The Json web key
     * @return the observable to the KeyBundle object
     */
public Observable<ServiceResponse<KeyBundle>> importKeyWithServiceResponseAsync(String vaultBaseUrl, String keyName, JsonWebKey key) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (key == null) {
        throw new IllegalArgumentException("Parameter key is required and cannot be null.");
    }
    Validator.validate(key);
    final Boolean hsm = null;
    final KeyAttributes keyAttributes = null;
    final Map<String, String> tags = null;
    KeyImportParameters parameters = new KeyImportParameters();
    parameters.withHsm(null);
    parameters.withKey(key);
    parameters.withKeyAttributes(null);
    parameters.withTags(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.importKey(keyName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyBundle>>>() {

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

Aggregations

KeyBundle (com.microsoft.azure.keyvault.models.KeyBundle)2 KeyImportParameters (com.microsoft.azure.keyvault.models.KeyImportParameters)2 ServiceResponse (com.microsoft.rest.ServiceResponse)2 ResponseBody (okhttp3.ResponseBody)2 Response (retrofit2.Response)2 Observable (rx.Observable)2 KeyAttributes (com.microsoft.azure.keyvault.models.KeyAttributes)1