Search in sources :

Example 81 with Credential

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

the class CredentialServiceTest method testUpdateByAccountIdAndEnvironmentCredential.

@Test
void testUpdateByAccountIdAndEnvironmentCredential() {
    Credential result = new Credential();
    result.setId(2L);
    result.setResourceCrn("this");
    result.setCloudPlatform(PLATFORM);
    CREDENTIAL.setId(1L);
    CREDENTIAL.setResourceCrn("that");
    CREDENTIAL.setCloudPlatform(PLATFORM);
    when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
    when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
    when(repository.save(any())).thenAnswer(i -> i.getArgument(0));
    when(credentialValidator.validateCredentialUpdate(any(Credential.class), any(Credential.class), any(CredentialType.class))).thenReturn(ValidationResult.builder().build());
    Credential testResult = credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, ENVIRONMENT);
    verify(repository).save(CREDENTIAL);
    assertEquals(2L, testResult.getId());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CredentialType(com.sequenceiq.common.model.CredentialType) CredentialVerification(com.sequenceiq.environment.credential.verification.CredentialVerification) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 82 with Credential

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

the class EnvironmentCreationService method initializeEnvironment.

private Environment initializeEnvironment(EnvironmentCreationDto creationDto) {
    Environment environment = environmentDtoConverter.creationDtoToEnvironment(creationDto);
    environment.setResourceCrn(creationDto.getCrn());
    Credential credential = environmentResourceService.getCredentialFromRequest(creationDto.getCredential(), creationDto.getAccountId());
    environment.setCredential(credential);
    Optional<ProxyConfig> proxyConfig = environmentResourceService.getProxyConfig(creationDto.getProxyConfigName(), creationDto.getAccountId());
    proxyConfig.ifPresent(pc -> environment.setProxyConfig(pc));
    environment.setCloudPlatform(credential.getCloudPlatform());
    environment.setAuthentication(authenticationDtoConverter.dtoToAuthentication(creationDto.getAuthentication()));
    environment.setEnvironmentServiceVersion(environmentServiceVersion);
    LOGGER.info("Environment is initialized for creation.");
    return environment;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment) ProxyConfig(com.sequenceiq.environment.proxy.domain.ProxyConfig)

Example 83 with Credential

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

the class S3GuardTableDeleteHandler method deleteNoSqlTable.

private ResponseStatus deleteNoSqlTable(LocationAwareCredential locationAwareCredential, String dynamoDbTablename) {
    Credential credential = locationAwareCredential.getCredential();
    String cloudPlatform = credential.getCloudPlatform();
    String location = locationAwareCredential.getLocation();
    NoSqlConnector noSqlConnector = getNoSqlConnector(cloudPlatform);
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
    NoSqlTableMetadataRequest noSqlTableMetadataRequest = NoSqlTableMetadataRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
    NoSqlTableMetadataResponse noSqlTableMetaData = noSqlConnector.getNoSqlTableMetaData(noSqlTableMetadataRequest);
    if (ResponseStatus.OK.equals(noSqlTableMetaData.getStatus())) {
        NoSqlTableDeleteRequest request = NoSqlTableDeleteRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
        NoSqlTableDeleteResponse response = noSqlConnector.deleteNoSqlTable(request);
        return response.getStatus();
    } else {
        return ResponseStatus.OK;
    }
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) LocationAwareCredential(com.sequenceiq.environment.environment.domain.LocationAwareCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) NoSqlConnector(com.sequenceiq.cloudbreak.cloud.NoSqlConnector) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableDeleteResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteResponse) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse)

Example 84 with Credential

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

the class EnvironmentServiceIntegrationTest method testCredentialList.

