Search in sources :

Example 6 with SslConfig

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);
}
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 7 with SslConfig

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);
    }
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 8 with SslConfig

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;
}
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)

Example 9 with SslConfig

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();
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Test(org.junit.jupiter.api.Test)

Example 10 with SslConfig

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();
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.redbeams.domain.stack.DatabaseServer) Test(org.junit.jupiter.api.Test)

Aggregations

SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)16 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 Test (org.junit.jupiter.api.Test)5 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)4 SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)3 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)3 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)3 SslCertificateEntry (com.sequenceiq.redbeams.configuration.SslCertificateEntry)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)1 Objects (java.util.Objects)1 Set (java.util.Set)1