use of com.microsoft.azure.management.graphrbac.BuiltInRole 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;
}
});
}
Aggregations