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();
}
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;
}
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;
}
}
}
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());
}
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");
}
}
Aggregations