Search in sources :

Example 1 with InitCodeGrantFlowRequest

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()));
    }
}
Also used : InitCodeGrantFlowResponse(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowResponse) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest)

Example 2 with InitCodeGrantFlowRequest

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);
    }
}
Also used : InitCodeGrantFlowResponse(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowResponse) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(javax.ws.rs.BadRequestException) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 InitCodeGrantFlowRequest (com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest)2 InitCodeGrantFlowResponse (com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowResponse)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 BadRequestException (javax.ws.rs.BadRequestException)1