Search in sources :

Example 11 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class MockUserManagementService method createAccessKey.

@Override
public void createAccessKey(CreateAccessKeyRequest request, StreamObserver<CreateAccessKeyResponse> responseObserver) {
    LOGGER.info("Create access key for account: {}", request.getAccountId());
    String accessKeyId;
    String privateKey;
    AltusCredential altusCredential = AccessKeyType.Value.UNSET.equals(request.getType()) ? telemetyPublisherCredential : fluentCredential;
    if (altusCredential != null) {
        accessKeyId = altusCredential.getAccessKey();
        privateKey = new String(altusCredential.getPrivateKey());
    } else {
        accessKeyId = UUID.randomUUID().toString();
        privateKey = UUID.randomUUID().toString();
    }
    responseObserver.onNext(CreateAccessKeyResponse.newBuilder().setPrivateKey(privateKey).setAccessKey(AccessKey.newBuilder().setAccessKeyId(accessKeyId).build()).build());
    responseObserver.onCompleted();
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)

Example 12 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class MockUserManagementService method getAltusCredential.

private AltusCredential getAltusCredential(String altusCredentialFile, String altusCredentialProfile) {
    if (StringUtils.isNoneEmpty(altusCredentialFile, altusCredentialProfile) && Files.exists(Paths.get(altusCredentialFile))) {
        try {
            Map<String, Properties> propsMap = iniUtil.parseIni(new FileReader(altusCredentialFile));
            if (propsMap.containsKey(altusCredentialProfile)) {
                Properties prop = propsMap.get(altusCredentialProfile);
                String accessKey = prop.getProperty(ALTUS_ACCESS_KEY_ID, prop.getProperty(CDP_ACCESS_KEY_ID));
                String privateKey = prop.getProperty(ALTUS_PRIVATE_KEY, prop.getProperty(CDP_PRIVATE_KEY));
                return new AltusCredential(accessKey, privateKey.toCharArray());
            }
        } catch (IOException e) {
            LOGGER.warn("Error occurred during reading altus credential.", e);
        }
    }
    return null;
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties)

Example 13 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential 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)

Example 14 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class ClouderaManagerDatabusService method getAltusCredential.

AltusCredential getAltusCredential(Stack stack) {
    AltusCredential credential = createMachineUserAndGenerateKeys(stack);
    String accessKey = credential.getAccessKey();
    String privateKey = trimAndReplacePrivateKey(credential.getPrivateKey());
    return new AltusCredential(accessKey, privateKey.toCharArray());
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)

Example 15 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class ClouderaManagerMgmtTelemetryService method setupTelemetryRole.

public void setupTelemetryRole(final Stack stack, final ApiClient client, final ApiHostRef cmHostRef, final ApiRoleList mgmtRoles, final Telemetry telemetry) throws ApiException {
    if (isWorkflowAnalyticsEnabled(stack, telemetry)) {
        WorkloadAnalytics workloadAnalytics = telemetry.getWorkloadAnalytics();
        String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
        boolean useDbusCnameEndpoint = entitlementService.useDataBusCNameEndpointEnabled(accountId);
        String databusEndpoint = dataBusEndpointProvider.getDataBusEndpoint(workloadAnalytics.getDatabusEndpoint(), useDbusCnameEndpoint);
        ClouderaManagerResourceApi cmResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
        ApiConfigList apiConfigList = buildTelemetryCMConfigList(workloadAnalytics, databusEndpoint);
        cmResourceApi.updateConfig("Adding telemetry settings.", apiConfigList);
        AltusCredential credentials = clouderaManagerDatabusService.getAltusCredential(stack);
        Map<String, String> accountConfigs = new HashMap<>();
        accountConfigs.put(ALTUS_CREDENTIAL_ACCESS_KEY_NAME, credentials.getAccessKey());
        accountConfigs.put(ALTUS_CREDENTIAL_PRIVATE_KEY_NAME, new String(credentials.getPrivateKey()));
        externalAccountService.createExternalAccount(ALTUS_CREDENTIAL_NAME, ALTUS_CREDENTIAL_NAME, ALTUS_CREDENTIAL_TYPE, accountConfigs, client);
        final ApiRole telemetryPublisher = new ApiRole();
        telemetryPublisher.setName(TELEMETRYPUBLISHER);
        telemetryPublisher.setType(TELEMETRYPUBLISHER);
        telemetryPublisher.setHostRef(cmHostRef);
        mgmtRoles.addItemsItem(telemetryPublisher);
    } else {
        LOGGER.info("Telemetry WA is disabled");
    }
}
Also used : ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) ConfigUtils.makeApiConfigList(com.sequenceiq.cloudbreak.cm.util.ConfigUtils.makeApiConfigList) ApiRole(com.cloudera.api.swagger.model.ApiRole) HashMap(java.util.HashMap) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) WorkloadAnalytics(com.sequenceiq.common.api.telemetry.model.WorkloadAnalytics)

Aggregations

AltusCredential (com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)15 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)4 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 DataBusCredential (com.sequenceiq.common.api.telemetry.model.DataBusCredential)3 WorkloadAnalytics (com.sequenceiq.common.api.telemetry.model.WorkloadAnalytics)3 Test (org.junit.Test)3 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)2 ApiRole (com.cloudera.api.swagger.model.ApiRole)2 CreateAccessKeyResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse)2 UmsOperationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException)2 ConfigUtils.makeApiConfigList (com.sequenceiq.cloudbreak.cm.util.ConfigUtils.makeApiConfigList)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 HashMap (java.util.HashMap)2 Retryable (org.springframework.retry.annotation.Retryable)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiResponse (com.cloudera.api.swagger.client.ApiResponse)1 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1