use of com.microsoft.azure.management.resources.implementation.SubscriptionClientImpl in project photon-model by vmware.
the class AzureEndpointAdapterService method validateCredentials.
private DeferredResult<SubscriptionInner> validateCredentials(AuthCredentialsServiceState credentials) {
String msg = "Getting Azure Subscription [" + credentials.userLink + "] for endpoint validation";
AzureDeferredResultServiceCallback<SubscriptionInner> handler = new AzureDeferredResultServiceCallback<SubscriptionInner>(this, msg) {
@Override
protected DeferredResult<SubscriptionInner> consumeSuccess(SubscriptionInner subscription) {
logFine(() -> String.format("Got subscription %s with id %s", subscription.displayName(), subscription.id()));
if (!SubscriptionState.ENABLED.equals(subscription.state())) {
logFine(() -> String.format("Subscription with id %s is not in active" + " state but in %s", subscription.id(), subscription.state()));
return DeferredResult.failed(new IllegalStateException("Subscription is not active"));
}
return DeferredResult.completed(subscription);
}
};
AzureSdkClients azureSdkClients = new AzureSdkClients(credentials);
SubscriptionClientImpl subscriptionClient = azureSdkClients.getSubscriptionClientImpl();
subscriptionClient.subscriptions().getAsync(credentials.userLink, handler);
return handler.toDeferredResult().whenComplete((res, exc) -> azureSdkClients.close());
}
use of com.microsoft.azure.management.resources.implementation.SubscriptionClientImpl in project photon-model by vmware.
the class AzureInstanceService method validateAzureCredentials.
/**
* Validates azure credential by making an API call.
*/
private void validateAzureCredentials(final AzureInstanceContext ctx) {
if (ctx.computeRequest.isMockRequest) {
ctx.operation.complete();
return;
}
SubscriptionClientImpl subscriptionClient = new SubscriptionClientImpl(ctx.azureSdkClients.credentials);
subscriptionClient.subscriptions().getAsync(ctx.endpointAuth.userLink, new ServiceCallback<SubscriptionInner>() {
@Override
public void failure(Throwable e) {
// Azure doesn't send us any meaningful status code to work with
ServiceErrorResponse rsp = new ServiceErrorResponse();
rsp.message = "Invalid Azure credentials";
rsp.statusCode = STATUS_CODE_UNAUTHORIZED;
ctx.operation.fail(e, rsp);
}
@Override
public void success(SubscriptionInner result) {
logFine(() -> String.format("Got subscription %s with id %s", result.displayName(), result.id()));
ctx.operation.complete();
}
});
}
Aggregations