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);
}
}
}
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());
}
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);
}
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"));
}
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());
}
Aggregations