use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response in project cloudbreak by hortonworks.
the class RedbeamsDbServerConfigurerTest method createDatabaseServerV4ResponseWithSsl.
private DatabaseServerV4Response createDatabaseServerV4ResponseWithSsl(String dbHost, SslMode sslMode) {
SslConfigV4Response sslConfig = new SslConfigV4Response();
sslConfig.setSslMode(sslMode);
DatabaseServerV4Response response = createDatabaseServerV4Response(dbHost);
response.setSslConfig(sslConfig);
return response;
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response in project cloudbreak by hortonworks.
the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterSdxAndRdsConfiguredWithoutSSL.
@Test
void getRelatedSslCertsWhenTheClusterSdxAndRdsConfiguredWithoutSSL() {
String dbServerCrn = "adbservercrn";
Cluster cluster = TestUtil.cluster();
cluster.setDatabaseServerCrn(dbServerCrn);
Stack stack = cluster.getStack();
stack.setCluster(cluster);
stack.setType(StackType.DATALAKE);
when(dbServerConfigurer.isRemoteDatabaseNeeded(cluster)).thenReturn(Boolean.TRUE);
DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
databaseServerV4Response.setSslConfig(new SslConfigV4Response());
when(dbServerConfigurer.getDatabaseServer(dbServerCrn)).thenReturn(databaseServerV4Response);
Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
assertThat(actual).isEmpty();
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response in project cloudbreak by hortonworks.
the class RedbeamsDbCertificateProviderTest method getRelatedSslCertsWhenTheClusterDistroXAndRdsConfiguredButRelatedSdxRdsHasNoSSLConfigured.
@Test
void getRelatedSslCertsWhenTheClusterDistroXAndRdsConfiguredButRelatedSdxRdsHasNoSSLConfigured() {
String dbServerCrn = "dbservercrn-A";
String dbServerCrnB = "dbservercrn-B";
String certificateA = "certificate-A";
Cluster sdxCluster = TestUtil.cluster();
sdxCluster.setId(2L);
sdxCluster.setDatabaseServerCrn(dbServerCrnB);
Stack sdxStack = sdxCluster.getStack();
sdxStack.setCluster(sdxCluster);
sdxStack.setType(StackType.DATALAKE);
sdxStack.setId(2L);
Cluster cluster = TestUtil.cluster();
cluster.setDatabaseServerCrn(dbServerCrn);
Stack stack = cluster.getStack();
stack.setCluster(cluster);
stack.setType(StackType.WORKLOAD);
when(datalakeService.getDatalakeStackByDatahubStack(any())).thenReturn(Optional.of(sdxStack));
when(dbServerConfigurer.isRemoteDatabaseNeeded(any())).thenReturn(Boolean.TRUE);
DatabaseServerV4Response databaseServerV4Response = new DatabaseServerV4Response();
databaseServerV4Response.setSslConfig(getSslConfigV4ResponseWithCertificate(Set.of(certificateA)));
when(dbServerConfigurer.getDatabaseServer(dbServerCrn)).thenReturn(databaseServerV4Response);
DatabaseServerV4Response databaseServerV4ResponseB = new DatabaseServerV4Response();
SslConfigV4Response sslConfig = new SslConfigV4Response();
sslConfig.setSslMode(SslMode.DISABLED);
databaseServerV4ResponseB.setSslConfig(sslConfig);
when(dbServerConfigurer.getDatabaseServer(dbServerCrnB)).thenReturn(databaseServerV4ResponseB);
Set<String> actual = underTest.getRelatedSslCerts(stack, cluster);
assertThat(actual).isNotEmpty();
assertThat(actual).contains(certificateA);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response 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.api.endpoint.v4.databaseserver.responses.SslConfigV4Response 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;
}
Aggregations