diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index 16932384091..2e523790586 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -384,27 +384,6 @@ public static String provideCloudSqlJdbcUrl(RegistryConfigSettings config) { return config.cloudSql.jdbcUrl; } - @Provides - @Config("cloudSqlInstanceConnectionName") - public static String provideCloudSqlInstanceConnectionName(RegistryConfigSettings config) { - return config.cloudSql.instanceConnectionName; - } - - @Provides - @Config("cloudSqlReplicaInstanceConnectionName") - public static Optional provideCloudSqlReplicaInstanceConnectionName( - RegistryConfigSettings config) { - return Optional.ofNullable(config.cloudSql.replicaInstanceConnectionName); - } - - @Provides - @Config("cloudSqlDbInstanceName") - public static String provideCloudSqlDbInstance(RegistryConfigSettings config) { - // Format of instanceConnectionName: project-id:region:instance-name - int lastColonIndex = config.cloudSql.instanceConnectionName.lastIndexOf(':'); - return config.cloudSql.instanceConnectionName.substring(lastColonIndex + 1); - } - @Provides @Config("cloudDnsRootUrl") public static Optional getCloudDnsRootUrl(RegistryConfigSettings config) { diff --git a/core/src/main/java/google/registry/config/RegistryConfigSettings.java b/core/src/main/java/google/registry/config/RegistryConfigSettings.java index 46f273ea517..dde25190c7e 100644 --- a/core/src/main/java/google/registry/config/RegistryConfigSettings.java +++ b/core/src/main/java/google/registry/config/RegistryConfigSettings.java @@ -133,7 +133,7 @@ public static class Hibernate { /** Configuration for Cloud SQL. */ public static class CloudSql { public String jdbcUrl; - // TODO(05012021): remove username field after it is removed from all yaml files. + // TODO(05012021): remove 3 fields below after they are removed from all yaml files. public String username; public String instanceConnectionName; public String replicaInstanceConnectionName; diff --git a/core/src/main/java/google/registry/keyring/KeyringModule.java b/core/src/main/java/google/registry/keyring/KeyringModule.java index 089af7802bf..a6e1b57529b 100644 --- a/core/src/main/java/google/registry/keyring/KeyringModule.java +++ b/core/src/main/java/google/registry/keyring/KeyringModule.java @@ -21,6 +21,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.keyring.api.Keyring; import java.util.Map; +import java.util.Optional; import javax.inject.Singleton; /** Dagger module for {@link Keyring} */ @@ -38,4 +39,25 @@ public static Keyring provideKeyring( keyrings.keySet()); return keyrings.get(activeKeyring); } + + @Provides + @Config("cloudSqlInstanceConnectionName") + public static String provideCloudSqlInstanceConnectionName(Keyring keyring) { + return keyring.getSqlPrimaryConnectionName(); + } + + @Provides + @Config("cloudSqlReplicaInstanceConnectionName") + public static Optional provideCloudSqlReplicaInstanceConnectionName(Keyring keyring) { + return Optional.ofNullable(keyring.getSqlReplicaConnectionName()); + } + + @Provides + @Config("cloudSqlDbInstanceName") + public static String provideCloudSqlDbInstance( + @Config("cloudSqlInstanceConnectionName") String instanceConnectionName) { + // Format of instanceConnectionName: project-id:region:instance-name + int lastColonIndex = instanceConnectionName.lastIndexOf(':'); + return instanceConnectionName.substring(lastColonIndex + 1); + } } diff --git a/core/src/main/java/google/registry/persistence/PersistenceModule.java b/core/src/main/java/google/registry/persistence/PersistenceModule.java index f292eac55a9..37fefa39fe0 100644 --- a/core/src/main/java/google/registry/persistence/PersistenceModule.java +++ b/core/src/main/java/google/registry/persistence/PersistenceModule.java @@ -34,10 +34,13 @@ import dagger.Module; import dagger.Provides; import google.registry.config.RegistryConfig.Config; +import google.registry.keyring.KeyringModule; +import google.registry.keyring.api.DummyKeyringModule; import google.registry.persistence.transaction.CloudSqlCredentialSupplier; import google.registry.persistence.transaction.JpaTransactionManager; import google.registry.persistence.transaction.JpaTransactionManagerImpl; import google.registry.persistence.transaction.TransactionManager; +import google.registry.privileges.secretmanager.SecretManagerModule; import google.registry.privileges.secretmanager.SqlCredential; import google.registry.privileges.secretmanager.SqlCredentialStore; import google.registry.privileges.secretmanager.SqlUser; @@ -63,7 +66,7 @@ import org.hibernate.cfg.Environment; /** Dagger module class for the persistence layer. */ -@Module +@Module(includes = {KeyringModule.class, SecretManagerModule.class, DummyKeyringModule.class}) public abstract class PersistenceModule { // This name must be the same as the one defined in persistence.xml.