Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens committed Nov 1, 2022
1 parent d86f1ab commit c9384ed
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.airbyte.config.persistence.DatabaseConfigPersistence;
import io.airbyte.config.persistence.SecretsRepositoryReader;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.config.persistence.split_secrets.SecretPersistence;
import io.airbyte.config.persistence.split_secrets.SecretsHydrator;
import io.airbyte.db.Database;
Expand Down Expand Up @@ -195,11 +194,7 @@ private static Database getConfigDatabase(final DSLContext dslContext) throws IO
}

private static ConfigPersistence getConfigPersistence(final Database configDatabase) throws IOException {
final JsonSecretsProcessor jsonSecretsProcessor = JsonSecretsProcessor.builder()
.copySecrets(true)
.build();

return DatabaseConfigPersistence.createWithValidation(configDatabase, jsonSecretsProcessor);
return DatabaseConfigPersistence.createWithValidation(configDatabase);
}

private static DefinitionsProvider getLocalDefinitionsProvider() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.airbyte.config.persistence.DatabaseConfigPersistence;
import io.airbyte.config.persistence.SecretsRepositoryReader;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.config.persistence.split_secrets.LocalTestingSecretPersistence;
import io.airbyte.config.persistence.split_secrets.RealSecretsHydrator;
import io.airbyte.config.persistence.split_secrets.SecretPersistence;
Expand Down Expand Up @@ -173,10 +172,6 @@ void testBootloaderAppRunSecretMigration() throws Exception {

val mockedFeatureFlags = mock(FeatureFlags.class);

final JsonSecretsProcessor jsonSecretsProcessor = JsonSecretsProcessor.builder()
.copySecrets(true)
.build();

try (val configsDslContext = DSLContextFactory.create(configsDataSource, SQLDialect.POSTGRES);
val jobsDslContext = DSLContextFactory.create(configsDataSource, SQLDialect.POSTGRES)) {

Expand All @@ -186,7 +181,7 @@ void testBootloaderAppRunSecretMigration() throws Exception {
val configDatabase = new ConfigsDatabaseTestProvider(configsDslContext, configsFlyway).create(false);
val jobDatabase = new JobsDatabaseTestProvider(jobsDslContext, jobsFlyway).create(false);

val configPersistence = new DatabaseConfigPersistence(configDatabase, jsonSecretsProcessor);
val configPersistence = new DatabaseConfigPersistence(configDatabase);
val configRepository = new ConfigRepository(configPersistence, configDatabase);
val jobsPersistence = new DefaultJobPersistence(jobDatabase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import io.airbyte.config.State;
import io.airbyte.config.WorkspaceServiceAccount;
import io.airbyte.config.helpers.ScheduleHelpers;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.db.Database;
import io.airbyte.db.ExceptionWrappingDatabase;
import io.airbyte.db.instance.configs.jooq.generated.enums.ActorType;
Expand Down Expand Up @@ -85,27 +84,22 @@
public class DatabaseConfigPersistence implements ConfigPersistence {

private final ExceptionWrappingDatabase database;
private final JsonSecretsProcessor jsonSecretsProcessor;
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseConfigPersistence.class);
private static final String UNKNOWN_CONFIG_TYPE = "Unknown Config Type ";
private static final String NOT_FOUND = " not found";

/**
* Entrypoint into DatabaseConfigPersistence. Except in testing, we should never be using it without
* it being decorated with validation classes.
*
* @param database - database where configs are stored
* @param jsonSecretsProcessor - for filtering secrets in export
* @return database config persistence wrapped in validation decorators
*/
public static ConfigPersistence createWithValidation(final Database database,
final JsonSecretsProcessor jsonSecretsProcessor) {
return new ValidatingConfigPersistence(new DatabaseConfigPersistence(database, jsonSecretsProcessor));
public static ConfigPersistence createWithValidation(final Database database) {
return new ValidatingConfigPersistence(new DatabaseConfigPersistence(database));
}

public DatabaseConfigPersistence(final Database database, final JsonSecretsProcessor jsonSecretsProcessor) {
public DatabaseConfigPersistence(final Database database) {
this.database = new ExceptionWrappingDatabase(database);
this.jsonSecretsProcessor = jsonSecretsProcessor;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private DestinationConnection hydrateDestinationPartialConfig(final DestinationC
return Jsons.clone(sourceWithPartialConfig).withConfiguration(hydratedConfig);
}

@SuppressWarnings("unused")
private void hydrateValuesIfKeyPresent(final String key, final Map<String, Stream<JsonNode>> dump) {
if (dump.containsKey(key)) {
final Stream<JsonNode> augmentedValue = dump.get(key).map(secretsHydrator::hydrate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void writeDestinationConnection(final DestinationConnection destination,
* @param spec connector specification
* @return partial config
*/
@SuppressWarnings("unused")
private JsonNode statefulSplitSecrets(final UUID workspaceId, final JsonNode fullConfig, final ConnectorSpecification spec) {
return splitSecretConfig(workspaceId, fullConfig, spec, longLivedSecretPersistence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

import io.airbyte.commons.json.Jsons;
Expand All @@ -32,7 +31,6 @@
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.persistence.ConfigRepository.DestinationAndDefinition;
import io.airbyte.config.persistence.ConfigRepository.SourceAndDefinition;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.db.Database;
import io.airbyte.db.factory.DSLContextFactory;
import io.airbyte.db.factory.FlywayFactory;
Expand Down Expand Up @@ -78,7 +76,6 @@ class ConfigRepositoryE2EReadWriteTest {
private Database database;
private ConfigRepository configRepository;
private DatabaseConfigPersistence configPersistence;
private JsonSecretsProcessor jsonSecretsProcessor;
private Flyway flyway;
private final static String DOCKER_IMAGE_TAG = "1.2.0";
private final static String CONFIG_HASH = "ConfigHash";
Expand All @@ -96,11 +93,10 @@ public static void dbSetup() {
void setup() throws IOException, JsonValidationException, SQLException, DatabaseInitializationException, InterruptedException {
dataSource = DatabaseConnectionHelper.createDataSource(container);
dslContext = DSLContextFactory.create(dataSource, SQLDialect.POSTGRES);
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceLoadDataTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
flyway = FlywayFactory.create(dataSource, ConfigRepositoryE2EReadWriteTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(false);
jsonSecretsProcessor = mock(JsonSecretsProcessor.class);
configPersistence = spy(new DatabaseConfigPersistence(database, jsonSecretsProcessor));
configPersistence = spy(new DatabaseConfigPersistence(database));
configRepository = spy(new ConfigRepository(configPersistence, database));
final ConfigsDatabaseMigrator configsDatabaseMigrator =
new ConfigsDatabaseMigrator(database, flyway);
Expand Down Expand Up @@ -160,8 +156,8 @@ void testWorkspaceCountConnectionsDeprecated() throws IOException {

@Test
void testFetchActorsUsingDefinition() throws IOException {
UUID destinationDefinitionId = MockData.publicDestinationDefinition().getDestinationDefinitionId();
UUID sourceDefinitionId = MockData.publicSourceDefinition().getSourceDefinitionId();
final UUID destinationDefinitionId = MockData.publicDestinationDefinition().getDestinationDefinitionId();
final UUID sourceDefinitionId = MockData.publicSourceDefinition().getSourceDefinitionId();
final List<DestinationConnection> destinationConnections = configRepository.listDestinationsForDefinition(
destinationDefinitionId);
final List<SourceConnection> sourceConnections = configRepository.listSourcesForDefinition(
Expand Down Expand Up @@ -315,7 +311,7 @@ void testListPublicSourceDefinitions() throws IOException {

@Test
void testListWorkspaceSources() throws IOException {
UUID workspaceId = MockData.standardWorkspaces().get(1).getWorkspaceId();
final UUID workspaceId = MockData.standardWorkspaces().get(1).getWorkspaceId();
final List<SourceConnection> expectedSources = MockData.sourceConnections().stream()
.filter(source -> source.getWorkspaceId().equals(workspaceId)).collect(Collectors.toList());
final List<SourceConnection> sources = configRepository.listWorkspaceSourceConnection(workspaceId);
Expand All @@ -324,7 +320,7 @@ void testListWorkspaceSources() throws IOException {

@Test
void testListWorkspaceDestinations() throws IOException {
UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final UUID workspaceId = MockData.standardWorkspaces().get(0).getWorkspaceId();
final List<DestinationConnection> expectedDestinations = MockData.destinationConnections().stream()
.filter(destination -> destination.getWorkspaceId().equals(workspaceId)).collect(Collectors.toList());
final List<DestinationConnection> destinations = configRepository.listWorkspaceDestinationConnection(workspaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class DatabaseConfigPersistenceE2EReadWriteTest extends BaseDatabaseConfigPersis
void setup() throws Exception {
dataSource = DatabaseConnectionHelper.createDataSource(container);
dslContext = DSLContextFactory.create(dataSource, SQLDialect.POSTGRES);
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceLoadDataTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceE2EReadWriteTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(false);
configPersistence = spy(new DatabaseConfigPersistence(database, jsonSecretsProcessor));
configPersistence = spy(new DatabaseConfigPersistence(database));
final ConfigsDatabaseMigrator configsDatabaseMigrator =
new ConfigsDatabaseMigrator(database, flyway);
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setup() throws Exception {
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(false);
configPersistence = spy(new DatabaseConfigPersistence(database, jsonSecretsProcessor));
configPersistence = spy(new DatabaseConfigPersistence(database));
final ConfigsDatabaseMigrator configsDatabaseMigrator =
new ConfigsDatabaseMigrator(database, flyway);
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class DatabaseConfigPersistenceUpdateConnectorDefinitionsTest extends BaseDataba
public static void setup() throws Exception {
dataSource = DatabaseConnectionHelper.createDataSource(container);
dslContext = DSLContextFactory.create(dataSource, SQLDialect.POSTGRES);
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceLoadDataTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceUpdateConnectorDefinitionsTest.class.getName(),
ConfigsDatabaseMigrator.DB_IDENTIFIER,
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(false);
configPersistence = new DatabaseConfigPersistence(database, jsonSecretsProcessor);
configPersistence = new DatabaseConfigPersistence(database);
final ConfigsDatabaseMigrator configsDatabaseMigrator =
new ConfigsDatabaseMigrator(database, flyway);
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package io.airbyte.config.persistence;

import static org.mockito.Mockito.mock;

import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.enums.Enums;
import io.airbyte.commons.json.Jsons;
Expand All @@ -18,7 +16,6 @@
import io.airbyte.config.State;
import io.airbyte.config.StateType;
import io.airbyte.config.StateWrapper;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.db.factory.DSLContextFactory;
import io.airbyte.db.factory.FlywayFactory;
import io.airbyte.db.init.DatabaseInitializationException;
Expand Down Expand Up @@ -530,7 +527,7 @@ void testStatePersistenceLegacyWriteConsistency() throws IOException {
void beforeEach() throws DatabaseInitializationException, IOException, JsonValidationException {
dataSource = DatabaseConnectionHelper.createDataSource(container);
dslContext = DSLContextFactory.create(dataSource, SQLDialect.POSTGRES);
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceLoadDataTest.class.getName(),
flyway = FlywayFactory.create(dataSource, StatePersistenceTest.class.getName(),
ConfigsDatabaseMigrator.DB_IDENTIFIER, ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(true);
setupTestData();
Expand All @@ -547,9 +544,7 @@ void afterEach() {
}

private void setupTestData() throws JsonValidationException, IOException {
configRepository = new ConfigRepository(
new DatabaseConfigPersistence(database, mock(JsonSecretsProcessor.class)),
database);
configRepository = new ConfigRepository(new DatabaseConfigPersistence(database), database);

final StandardWorkspace workspace = MockData.standardWorkspaces().get(0);
final StandardSourceDefinition sourceDefinition = MockData.publicSourceDefinition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StreamResetPersistenceTest extends BaseDatabaseConfigPersistenceTest {
public void setup() throws Exception {
dataSource = DatabaseConnectionHelper.createDataSource(container);
dslContext = DSLContextFactory.create(dataSource, SQLDialect.POSTGRES);
flyway = FlywayFactory.create(dataSource, DatabaseConfigPersistenceLoadDataTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
flyway = FlywayFactory.create(dataSource, StreamResetPersistenceTest.class.getName(), ConfigsDatabaseMigrator.DB_IDENTIFIER,
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
database = new ConfigsDatabaseTestProvider(dslContext, flyway).create(false);
streamResetPersistence = spy(new StreamResetPersistence(database));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Flyway configFlyway(@Named("config") final FlywayConfigurationProperties
@Singleton
public ConfigPersistence configPersistence(@Named("configDatabase") final Database configDatabase,
final JsonSecretsProcessor jsonSecretsProcessor) {
return DatabaseConfigPersistence.createWithValidation(configDatabase, jsonSecretsProcessor);
return DatabaseConfigPersistence.createWithValidation(configDatabase);
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.airbyte.config.persistence.SecretsRepositoryReader;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.config.persistence.StreamResetPersistence;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.config.persistence.split_secrets.SecretPersistence;
import io.airbyte.config.persistence.split_secrets.SecretsHydrator;
import io.airbyte.db.Database;
Expand Down Expand Up @@ -190,10 +189,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,

LOGGER.info("Creating config repository...");
final Database configsDatabase = new Database(configsDslContext);
final JsonSecretsProcessor jsonSecretsProcessor = JsonSecretsProcessor.builder()
.copySecrets(false)
.build();
final ConfigPersistence configPersistence = DatabaseConfigPersistence.createWithValidation(configsDatabase, jsonSecretsProcessor);
final ConfigPersistence configPersistence = DatabaseConfigPersistence.createWithValidation(configsDatabase);
final SecretsHydrator secretsHydrator = SecretPersistence.getSecretsHydrator(configsDslContext, configs);
final Optional<SecretPersistence> secretPersistence = SecretPersistence.getLongLived(configsDslContext, configs);
final Optional<SecretPersistence> ephemeralSecretPersistence = SecretPersistence.getEphemeral(configsDslContext, configs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Flyway jobsFlyway(@Named("jobs") final FlywayConfigurationProperties jobs
@Requires(env = WorkerMode.CONTROL_PLANE)
public ConfigPersistence configPersistence(@Named("configDatabase") final Database configDatabase,
final JsonSecretsProcessor jsonSecretsProcessor) {
return DatabaseConfigPersistence.createWithValidation(configDatabase, jsonSecretsProcessor);
return DatabaseConfigPersistence.createWithValidation(configDatabase);
}

@Singleton
Expand Down

0 comments on commit c9384ed

Please sign in to comment.