Search in sources :

Example 1 with SecretResponse

use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse 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 SecretResponse

use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenSecretCouldNotBeFetchedFromVault.

@Test
void testGetWhenSecretCouldNotBeFetchedFromVault() {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    SecretResponse secretResponse = new SecretResponse();
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(secretResponse);
    proxyResponse.setPassword(secretResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
    when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
    when(secretService.getByResponse(any(SecretResponse.class))).thenThrow(new VaultException("Vault token is invalid!"));
    CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"));
    assertEquals("Failed to get Proxy config related secret due to: 'Vault token is invalid!' ", exception.getMessage());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) VaultException(org.springframework.vault.VaultException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SecretResponse

use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigCouldBeFetched.

@Test
void testGetWhenProxyConfigCouldBeFetched() {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    String decryptedSecretValue = "decrypted-secret-value";
    String noProxyList = "noproxy.com";
    SecretResponse secretResponse = new SecretResponse();
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(secretResponse);
    proxyResponse.setPassword(secretResponse);
    proxyResponse.setNoProxyHosts(noProxyList);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
    when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
    when(secretService.getByResponse(any(SecretResponse.class))).thenReturn(decryptedSecretValue);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    verify(secretService, times(2)).getByResponse(secretResponse);
    assertEquals(proxyConfig.getName(), name);
    assertEquals(proxyConfig.getServerHost(), host);
    assertEquals(proxyConfig.getServerPort(), port);
    assertTrue(proxyConfig.getProxyAuthentication().isPresent());
    assertEquals(proxyConfig.getProxyAuthentication().get().getUserName(), decryptedSecretValue);
    assertEquals(proxyConfig.getProxyAuthentication().get().getPassword(), decryptedSecretValue);
    assertEquals(proxyConfig.getNoProxyHosts(), noProxyList);
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SecretResponse

use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.

the class AbstractRdsConfigProviderTest method createServicePillarForRemoteRdsConfig.

@Test
public void createServicePillarForRemoteRdsConfig() {
    when(rdsConfigService.createIfNotExists(any(), any(), any())).thenAnswer(i -> i.getArguments()[1]);
    RDSConfig config = TestUtil.rdsConfig(DatabaseType.CLOUDERA_MANAGER);
    when(dbServerConfigurer.createNewRdsConfig(any(), any(), any(), any(), any())).thenReturn(config);
    when(dbServerConfigurer.isRemoteDatabaseNeeded(any())).thenReturn(true);
    DatabaseServerV4Response resp = new DatabaseServerV4Response();
    resp.setHost(DB_HOST);
    resp.setPort(DB_PORT);
    SecretResponse username = new SecretResponse("user", "name");
    SecretResponse password = new SecretResponse("pass", "word");
    resp.setConnectionUserName(username);
    resp.setConnectionPassword(password);
    when(dbServerConfigurer.getDatabaseServer(any())).thenReturn(resp);
    when(secretService.getByResponse(username)).thenReturn(REMOTE_ADMIN);
    when(secretService.getByResponse(password)).thenReturn(REMOTE_ADMIN_PASSWORD);
    Stack testStack = TestUtil.stack();
    InstanceMetaData metaData = testStack.getNotTerminatedAndNotZombieGatewayInstanceMetadata().iterator().next();
    metaData.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
    testStack.getNotTerminatedAndNotZombieGatewayInstanceMetadata().add(metaData);
    Cluster testCluster = TestUtil.cluster();
    testStack.setCluster(testCluster);
    Map<String, Object> result = underTest.createServicePillarConfigMapIfNeeded(testStack, testCluster);
    Map<String, Object> postgresData = (Map<String, Object>) result.get("clouderamanager");
    assertEquals("clouderamanager", postgresData.get("database"));
    assertEquals(REMOTE_ADMIN, postgresData.get("remote_admin"));
    assertEquals(REMOTE_ADMIN_PASSWORD, postgresData.get("remote_admin_pw"));
    assertEquals(DB_HOST, postgresData.get("remote_db_url"));
    assertEquals(DB_PORT, postgresData.get("remote_db_port"));
    assertNotNull(postgresData.get("password"));
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 5 with SecretResponse

use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.

the class DatabaseConfigToDatabaseV4ResponseConverterTest method testConvert.

@Test
public void testConvert() {
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setName(NAME);
    databaseConfig.setResourceCrn(CRN);
    databaseConfig.setDescription(DESCRIPTION);
    databaseConfig.setCreationDate(CREATION_DATE);
    databaseConfig.setConnectionDriver(CONNECTION_DRIVER);
    databaseConfig.setConnectionUserName("userName");
    databaseConfig.setConnectionPassword("password");
    databaseConfig.setConnectionURL(CONNECTION_URL);
    databaseConfig.setDatabaseVendor(DatabaseVendor.MYSQL);
    databaseConfig.setType(TYPE);
    databaseConfig.setEnvironmentId(ENVIRONMENT_CRN);
    databaseConfig.setStatus(ResourceStatus.SERVICE_MANAGED);
    when(stringToSecretResponseConverter.convert(any())).thenReturn(new SecretResponse());
    DatabaseV4Response response = underTest.convert(databaseConfig);
    assertEquals(NAME, response.getName());
    assertEquals(CRN.toString(), response.getCrn());
    assertEquals(DESCRIPTION, response.getDescription());
    assertEquals(CREATION_DATE, response.getCreationDate().longValue());
    assertEquals(CONNECTION_DRIVER, response.getConnectionDriver());
    assertNotNull(response.getConnectionPassword());
    assertNotNull(response.getConnectionUserName());
    assertEquals(CONNECTION_URL, response.getConnectionURL());
    assertEquals(DatabaseVendor.MYSQL.name(), response.getDatabaseEngine());
    assertEquals(TYPE, response.getType());
    assertEquals(ENVIRONMENT_CRN, response.getEnvironmentCrn());
    assertEquals(ResourceStatus.SERVICE_MANAGED, response.getResourceStatus());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) DatabaseV4Response(com.sequenceiq.redbeams.api.endpoint.v4.database.responses.DatabaseV4Response) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)27 Test (org.junit.jupiter.api.Test)14 Test (org.junit.Test)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 HostKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabRequest)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 Secret (com.sequenceiq.cloudbreak.service.secret.domain.Secret)4 HostKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostKeytabResponse)4 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)4 Host (com.sequenceiq.freeipa.client.model.Host)4 KeytabCache (com.sequenceiq.freeipa.entity.KeytabCache)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)3 ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)3 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)3 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)2