Search in sources :

Example 41 with Observable

use of rx.Observable 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 42 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class RoleAssignmentsInner method createByIdWithServiceResponseAsync.

/**
     * Creates a role assignment by ID.
     *
     * @param roleAssignmentId The ID of the role assignment to create.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the RoleAssignmentInner object
     */
public Observable<ServiceResponse<RoleAssignmentInner>> createByIdWithServiceResponseAsync(String roleAssignmentId) {
    if (roleAssignmentId == null) {
        throw new IllegalArgumentException("Parameter roleAssignmentId is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    final RoleAssignmentPropertiesInner properties = null;
    RoleAssignmentCreateParameters parameters = new RoleAssignmentCreateParameters();
    parameters.withProperties(null);
    return service.createById(roleAssignmentId, this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<RoleAssignmentInner>>>() {

        @Override
        public Observable<ServiceResponse<RoleAssignmentInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<RoleAssignmentInner> clientResponse = createByIdDelegate(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) RoleAssignmentCreateParameters(com.microsoft.azure.management.graphrbac.RoleAssignmentCreateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 43 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class ServicePrincipalImpl method createResourceAsync.

@Override
public Observable<ServicePrincipal> createResourceAsync() {
    ActiveDirectoryApplication application = (ActiveDirectoryApplication) ((Object) super.createdModel(applicationCreatable.key()));
    createParameters.withAppId(application.applicationId());
    Observable<ServicePrincipal> sp = manager.inner().servicePrincipals().createAsync(createParameters).map(innerToFluentMap(this)).flatMap(new Func1<ServicePrincipal, Observable<ServicePrincipal>>() {

        @Override
        public Observable<ServicePrincipal> call(ServicePrincipal servicePrincipal) {
            return refreshCredentialsAsync();
        }
    });
    if (roles == null || roles.isEmpty()) {
        return sp;
    }
    return sp.flatMap(new Func1<ServicePrincipal, Observable<ServicePrincipal>>() {

        @Override
        public Observable<ServicePrincipal> call(final ServicePrincipal servicePrincipal) {
            return Observable.from(roles.entrySet()).flatMap(new Func1<Map.Entry<String, BuiltInRole>, Observable<?>>() {

                @Override
                public Observable<?> call(Map.Entry<String, BuiltInRole> role) {
                    return manager().roleAssignments().define(UUID.randomUUID().toString()).forServicePrincipal(servicePrincipal).withBuiltInRole(role.getValue()).withScope(role.getKey()).createAsync().retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {

                        @Override
                        public Observable<?> call(Observable<? extends Throwable> observable) {
                            return observable.zipWith(Observable.range(1, 30), new Func2<Throwable, Integer, Integer>() {

                                @Override
                                public Integer call(Throwable throwable, Integer integer) {
                                    if (throwable instanceof CloudException && ((CloudException) throwable).body().code().equalsIgnoreCase("PrincipalNotFound")) {
                                        return integer;
                                    } else {
                                        throw Exceptions.propagate(throwable);
                                    }
                                }
                            }).flatMap(new Func1<Integer, Observable<?>>() {

                                @Override
                                public Observable<?> call(Integer i) {
                                    return Observable.timer(i, TimeUnit.SECONDS);
                                }
                            });
                        }
                    });
                }
            }).last().map(new Func1<Object, ServicePrincipal>() {

                @Override
                public ServicePrincipal call(Object o) {
                    return servicePrincipal;
                }
            });
        }
    }).map(new Func1<ServicePrincipal, ServicePrincipal>() {

        @Override
        public ServicePrincipal call(ServicePrincipal servicePrincipal) {
            for (PasswordCredentialImpl<?> passwordCredential : passwordCredentials) {
                passwordCredential.exportAuthFile((ServicePrincipalImpl) servicePrincipal);
            }
            for (CertificateCredentialImpl<?> certificateCredential : certificateCredentials) {
                certificateCredential.exportAuthFile((ServicePrincipalImpl) servicePrincipal);
            }
            return servicePrincipal;
        }
    });
}
Also used : ServicePrincipal(com.microsoft.azure.management.graphrbac.ServicePrincipal) BuiltInRole(com.microsoft.azure.management.graphrbac.BuiltInRole) CloudException(com.microsoft.azure.CloudException) Observable(rx.Observable) ActiveDirectoryApplication(com.microsoft.azure.management.graphrbac.ActiveDirectoryApplication) Func1(rx.functions.Func1) HashMap(java.util.HashMap) Map(java.util.Map) Func2(rx.functions.Func2)

Example 44 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class ServicePrincipalsInner method updatePasswordCredentialsWithServiceResponseAsync.

/**
     * Updates the passwordCredentials associated with a service principal.
     *
     * @param objectId The object ID of the service principal.
     * @param value A collection of PasswordCredentials.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
public Observable<ServiceResponse<Void>> updatePasswordCredentialsWithServiceResponseAsync(String objectId, List<PasswordCredentialInner> value) {
    if (objectId == null) {
        throw new IllegalArgumentException("Parameter objectId is required and cannot be null.");
    }
    if (this.client.tenantID() == null) {
        throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    Validator.validate(value);
    PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters();
    parameters.withValue(value);
    return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {

        @Override
        public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<Void> clientResponse = updatePasswordCredentialsDelegate(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) Observable(rx.Observable) PasswordCredentialsUpdateParameters(com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters) ResponseBody(okhttp3.ResponseBody)

Example 45 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class ServicePrincipalsInner method updateKeyCredentialsWithServiceResponseAsync.

/**
     * Update the keyCredentials associated with a service principal.
     *
     * @param objectId The object ID for which to get service principal information.
     * @param value A collection of KeyCredentials.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
public Observable<ServiceResponse<Void>> updateKeyCredentialsWithServiceResponseAsync(String objectId, List<KeyCredentialInner> value) {
    if (objectId == null) {
        throw new IllegalArgumentException("Parameter objectId is required and cannot be null.");
    }
    if (this.client.tenantID() == null) {
        throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    Validator.validate(value);
    KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters();
    parameters.withValue(value);
    return service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {

        @Override
        public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<Void> clientResponse = updateKeyCredentialsDelegate(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) KeyCredentialsUpdateParameters(com.microsoft.azure.management.graphrbac.KeyCredentialsUpdateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Aggregations

Observable (rx.Observable)311 ResponseBody (okhttp3.ResponseBody)119 Response (retrofit2.Response)111 ServiceResponse (com.microsoft.rest.ServiceResponse)108 Test (org.junit.Test)59 ArrayList (java.util.ArrayList)57 List (java.util.List)55 IOException (java.io.IOException)46 Subscription (rx.Subscription)34 Func1 (rx.functions.Func1)31 Map (java.util.Map)26 ByteBuf (io.netty.buffer.ByteBuf)24 TimeUnit (java.util.concurrent.TimeUnit)23 Schedulers (rx.schedulers.Schedulers)22 Collections (java.util.Collections)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 File (java.io.File)17 HashMap (java.util.HashMap)16 Subscriber (rx.Subscriber)15