use of com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest in project cloudbreak by hortonworks.
the class InitCodeGrantFlowHandler method accept.
@Override
public void accept(Event<InitCodeGrantFlowRequest> initCodeGrantFlowRequestEvent) {
LOGGER.info("Received event: {}", initCodeGrantFlowRequestEvent);
InitCodeGrantFlowRequest request = initCodeGrantFlowRequestEvent.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector<?> connector = cloudPlatformConnectors.getDefault(cloudContext.getPlatform());
Map<String, String> parameters = connector.credentials().initCodeGrantFlow(cloudContext, request.getCloudCredential());
InitCodeGrantFlowResponse initCodeGrantFlowResponse = new InitCodeGrantFlowResponse(request.getResourceId(), parameters);
request.getResult().onNext(initCodeGrantFlowResponse);
LOGGER.info("Authorization code grant flow has initialized successfully.");
} catch (RuntimeException e) {
request.getResult().onNext(new InitCodeGrantFlowResponse(e.getMessage(), e, request.getResourceId()));
}
}
use of com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest in project cloudbreak by hortonworks.
the class ServiceProviderCredentialAdapter method initCodeGrantFlow.
public Credential initCodeGrantFlow(Credential credential, String accountId) {
CloudContext cloudContext = CloudContext.Builder.builder().withId(credential.getId()).withName(credential.getName()).withCrn(credential.getResourceCrn()).withPlatform(credential.getCloudPlatform()).withVariant(credential.getCloudPlatform()).withAccountId(accountId).build();
CloudCredential cloudCredential = credentialConverter.convert(credential);
LOGGER.debug("Requesting code grant flow cloudPlatform {}.", credential.getCloudPlatform());
InitCodeGrantFlowRequest request = requestProvider.getInitCodeGrantFlowRequest(cloudContext, cloudCredential);
LOGGER.info("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
InitCodeGrantFlowResponse res = request.await();
LOGGER.info("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
String message = "Authorization code grant based credential creation couldn't be initialized: ";
LOGGER.error(message, res.getErrorDetails());
throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
}
Map<String, String> codeGrantFlowInitParams = res.getCodeGrantFlowInitParams();
addCodeGrantFlowInitAttributesToCredential(credential, codeGrantFlowInitParams);
return credential;
} catch (InterruptedException e) {
LOGGER.error("Error while executing initialization of authorization code grant based credential creation:", e);
throw new OperationException(e);
}
}
Aggregations