Search in sources :

Example 1 with SslConfigV4Response

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;
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)

Example 2 with SslConfigV4Response

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();
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with SslConfigV4Response

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);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with SslConfigV4Response

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);
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SslConfigV4Response

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;
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)

Aggregations

SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)14 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)11 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 DatabaseServerSslConfig (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseServerSslConfig)4 StackDatabaseServerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.StackDatabaseServerResponse)4 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)4 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)3 Date (java.util.Date)2 HashSet (java.util.HashSet)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1