Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract the secret's json path from a config schema #11823

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import io.airbyte.commons.features.FeatureFlags;
import io.airbyte.commons.resources.MoreResources;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.ConfigSchema;
import io.airbyte.config.Configs;
import io.airbyte.config.EnvConfigs;
import io.airbyte.config.SourceConnection;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.init.YamlSeedConfigPersistence;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.config.persistence.DatabaseConfigPersistence;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.airbyte.config.persistence.split_secrets.SecretPersistence;
import io.airbyte.db.Database;
import io.airbyte.db.instance.DatabaseMigrator;
import io.airbyte.db.instance.configs.ConfigsDatabaseInstance;
Expand All @@ -32,6 +35,7 @@
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.slf4j.Logger;
Expand All @@ -57,11 +61,13 @@ public class BootloaderApp {
private final Configs configs;
private Runnable postLoadExecution;
private final FeatureFlags featureFlags;
private ConfigPersistence configPersistence;

@VisibleForTesting
public BootloaderApp(final Configs configs, final FeatureFlags featureFlags) {
public BootloaderApp(final Configs configs, final FeatureFlags featureFlags, final ConfigPersistence configPersistence) {
this.configs = configs;
this.featureFlags = featureFlags;
this.configPersistence = configPersistence;
}

/**
Expand All @@ -72,10 +78,14 @@ public BootloaderApp(final Configs configs, final FeatureFlags featureFlags) {
* @param configs
* @param postLoadExecution
*/
public BootloaderApp(final Configs configs, final Runnable postLoadExecution, final FeatureFlags featureFlags) {
public BootloaderApp(final Configs configs,
final Runnable postLoadExecution,
final FeatureFlags featureFlags,
final ConfigPersistence configPersistence) {
this.configs = configs;
this.postLoadExecution = postLoadExecution;
this.featureFlags = featureFlags;
this.configPersistence = configPersistence;
}

public BootloaderApp() {
Expand All @@ -90,7 +100,7 @@ public BootloaderApp() {
.maskSecrets(!featureFlags.exposeSecretsInExport())
.copySecrets(true)
.build();
final ConfigPersistence configPersistence =
configPersistence =
DatabaseConfigPersistence.createWithValidation(configDatabase, jsonSecretsProcessor);
configPersistence.loadData(YamlSeedConfigPersistence.getDefault());
LOGGER.info("Loaded seed data..");
Expand Down Expand Up @@ -242,4 +252,18 @@ private static void cleanupZombies(final JobPersistence jobPersistence) throws I
}
}

/**
* Migrate secret from plain text to a secret store.
*/
private void migrateSecret() throws IOException, JsonValidationException {
final SecretPersistence secretPersistence = SecretPersistence.getEphemeral(configs).orElseThrow(() -> new IllegalStateException("Migration "
+ "without setting a secret store"));

final List<SourceConnection> sourceConnections = configPersistence.listConfigs(ConfigSchema.SOURCE_CONNECTION, SourceConnection.class);

sourceConnections.forEach(sourceConnection -> {
sourceConnection.getConfiguration();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.airbyte.commons.features.FeatureFlags;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.db.instance.configs.ConfigsDatabaseInstance;
import io.airbyte.db.instance.configs.ConfigsDatabaseMigrator;
import io.airbyte.db.instance.jobs.JobsDatabaseInstance;
Expand Down Expand Up @@ -57,14 +58,16 @@ void testBootloaderAppBlankDb() throws Exception {
val mockedFeatureFlags = mock(FeatureFlags.class);
when(mockedFeatureFlags.usesNewScheduler()).thenReturn(false);

val mConfigPersistence = mock(ConfigPersistence.class);

// Although we are able to inject mocked configs into the Bootloader, a particular migration in the
// configs database
// requires the env var to be set. Flyway prevents injection, so we dynamically set this instead.
environmentVariables.set("DATABASE_USER", "docker");
environmentVariables.set("DATABASE_PASSWORD", "docker");
environmentVariables.set("DATABASE_URL", container.getJdbcUrl());

val bootloader = new BootloaderApp(mockedConfigs, mockedFeatureFlags);
val bootloader = new BootloaderApp(mockedConfigs, mockedFeatureFlags, mConfigPersistence);
bootloader.load();

val jobDatabase = new JobsDatabaseInstance(
Expand Down Expand Up @@ -134,7 +137,9 @@ void testPostLoadExecutionExecutes() throws Exception {
val mockedFeatureFlags = mock(FeatureFlags.class);
when(mockedFeatureFlags.usesNewScheduler()).thenReturn(false);

new BootloaderApp(mockedConfigs, () -> testTriggered.set(true), mockedFeatureFlags).load();
val mConfigPersistence = mock(ConfigPersistence.class);

new BootloaderApp(mockedConfigs, () -> testTriggered.set(true), mockedFeatureFlags, mConfigPersistence).load();

assertTrue(testTriggered.get());
}
Expand Down
Loading