use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CredentialService method getCredentialByEnvCrn.
public Credential getCredentialByEnvCrn(String envCrn) {
try {
CredentialResponse credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
SecretResponse secretResponse = credentialResponse.getAttributes();
String attributes = secretService.getByResponse(secretResponse);
return new Credential(credentialResponse.getCloudPlatform(), credentialResponse.getName(), attributes, credentialResponse.getCrn(), credentialResponse.getAccountId());
} catch (WebApplicationException e) {
try (Response response = e.getResponse()) {
if (Response.Status.NOT_FOUND.getStatusCode() == response.getStatus()) {
LOGGER.error("Credential not found by environment CRN: {}", envCrn, e);
throw new BadRequestException(String.format("Credential not found by environment CRN: %s", envCrn), e);
}
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
LOGGER.error("Failed to get credential for environment CRN [{}]: {}", envCrn, errorMessage);
throw new CloudbreakServiceException(String.format("Failed to get credential: %s", errorMessage), e);
}
}
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CredentialServiceTest method testGetCredentialByEnvCrnSuccessful.
@Test
public void testGetCredentialByEnvCrnSuccessful() {
CredentialResponse credentialResponse = new CredentialResponse();
credentialResponse.setCrn(CRN);
credentialResponse.setName(NAME);
credentialResponse.setAccountId(ACCOUNT_ID);
credentialResponse.setCloudPlatform(CLOUD_PLATFORM);
credentialResponse.setAttributes(secretResponse);
when(credentialEndpoint.getByEnvironmentCrn(ENVIRONMENT_CRN)).thenReturn(credentialResponse);
Credential credential = underTest.getCredentialByEnvCrn(ENVIRONMENT_CRN);
assertEquals(CRN, credential.getCrn());
assertEquals(NAME, credential.getName());
assertEquals(ACCOUNT_ID, credential.getAccountId());
assertEquals(CLOUD_PLATFORM, credential.getCloudPlatform());
assertEquals(ATTRIBUTES, credential.getAttributes());
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method setUp.
@BeforeEach
public void setUp() {
LocationResponse locationResponse = LocationResponseBuilder.aLocationResponse().withName(ENV_REGION).build();
when(environment.getLocation()).thenReturn(locationResponse);
when(environment.getCloudPlatform()).thenReturn(CLOUD_PLATFORM);
when(environment.getCredential()).thenReturn(new CredentialResponse());
when(credentialToCloudCredentialConverter.convert(any(Credential.class))).thenReturn(CLOUD_CREDENTIAL);
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CloudStorageValidatorTest method validateEnvironmentRequestCloudStorageValidation.
@Test
public void validateEnvironmentRequestCloudStorageValidation() {
when(environment.getCloudStorageValidation()).thenReturn(CloudStorageValidation.ENABLED);
when(environment.getCredential()).thenReturn(new CredentialResponse());
when(secretService.getByResponse(any())).thenReturn("secret");
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(credentialToCloudCredentialConverter.convert(any())).thenReturn(new CloudCredential("id", "name", Map.of("secretKey", "thisshouldnotappearinlog"), "acc", false));
when(entitlementService.cloudStorageValidationEnabled(any())).thenReturn(true);
when(cloudProviderServicesV4Endopint.validateObjectStorage(any())).thenReturn(new ObjectStorageValidateResponse());
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validate(new CloudStorageRequest(), environment, validationResultBuilder));
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class InteractiveCredentialCreationHandler method accept.
@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
try {
LOGGER.debug("Azure init code grant flow for account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
credentialService.initCodeGrantFlow(credential.getAccountId(), credential, credential.getCreator());
CredentialResponse payload = extendedCloudCredentialToCredentialConverter.convert(credential);
LOGGER.debug("Sending notification that the interactive credential successfully created account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
eventService.sendEventAndNotificationWithPayload(credential, credential.getCreator(), CREDENTIAL_AZURE_INTERACTIVE_CREATED, payload);
LOGGER.info("Azure interactive credential ({}) succesfully created", credential.getName());
} catch (BadRequestException e) {
LOGGER.debug("Sending notification that the interactive credential failed to create account id {} creator {} credential name {}", credential.getAccountId(), credential.getCreator(), credential.getName());
eventService.sendEventAndNotificationWithPayload(credential, credential.getCreator(), CREDENTIAL_AZURE_INTERACTIVE_FAILED, null);
LOGGER.info("Failed to create Azure interactive credential with name \"{}\"", credential.getName());
}
}
Aggregations