@Test
public void testCredentialList() {
    credentialRepository.save(credential);
    CredentialResponses results = client.credentialV1Endpoint().list();
    assertTrue(results.getResponses().stream().anyMatch(credentialResponse -> credentialResponse.getName().equals(credential.getName())), String.format("Result set should have credential with name: %s", credential.getName()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) NetworkService(com.sequenceiq.environment.network.NetworkService) Map(java.util.Map) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) AzureCredentialRequestParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters) BadRequestException(javax.ws.rs.BadRequestException) RoleBasedRequest(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest) AwsDefaultRegionSelectionFailed(com.sequenceiq.cloudbreak.cloud.aws.common.exception.AwsDefaultRegionSelectionFailed) InteractiveLoginRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest) MockBean(org.springframework.boot.test.mock.mockito.MockBean) UmsResourceAuthorizationService(com.sequenceiq.authorization.service.UmsResourceAuthorizationService) AwsCredentialParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.AwsCredentialParameters) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CredentialStatus) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) ProxyResponses(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponses) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ProxyTestSource.getProxyConfig(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyConfig) ProxyConfigRepository(com.sequenceiq.environment.proxy.repository.ProxyConfigRepository) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest) UmsAccountAuthorizationService(com.sequenceiq.authorization.service.UmsAccountAuthorizationService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) ProxyRequest(com.sequenceiq.environment.api.v1.proxy.model.request.ProxyRequest) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.lenient(org.mockito.Mockito.lenient) CredentialRepository(com.sequenceiq.environment.credential.repository.CredentialRepository) TestConfigurationForServiceIntegration(com.sequenceiq.environment.service.integration.testconfiguration.TestConfigurationForServiceIntegration) Inject(javax.inject.Inject) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RightCheck(com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck) EnvironmentServiceClientBuilder(com.sequenceiq.environment.client.EnvironmentServiceClientBuilder) ForbiddenException(javax.ws.rs.ForbiddenException) QuartzJobInitializer(com.sequenceiq.cloudbreak.quartz.configuration.QuartzJobInitializer) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Maps(com.google.common.collect.Maps) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) KeyBasedParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.KeyBasedParameters) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) EnvironmentServiceCrnEndpoints(com.sequenceiq.environment.client.EnvironmentServiceCrnEndpoints) Collectors.toList(java.util.stream.Collectors.toList) AfterEach(org.junit.jupiter.api.AfterEach) ProxyTestSource.getProxyRequest(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyRequest) Assertions(org.junit.jupiter.api.Assertions) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) RequestProvider(com.sequenceiq.environment.credential.service.RequestProvider) InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) ProxyConfig(com.sequenceiq.environment.proxy.domain.ProxyConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 85 with Credential

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

the class EnvironmentServiceIntegrationTest method setup.

@BeforeEach
public void setup() {
    client = new EnvironmentServiceClientBuilder(String.format(SERVICE_ADDRESS, port)).withCertificateValidation(false).withDebug(true).withIgnorePreValidation(true).build().withCrn(TEST_USER_CRN);
    credential = new Credential();
    credential.setName("credential_test");
    credential.setResourceCrn(TEST_RESOURCE_CRN);
    credential.setAccountId(TEST_ACCOUNT_ID);
    credential.setCloudPlatform("AWS");
    credential.setCreator(TEST_USER_CRN);
    credential.setDescription("description");
    credential.setGovCloud(false);
    credential.setArchived(false);
    credential.setType(ENVIRONMENT);
    credentialRequest = new CredentialRequest();
    when(entitlementService.azureEnabled(any())).thenReturn(true);
    doNothing().when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any(), any());
    lenient().when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).then(i -> {
        List<RightCheck> rightChecks = i.getArgument(1);
        return rightChecks.stream().map(r -> Boolean.TRUE).collect(toList());
    });
    lenient().when(grpcUmsClient.checkAccountRight(anyString(), anyString(), any(), any())).thenReturn(true);
    Map<String, Boolean> rightCheckMap = Maps.newHashMap();
    rightCheckMap.put(credential.getResourceCrn(), true);
    when(umsResourceAuthorizationService.getRightOfUserOnResources(anyString(), any(), anyList())).thenReturn(rightCheckMap);
    when(grpcUmsClient.getResourceRoles(any(), any())).thenReturn(Set.of("crn:altus:iam:us-west-1:altus:resourceRole:Owner", "crn:altus:iam:us-west-1:altus:resourceRole:EnvironmentAdmin"));
}
Also used : RightCheck(com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck) BeforeEach(org.junit.jupiter.api.BeforeEach) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) ActiveProfiles(org.springframework.test.context.ActiveProfiles) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) NetworkService(com.sequenceiq.environment.network.NetworkService) Map(java.util.Map) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) AzureCredentialRequestParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialRequestParameters) BadRequestException(javax.ws.rs.BadRequestException) RoleBasedRequest(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.RoleBasedRequest) AwsDefaultRegionSelectionFailed(com.sequenceiq.cloudbreak.cloud.aws.common.exception.AwsDefaultRegionSelectionFailed) InteractiveLoginRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest) MockBean(org.springframework.boot.test.mock.mockito.MockBean) UmsResourceAuthorizationService(com.sequenceiq.authorization.service.UmsResourceAuthorizationService) AwsCredentialParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.AwsCredentialParameters) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CredentialStatus) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test) ProxyResponses(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponses) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ProxyTestSource.getProxyConfig(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyConfig) ProxyConfigRepository(com.sequenceiq.environment.proxy.repository.ProxyConfigRepository) InitCodeGrantFlowRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InitCodeGrantFlowRequest) UmsAccountAuthorizationService(com.sequenceiq.authorization.service.UmsAccountAuthorizationService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) ProxyRequest(com.sequenceiq.environment.api.v1.proxy.model.request.ProxyRequest) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.lenient(org.mockito.Mockito.lenient) CredentialRepository(com.sequenceiq.environment.credential.repository.CredentialRepository) TestConfigurationForServiceIntegration(com.sequenceiq.environment.service.integration.testconfiguration.TestConfigurationForServiceIntegration) Inject(javax.inject.Inject) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RightCheck(com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck) EnvironmentServiceClientBuilder(com.sequenceiq.environment.client.EnvironmentServiceClientBuilder) ForbiddenException(javax.ws.rs.ForbiddenException) QuartzJobInitializer(com.sequenceiq.cloudbreak.quartz.configuration.QuartzJobInitializer) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Maps(com.google.common.collect.Maps) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) KeyBasedParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.aws.KeyBasedParameters) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) EnvironmentServiceCrnEndpoints(com.sequenceiq.environment.client.EnvironmentServiceCrnEndpoints) Collectors.toList(java.util.stream.Collectors.toList) AfterEach(org.junit.jupiter.api.AfterEach) ProxyTestSource.getProxyRequest(com.sequenceiq.environment.proxy.v1.ProxyTestSource.getProxyRequest) Assertions(org.junit.jupiter.api.Assertions) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) RequestProvider(com.sequenceiq.environment.credential.service.RequestProvider) InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) ProxyConfig(com.sequenceiq.environment.proxy.domain.ProxyConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentServiceClientBuilder(com.sequenceiq.environment.client.EnvironmentServiceClientBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) BeforeEach(org.junit.jupiter.api.BeforeEach)

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