use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeBringYourOwn.
@Test
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeBringYourOwn() {
DatabaseServerConfig server = new DatabaseServerConfig();
server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
DBStack dbStack = new DBStack();
SslConfig sslConfig = new SslConfig();
sslConfig.setSslCertificateType(SslCertificateType.BRING_YOUR_OWN);
dbStack.setSslConfig(sslConfig);
server.setDbStack(dbStack);
DatabaseServerV4Response response = converter.convert(server);
assertThat(response).isNotNull();
SslConfigV4Response sslConfigV4Response = response.getSslConfig();
assertThat(sslConfigV4Response).isNotNull();
assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.ENABLED);
assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.BRING_YOUR_OWN);
}
use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.
the class DatabaseServerSslCertificateSyncService method syncSslCertificateIfNeeded.
public void syncSslCertificateIfNeeded(CloudContext cloudContext, CloudCredential cloudCredential, DBStack dbStack, DatabaseStack databaseStack) throws Exception {
SslConfig sslConfig = dbStack.getSslConfig();
String cloudPlatform = dbStack.getCloudPlatform();
if (sslConfig != null && SslCertificateType.CLOUD_PROVIDER_OWNED.equals(sslConfig.getSslCertificateType()) && CloudPlatform.AWS.name().equals(cloudPlatform)) {
CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
CloudDatabaseServerSslCertificate activeSslRootCertificate = connector.resources().getDatabaseServerActiveSslRootCertificate(ac, databaseStack);
if (activeSslRootCertificate == null) {
LOGGER.warn("Database server or its SSL certificate does not exist in cloud platform \"{}\" for {}. Skipping synchronization.", cloudPlatform, cloudContext);
} else {
syncSslCertificateAws(cloudContext, dbStack, activeSslRootCertificate);
}
} else {
LOGGER.info("SSL not enabled or unsupported cloud platform \"{}\": SslConfig={}. Skipping SSL certificate synchronization for database stack {}", cloudPlatform, sslConfig, cloudContext);
}
}
use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.
the class DatabaseServerConfigToDatabaseServerV4ResponseConverter method convert.
public DatabaseServerV4Response convert(DatabaseServerConfig source) {
DatabaseServerV4Response response = new DatabaseServerV4Response();
response.setId(source.getId());
response.setCrn(source.getResourceCrn().toString());
response.setName(source.getName());
response.setDescription(source.getDescription());
response.setHost(source.getHost());
response.setPort(source.getPort());
response.setDatabaseVendor(source.getDatabaseVendor().databaseType());
response.setDatabaseVendorDisplayName(source.getDatabaseVendor().displayName());
response.setConnectionDriver(source.getConnectionDriver());
response.setConnectionUserName(stringToSecretResponseConverter.convert(source.getConnectionUserNameSecret()));
response.setConnectionPassword(stringToSecretResponseConverter.convert(source.getConnectionPasswordSecret()));
response.setCreationDate(source.getCreationDate());
response.setEnvironmentCrn(source.getEnvironmentId());
response.setClusterCrn(source.getClusterCrn());
response.setResourceStatus(source.getResourceStatus());
if (source.getDbStack().isPresent()) {
DBStack dbStack = source.getDbStack().get();
response.setStatus(dbStack.getStatus());
response.setStatusReason(dbStack.getStatusReason());
if (dbStack.getSslConfig() != null) {
SslConfig sslConfig = dbStack.getSslConfig();
SslConfigV4Response sslConfigV4Response = new SslConfigV4Response();
sslConfigV4Response.setSslCertificates(sslConfig.getSslCertificates());
sslConfigV4Response.setSslCertificateType(sslConfig.getSslCertificateType());
sslConfigV4Response.setSslMode(NONE.equals(sslConfig.getSslCertificateType()) ? DISABLED : ENABLED);
String cloudPlatform = dbStack.getCloudPlatform();
String region = dbStack.getRegion();
// TODO Add SslConfig.sslCertificateMaxVersion that is kept up-to-date (mostly for GCP), use getMaxVersionByPlatform() as fallback
sslConfigV4Response.setSslCertificateHighestAvailableVersion(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(cloudPlatform, region));
sslConfigV4Response.setSslCertificateActiveVersion(Optional.ofNullable(sslConfig.getSslCertificateActiveVersion()).orElse(databaseServerSslCertificateConfig.getLegacyMaxVersionByCloudPlatformAndRegion(cloudPlatform, region)));
sslConfigV4Response.setSslCertificateActiveCloudProviderIdentifier(Optional.ofNullable(sslConfig.getSslCertificateActiveCloudProviderIdentifier()).orElse(databaseServerSslCertificateConfig.getLegacyCloudProviderIdentifierByCloudPlatformAndRegion(cloudPlatform, region)));
response.setSslConfig(sslConfigV4Response);
}
} else if (source.getHost() != null && source.getPort() != null) {
response.setStatus(Status.AVAILABLE);
} else {
response.setStatus(Status.UNKNOWN);
}
if (response.getSslConfig() == null) {
response.setSslConfig(new SslConfigV4Response());
}
return response;
}
use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionWithSslCertificateNone.
@Test
void testConversionWithSslCertificateNone() {
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
dbStack.setDatabaseServer(server);
dbStack.setSslConfig(new SslConfig());
DatabaseStack convertedStack = underTest.convert(dbStack);
assertThat(convertedStack.getDatabaseServer().isUseSslEnforcement()).isFalse();
}
use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverterTest method testConversionWithSslCertificateBringYourOwn.
@Test
void testConversionWithSslCertificateBringYourOwn() {
DatabaseServer server = new DatabaseServer();
server.setDatabaseVendor(DatabaseVendor.POSTGRES);
dbStack.setDatabaseServer(server);
SslConfig sslConfig = new SslConfig();
sslConfig.setSslCertificateType(SslCertificateType.BRING_YOUR_OWN);
dbStack.setSslConfig(sslConfig);
DatabaseStack convertedStack = underTest.convert(dbStack);
assertThat(convertedStack.getDatabaseServer().isUseSslEnforcement()).isTrue();
}
Aggregations