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;
}
});
}
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);
}
}
});
}
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);
}
}
});
}
use of rx.Observable in project azure-sdk-for-java by Azure.
the class GroupsInner method addMemberWithServiceResponseAsync.
/**
* Add a member to a group.
*
* @param groupObjectId The object ID of the group to which to add the member.
* @param url A member object URL, such as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> addMemberWithServiceResponseAsync(String groupObjectId, String url) {
if (groupObjectId == null) {
throw new IllegalArgumentException("Parameter groupObjectId 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 (url == null) {
throw new IllegalArgumentException("Parameter url is required and cannot be null.");
}
GroupAddMemberParameters parameters = new GroupAddMemberParameters();
parameters.withUrl(url);
return service.addMember(groupObjectId, 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 = addMemberDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of rx.Observable in project azure-sdk-for-java by Azure.
the class UsersInner method getMemberGroupsWithServiceResponseAsync.
/**
* Gets a collection that contains the object IDs of the groups of which the user is a member.
*
* @param objectId The object ID of the user for which to get group membership.
* @param securityEnabledOnly If true, only membership in security-enabled groups should be checked. Otherwise, membership in all groups should be checked.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<String> object
*/
public Observable<ServiceResponse<List<String>>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) {
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.");
}
UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters();
parameters.withSecurityEnabledOnly(securityEnabledOnly);
return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<List<String>>>>() {
@Override
public Observable<ServiceResponse<List<String>>> call(Response<ResponseBody> response) {
try {
ServiceResponse<PageImpl1<String>> result = getMemberGroupsDelegate(response);
ServiceResponse<List<String>> clientResponse = new ServiceResponse<List<String>>(result.body().items(), result.response());
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
Aggregations