Search in sources :

Example 1 with CredentialResponse

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);
        }
    }
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Response(javax.ws.rs.core.Response) Credential(com.sequenceiq.consumption.dto.Credential) WebApplicationException(javax.ws.rs.WebApplicationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) BadRequestException(javax.ws.rs.BadRequestException) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Example 2 with CredentialResponse

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());
}
Also used : Credential(com.sequenceiq.consumption.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Test(org.junit.Test)

Example 3 with CredentialResponse

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);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.datalake.entity.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) LocationResponse(com.sequenceiq.environment.api.v1.environment.model.response.LocationResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with CredentialResponse

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());
}
Also used : CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Test(org.junit.jupiter.api.Test)

Example 5 with CredentialResponse

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());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(javax.ws.rs.BadRequestException) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest)

Aggregations

CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)29 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)12 Test (org.junit.jupiter.api.Test)10 InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)4 BadRequestException (javax.ws.rs.BadRequestException)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 Before (org.junit.Before)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)2 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)2 BackupResponse (com.sequenceiq.common.api.backup.response.BackupResponse)2