diff --git a/java/google/registry/config/BUILD b/java/google/registry/config/BUILD index 812b0a13a..d9bd096eb 100644 --- a/java/google/registry/config/BUILD +++ b/java/google/registry/config/BUILD @@ -23,6 +23,5 @@ java_library( "@javax_inject", "@joda_time", "@org_joda_money", - "@org_yaml_snakeyaml", ], ) diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index 91500a4ee..f4515107e 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -16,9 +16,11 @@ package google.registry.config; import static com.google.common.base.Suppliers.memoize; import static google.registry.config.ConfigUtils.makeUrl; +import static google.registry.util.ResourceUtils.readResourceUtf8; import static java.lang.annotation.RetentionPolicy.RUNTIME; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Ascii; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; @@ -29,6 +31,7 @@ import dagger.Provides; import google.registry.util.RandomStringGenerator; import google.registry.util.StringGenerator; import google.registry.util.TaskQueueUtils; +import google.registry.util.YamlUtils; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.net.URI; @@ -56,6 +59,10 @@ import org.joda.time.Duration; */ public final class RegistryConfig { + private static final String ENVIRONMENT_CONFIG_FORMAT = "files/nomulus-config-%s.yaml"; + private static final String YAML_CONFIG_PROD = + readResourceUtf8(RegistryConfig.class, "files/default-config.yaml"); + /** Dagger qualifier for configuration settings. */ @Qualifier @Retention(RUNTIME) @@ -64,6 +71,22 @@ public final class RegistryConfig { String value() default ""; } + /** + * Loads the {@link RegistryConfigSettings} POJO from the YAML configuration files. + * + *

The {@code default-config.yaml} file in this directory is loaded first, and a fatal error is + * thrown if it cannot be found or if there is an error parsing it. Separately, the + * environment-specific config file named {@code nomulus-config-ENVIRONMENT.yaml} is also loaded + * and those values merged into the POJO. + */ + static RegistryConfigSettings getConfigSettings() { + String configFilePath = + String.format( + ENVIRONMENT_CONFIG_FORMAT, Ascii.toLowerCase(RegistryEnvironment.get().name())); + String customYaml = readResourceUtf8(RegistryConfig.class, configFilePath); + return YamlUtils.getConfigSettings(YAML_CONFIG_PROD, customYaml, RegistryConfigSettings.class); + } + /** Dagger module for providing configuration settings. */ @Module public static final class ConfigModule { @@ -1514,7 +1537,7 @@ public final class RegistryConfig { */ @VisibleForTesting public static final Supplier CONFIG_SETTINGS = - memoize(YamlUtils::getConfigSettings); + memoize(RegistryConfig::getConfigSettings); private static String formatComments(String text) { return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text).stream() diff --git a/java/google/registry/proxy/ProxyConfig.java b/java/google/registry/proxy/ProxyConfig.java index c23f3342b..f4fa9bd12 100644 --- a/java/google/registry/proxy/ProxyConfig.java +++ b/java/google/registry/proxy/ProxyConfig.java @@ -14,8 +14,8 @@ package google.registry.proxy; -import static google.registry.config.YamlUtils.getConfigSettings; import static google.registry.util.ResourceUtils.readResourceUtf8; +import static google.registry.util.YamlUtils.getConfigSettings; import com.google.common.base.Ascii; import java.util.List; diff --git a/java/google/registry/util/BUILD b/java/google/registry/util/BUILD index 9c01dae4e..1ceefbe53 100644 --- a/java/google/registry/util/BUILD +++ b/java/google/registry/util/BUILD @@ -21,5 +21,6 @@ java_library( "@com_ibm_icu_icu4j", "@javax_inject", "@joda_time", + "@org_yaml_snakeyaml", ], ) diff --git a/java/google/registry/config/YamlUtils.java b/java/google/registry/util/YamlUtils.java similarity index 80% rename from java/google/registry/config/YamlUtils.java rename to java/google/registry/util/YamlUtils.java index a933c22c3..1fdb18901 100644 --- a/java/google/registry/config/YamlUtils.java +++ b/java/google/registry/util/YamlUtils.java @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.config; +package google.registry.util; -import static com.google.common.base.Ascii.toLowerCase; -import static google.registry.util.ResourceUtils.readResourceUtf8; import com.google.common.flogger.FluentLogger; import java.util.Map; @@ -35,10 +33,6 @@ public final class YamlUtils { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private static final String ENVIRONMENT_CONFIG_FORMAT = "files/nomulus-config-%s.yaml"; - private static final String YAML_CONFIG_PROD = - readResourceUtf8(RegistryConfig.class, "files/default-config.yaml"); - /** * Loads the POJO of type {@code T} from merged YAML configuration files. * @@ -57,21 +51,6 @@ public final class YamlUtils { } } - /** - * Loads the {@link RegistryConfigSettings} POJO from the YAML configuration files. - * - *

The {@code default-config.yaml} file in this directory is loaded first, and a fatal error is - * thrown if it cannot be found or if there is an error parsing it. Separately, the - * environment-specific config file named {@code nomulus-config-ENVIRONMENT.yaml} is also loaded - * and those values merged into the POJO. - */ - static RegistryConfigSettings getConfigSettings() { - String configFilePath = - String.format(ENVIRONMENT_CONFIG_FORMAT, toLowerCase(RegistryEnvironment.get().name())); - String customYaml = readResourceUtf8(RegistryConfig.class, configFilePath); - return getConfigSettings(YAML_CONFIG_PROD, customYaml, RegistryConfigSettings.class); - } - /** * Recursively merges two YAML documents together. * diff --git a/javatests/google/registry/config/YamlUtilsTest.java b/javatests/google/registry/util/YamlUtilsTest.java similarity index 96% rename from javatests/google/registry/config/YamlUtilsTest.java rename to javatests/google/registry/util/YamlUtilsTest.java index 51f4e5960..aa789db47 100644 --- a/javatests/google/registry/config/YamlUtilsTest.java +++ b/javatests/google/registry/util/YamlUtilsTest.java @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.config; +package google.registry.util; import static com.google.common.truth.Truth.assertThat; -import static google.registry.config.YamlUtils.mergeYaml; +import static google.registry.util.YamlUtils.mergeYaml; import com.google.common.base.Joiner; import org.junit.Test;