Search in sources :

Example 86 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class PlatformParameterServiceTest method getPlatformResourceRequestCredentialByCrn.

@Test
void getPlatformResourceRequestCredentialByCrn() {
    final Credential credential = new Credential();
    credential.setCloudPlatform("anotherVariant");
    when(credentialService.getOptionalByCrnForAccountId(eq(CREDENTIAL_CRN), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(Optional.of(credential));
    when(credentialService.extractCredential(any(), any())).thenReturn(credential);
    PlatformResourceRequest result = platformParameterServiceUnderTest.getPlatformResourceRequest(ACCOUNT_ID, null, CREDENTIAL_CRN, REGION, PLATFORM_VARIANT, AVAILIBILTY_ZONE);
    assertEquals(credential, result.getCredential());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Test(org.junit.jupiter.api.Test)

Example 87 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AuditCredentialAuthorizationIntegrationTest method getAwsCredential.

private Credential getAwsCredential(String name, String accountId, String userCrn) {
    Credential credential = new Credential();
    credential.setName(name);
    credential.setResourceCrn(getResourceCrn(name, accountId));
    credential.setAccountId(accountId);
    credential.setCloudPlatform("AWS");
    credential.setCreator(userCrn);
    credential.setDescription("description");
    credential.setType(CredentialType.AUDIT);
    credential.setGovCloud(false);
    credential.setArchived(false);
    return credential;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 88 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class CredentialAuthorizationIntegrationTest method getAwsCredential.

private Credential getAwsCredential(String name, String accountId, String userCrn) {
    Credential credential = new Credential();
    credential.setName(name);
    credential.setResourceCrn(getResourceCrn(name, accountId));
    credential.setAccountId(accountId);
    credential.setCloudPlatform("AWS");
    credential.setCreator(userCrn);
    credential.setDescription("description");
    credential.setType(CredentialType.ENVIRONMENT);
    credential.setGovCloud(false);
    credential.setArchived(false);
    return credential;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential)

Example 89 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method createEnvironment.

private Environment createEnvironment() {
    Environment environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setId(1L);
    environment.setAccountId("2");
    environment.setDescription("description");
    environment.setCloudPlatform("AZURE");
    environment.setCredential(new Credential());
    environment.setLatitude(2.4);
    environment.setLongitude(3.5);
    environment.setLocation(LOCATION);
    environment.setLocationDisplayName("London");
    environment.setNetwork(new AzureNetwork());
    environment.setRegions(Collections.singleton(new Region()));
    return environment;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment) Region(com.sequenceiq.environment.environment.domain.Region) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork)

Example 90 with Credential

use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.

the class PlatformParameterService method getPlatformResourceRequest.

// CHECKSTYLE:OFF
public PlatformResourceRequest getPlatformResourceRequest(String accountId, String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone, String sharedProjectId, Map<String, String> filter, AccessConfigTypeQueryParam accessConfigType, CdpResourceType cdpResourceType) {
    // CHECKSTYLE:ON
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    if (!Strings.isNullOrEmpty(credentialName)) {
        Optional<Credential> credential = credentialService.getOptionalByNameForAccountId(credentialName, accountId, ENVIRONMENT);
        if (credential.isEmpty()) {
            credential = credentialService.getOptionalByNameForAccountId(credentialName, accountId, AUDIT);
        }
        platformResourceRequest.setCredential(credentialService.extractCredential(credential, credentialName));
    } else if (!Strings.isNullOrEmpty(credentialCrn)) {
        Optional<Credential> credential = credentialService.getOptionalByCrnForAccountId(credentialCrn, accountId, ENVIRONMENT);
        if (credential.isEmpty()) {
            credential = credentialService.getOptionalByCrnForAccountId(credentialCrn, accountId, AUDIT);
        }
        platformResourceRequest.setCredential(credentialService.extractCredential(credential, credentialCrn));
    } else {
        throw new BadRequestException("The credentialCrn or the credentialName must be specified in the request");
    }
    if (!Strings.isNullOrEmpty(platformVariant)) {
        platformResourceRequest.setCloudPlatform(platformResourceRequest.getCredential().getCloudPlatform());
    } else {
        platformResourceRequest.setPlatformVariant(Strings.isNullOrEmpty(platformVariant) ? platformResourceRequest.getCredential().getCloudPlatform() : platformVariant);
    }
    platformResourceRequest.setCdpResourceType(Objects.requireNonNullElse(cdpResourceType, CdpResourceType.DEFAULT));
    platformResourceRequest.setRegion(region);
    platformResourceRequest.setCloudPlatform(platformResourceRequest.getCredential().getCloudPlatform());
    if (!Strings.isNullOrEmpty(availabilityZone)) {
        platformResourceRequest.setAvailabilityZone(availabilityZone);
    }
    String accessConfigTypeString = NullUtil.getIfNotNull(accessConfigType, Enum::name);
    if (filter != null) {
        initFilterMap(platformResourceRequest);
        for (Map.Entry<String, String> entry : filter.entrySet()) {
            platformResourceRequest.getFilters().put(entry.getKey(), entry.getValue());
        }
    }
    if (accessConfigTypeString != null) {
        initFilterMap(platformResourceRequest);
        platformResourceRequest.getFilters().put(ACCESS_CONFIG_TYPE, accessConfigTypeString);
    }
    if (!Strings.isNullOrEmpty(sharedProjectId)) {
        initFilterMap(platformResourceRequest);
        platformResourceRequest.getFilters().put(SHARED_PROJECT_ID, sharedProjectId);
    }
    return platformResourceRequest;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Optional(java.util.Optional) BadRequestException(javax.ws.rs.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Credential (com.sequenceiq.environment.credential.domain.Credential)102 Test (org.junit.jupiter.api.Test)49 Environment (com.sequenceiq.environment.environment.domain.Environment)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)9 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 BadRequestException (javax.ws.rs.BadRequestException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)8 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)8 Set (java.util.Set)8 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)7 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)7 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)7 Map (java.util.Map)7 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6