Search in sources :

Example 1 with CreateAccessKeyResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse in project cloudbreak by hortonworks.

the class GrpcUmsClient method generateAccessSecretKeyPair.

/**
 * Generate access / private keypair
 *
 * @param actorCrn       actor that executes the key generation
 * @param machineUserCrn machine user (owner of the access key)
 * @param requestId      id for the request
 * @param accessKeyType  algorithm type used for the access key
 * @return access / private key holder object
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public AltusCredential generateAccessSecretKeyPair(String actorCrn, String accountId, String machineUserCrn, Optional<String> requestId, AccessKeyType.Value accessKeyType, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
        LOGGER.info("Generating new access / secret key pair for {}", machineUserCrn);
        CreateAccessKeyResponse accessKeyResponse = client.createAccessPrivateKeyPair(RequestIdUtil.getOrGenerate(requestId), actorCrn, accountId, machineUserCrn, accessKeyType);
        return new AltusCredential(accessKeyResponse.getAccessKey().getAccessKeyId(), accessKeyResponse.getPrivateKey().toCharArray());
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot generate access key pair for machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with CreateAccessKeyResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse in project cloudbreak by hortonworks.

the class GrpcUmsClient method generateAccessSecretKeyPair.

/**
 * Generate access / private keypair
 *
 * @param actorCrn       actor that executes the key generation
 * @param machineUserCrn machine user (owner of the access key)
 * @param requestId      id for the request
 * @param accessKeyType  algorithm type used for the access key
 * @return access / private key holder object
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public AltusCredential generateAccessSecretKeyPair(String actorCrn, String accountId, String machineUserCrn, Optional<String> requestId, AccessKeyType.Value accessKeyType) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel());
        LOGGER.info("Generating new access / secret key pair for {}", machineUserCrn);
        CreateAccessKeyResponse accessKeyResponse = client.createAccessPrivateKeyPair(RequestIdUtil.getOrGenerate(requestId), actorCrn, accountId, machineUserCrn, accessKeyType);
        return new AltusCredential(accessKeyResponse.getAccessKey().getAccessKeyId(), accessKeyResponse.getPrivateKey().toCharArray());
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot generate access key pair for machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

CreateAccessKeyResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse)2 UmsOperationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException)2 AltusCredential (com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 Retryable (org.springframework.retry.annotation.Retryable)2