diff --git a/docs/configuration.md b/docs/configuration.md index 2750a218d..0d4b08966 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -58,21 +58,16 @@ queues, and thus edit those associated XML files. Global configuration is managed through YAML files that are built with and deployed in the app. The full list of config options and their default values -can be found in the `[default-config.yaml][default-config]` file. If you wish to -change any of these values, do not change make changes to this file. Instead, -write a custom configuration file named `nomulus-config.yaml` that overrides -only the options you wish to change, and include it in the `WEB-INF` directory -in each service. - -The existing environments that Nomulus ships with (alpha, sandbox, etc.) come -with placeholder configuration files that are included in the default deployment -build, so if you are using one of these environments, simply make your changes -to that file. For example, to configure the alpha environment, edit -`[env/alpha/common/WEB-INF/nomulus-config.yaml][nomulus-config-alpha]`. +can be found in the [`default-config.yaml`][default-config] file. If you wish to +change any of these values, do not edit this file. Instead, edit the environment +configuration file named +`google/registry/config/files/nomulus-config-ENVIRONMENT.yaml`, overriding only +the options you wish to change. Nomulus ships with blank placeholders for all +standard environments. You will not need to change most of the default settings. Here is the subset of settings that you will need to change for all deployed environments, including -development environments. See `[default-config.yaml][default-config]` for a full +development environments. See [`default-config.yaml`][default-config] for a full description of each option: ```yaml @@ -93,7 +88,7 @@ need to specify more settings. The `nomulus-config-production-sample.yaml` file contains an exhaustive list of all settings to override. From a code perspective, all configuration settings ultimately come through the -`[RegistryConfig][registry-config]` class. This includes a Dagger module called +[`RegistryConfig`][registry-config] class. This includes a Dagger module called `ConfigModule` that provides injectable configuration options. Some legacy configuration options that can be changed in this class include timeout lengths and buffer sizes for various tasks, email addresses and URLs to use for various @@ -145,6 +140,5 @@ above, per-TLD configuration options are stored as data in the running system, and thus do not require code pushes to update. [app-engine-config]: https://cloud.google.com/appengine/docs/java/configuration-files -[default-config]: https://github.com/google/nomulus/blob/master/java/google/registry/config/default-config.yaml -[nomulus-config-alpha]: https://github.com/google/nomulus/blob/master/java/google/registry/env/alpha/common/WEB-INF/nomulus-config.yaml +[default-config]: https://github.com/google/nomulus/blob/master/java/google/registry/config/files/default-config.yaml [registry-config]: https://github.com/google/nomulus/blob/master/java/google/registry/config/RegistryConfig.java diff --git a/java/google/registry/BUILD b/java/google/registry/BUILD index b4ef594d9..64c2468b1 100644 --- a/java/google/registry/BUILD +++ b/java/google/registry/BUILD @@ -53,7 +53,6 @@ zip_file( "env/common/default/WEB-INF/logging.properties", "env/common/default/WEB-INF/queue.xml", "env/common/default/WEB-INF/web.xml", - "env/production/common/WEB-INF/nomulus-config.yaml", "env/production/default/WEB-INF/appengine-web.xml", "env/production/default/WEB-INF/cron.xml", "//java/google/registry/module/frontend:frontend_jar_deploy.jar", @@ -61,7 +60,6 @@ zip_file( out = "registry_default.war", mappings = { "domain_registry/java/google/registry/env/common/default": "", - "domain_registry/java/google/registry/env/production/common": "", "domain_registry/java/google/registry/env/production/default": "", "domain_registry/java/google/registry/module/frontend": "WEB-INF/lib", }, @@ -77,14 +75,12 @@ zip_file( "env/common/backend/WEB-INF/logging.properties", "env/common/backend/WEB-INF/web.xml", "env/production/backend/WEB-INF/appengine-web.xml", - "env/production/common/WEB-INF/nomulus-config.yaml", "//java/google/registry/module/backend:backend_jar_deploy.jar", ], out = "registry_backend.war", mappings = { "domain_registry/java/google/registry/env/common/backend": "", "domain_registry/java/google/registry/env/production/backend": "", - "domain_registry/java/google/registry/env/production/common": "", "domain_registry/java/google/registry/module/backend": "WEB-INF/lib", }, deps = [ @@ -98,14 +94,12 @@ zip_file( srcs = [ "env/common/tools/WEB-INF/logging.properties", "env/common/tools/WEB-INF/web.xml", - "env/production/common/WEB-INF/nomulus-config.yaml", "env/production/tools/WEB-INF/appengine-web.xml", "//java/google/registry/module/tools:tools_jar_deploy.jar", ], out = "registry_tools.war", mappings = { "domain_registry/java/google/registry/env/common/tools": "", - "domain_registry/java/google/registry/env/production/common": "", "domain_registry/java/google/registry/env/production/tools": "", "domain_registry/java/google/registry/module/tools": "WEB-INF/lib", }, @@ -138,13 +132,11 @@ registry_ear_file( zip_file( name = "registry_default_sandbox_war", srcs = [ - "env/sandbox/common/WEB-INF/nomulus-config.yaml", "env/sandbox/default/WEB-INF/appengine-web.xml", "env/sandbox/default/WEB-INF/cron.xml", ], out = "registry_default_sandbox.war", mappings = { - "domain_registry/java/google/registry/env/sandbox/common": "", "domain_registry/java/google/registry/env/sandbox/default": "", }, deps = [":registry_default_war"], @@ -154,12 +146,10 @@ zip_file( name = "registry_backend_sandbox_war", srcs = [ "env/sandbox/backend/WEB-INF/appengine-web.xml", - "env/sandbox/common/WEB-INF/nomulus-config.yaml", ], out = "registry_backend_sandbox.war", mappings = { "domain_registry/java/google/registry/env/sandbox/backend": "", - "domain_registry/java/google/registry/env/sandbox/common": "", }, deps = [":registry_backend_war"], ) @@ -167,12 +157,10 @@ zip_file( zip_file( name = "registry_tools_sandbox_war", srcs = [ - "env/sandbox/common/WEB-INF/nomulus-config.yaml", "env/sandbox/tools/WEB-INF/appengine-web.xml", ], out = "registry_tools_sandbox.war", mappings = { - "domain_registry/java/google/registry/env/sandbox/common": "", "domain_registry/java/google/registry/env/sandbox/tools": "", }, deps = [":registry_tools_war"], @@ -200,13 +188,11 @@ registry_ear_file( zip_file( name = "registry_default_alpha_war", srcs = [ - "env/alpha/common/WEB-INF/nomulus-config.yaml", "env/alpha/default/WEB-INF/appengine-web.xml", "env/alpha/default/WEB-INF/cron.xml", ], out = "registry_default_alpha.war", mappings = { - "domain_registry/java/google/registry/env/alpha/common": "", "domain_registry/java/google/registry/env/alpha/default": "", }, deps = [":registry_default_war"], @@ -216,12 +202,10 @@ zip_file( name = "registry_backend_alpha_war", srcs = [ "env/alpha/backend/WEB-INF/appengine-web.xml", - "env/alpha/common/WEB-INF/nomulus-config.yaml", ], out = "registry_backend_alpha.war", mappings = { "domain_registry/java/google/registry/env/alpha/backend": "", - "domain_registry/java/google/registry/env/alpha/common": "", }, deps = [":registry_backend_war"], ) @@ -229,12 +213,10 @@ zip_file( zip_file( name = "registry_tools_alpha_war", srcs = [ - "env/alpha/common/WEB-INF/nomulus-config.yaml", "env/alpha/tools/WEB-INF/appengine-web.xml", ], out = "registry_tools_alpha.war", mappings = { - "domain_registry/java/google/registry/env/alpha/common": "", "domain_registry/java/google/registry/env/alpha/tools": "", }, deps = [":registry_tools_war"], @@ -262,13 +244,11 @@ registry_ear_file( zip_file( name = "registry_default_crash_war", srcs = [ - "env/crash/common/WEB-INF/nomulus-config.yaml", "env/crash/default/WEB-INF/appengine-web.xml", "env/crash/default/WEB-INF/cron.xml", ], out = "registry_default_crash.war", mappings = { - "domain_registry/java/google/registry/env/crash/common": "", "domain_registry/java/google/registry/env/crash/default": "", }, deps = [":registry_default_war"], @@ -278,12 +258,10 @@ zip_file( name = "registry_backend_crash_war", srcs = [ "env/crash/backend/WEB-INF/appengine-web.xml", - "env/crash/common/WEB-INF/nomulus-config.yaml", ], out = "registry_backend_crash.war", mappings = { "domain_registry/java/google/registry/env/crash/backend": "", - "domain_registry/java/google/registry/env/crash/common": "", }, deps = [":registry_backend_war"], ) @@ -291,12 +269,10 @@ zip_file( zip_file( name = "registry_tools_crash_war", srcs = [ - "env/crash/common/WEB-INF/nomulus-config.yaml", "env/crash/tools/WEB-INF/appengine-web.xml", ], out = "registry_tools_crash.war", mappings = { - "domain_registry/java/google/registry/env/crash/common": "", "domain_registry/java/google/registry/env/crash/tools": "", }, deps = [":registry_tools_war"], @@ -324,12 +300,10 @@ registry_ear_file( zip_file( name = "registry_default_local_war", srcs = [ - "env/local/common/WEB-INF/nomulus-config.yaml", "env/local/default/WEB-INF/appengine-web.xml", ], out = "registry_default_local.war", mappings = { - "domain_registry/java/google/registry/env/local/common": "", "domain_registry/java/google/registry/env/local/default": "", }, deps = [":registry_default_war"], @@ -339,12 +313,10 @@ zip_file( name = "registry_backend_local_war", srcs = [ "env/local/backend/WEB-INF/appengine-web.xml", - "env/local/common/WEB-INF/nomulus-config.yaml", ], out = "registry_backend_local.war", mappings = { "domain_registry/java/google/registry/env/local/backend": "", - "domain_registry/java/google/registry/env/local/common": "", }, deps = [":registry_backend_war"], ) @@ -352,12 +324,10 @@ zip_file( zip_file( name = "registry_tools_local_war", srcs = [ - "env/local/common/WEB-INF/nomulus-config.yaml", "env/local/tools/WEB-INF/appengine-web.xml", ], out = "registry_tools_local.war", mappings = { - "domain_registry/java/google/registry/env/local/common": "", "domain_registry/java/google/registry/env/local/tools": "", }, deps = [":registry_tools_war"], diff --git a/java/google/registry/config/BUILD b/java/google/registry/config/BUILD index 1c4dd3022..77d3be5a9 100644 --- a/java/google/registry/config/BUILD +++ b/java/google/registry/config/BUILD @@ -7,7 +7,7 @@ licenses(["notice"]) # Apache 2.0 java_library( name = "config", srcs = glob(["*.java"]), - resources = glob(["*.yaml"]), + resources = glob(["files/*.yaml"]), deps = [ "//java/google/registry/util", "@com_google_appengine_api_1_0_sdk", diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index ea555aa3b..e6aead6f8 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -19,7 +19,6 @@ import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.config.YamlUtils.getConfigSettings; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import com.google.common.base.Ascii; import com.google.common.base.Optional; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; @@ -27,6 +26,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.net.HostAndPort; import dagger.Module; import dagger.Provides; +import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.net.URI; @@ -43,6 +43,11 @@ import org.joda.time.Duration; /** * Central clearing-house for all configuration. + * + *
This class does not represent the total configuration of the Nomulus service. It's only + * meant for settings that need to be configured once. Settings which may be subject to + * change in the future, should instead be retrieved from Datastore. The {@link + * google.registry.model.registry.Registry Registry} class is one such example of this. */ public final class RegistryConfig { @@ -54,26 +59,7 @@ public final class RegistryConfig { String value() default ""; } - /** - * Configuration example for the Nomulus codebase. - * - *
The Nomulus codebase contains many classes that inject configurable settings. This is - * the centralized class that is used by default to configure them all, in hard-coded type-safe - * Java code. - * - *
This class does not represent the total configuration of the Nomulus service. It's - * only meant for settings that need to be configured once. Settings which may - * be subject to change in the future, should instead be retrieved from Datastore. The - * {@link google.registry.model.registry.Registry Registry} class is one such example of this. - * - *
It is recommended that users do not modify this file within a forked repository. It is - * preferable to modify these settings by swapping out this module with a separate copied version - * in the user's repository. For this to work, other files need to be copied too, such as the - * {@code @Component} instances under {@code google.registry.module}. This allows modules to be - * substituted at the {@code @Component} level. - */ + /** Dagger module for providing configuration settings. */ @Module public static final class ConfigModule { @@ -1056,22 +1042,8 @@ public final class RegistryConfig { *
This is used by the {@code nomulus} tool to connect to the App Engine remote API. */ public static HostAndPort getServer() { - // TODO(b/33386530): Make this configurable in a way that is accessible from the nomulus - // command-line tool. - switch (RegistryEnvironment.get()) { - case PRODUCTION: - return HostAndPort.fromParts("tools-dot-domain-registry.appspot.com", 443); - case LOCAL: - return HostAndPort.fromParts("localhost", 8080); - case UNITTEST: - throw new UnsupportedOperationException("Unit tests can't spin up a full server"); - default: - return HostAndPort.fromParts( - String.format( - "tools-dot-domain-registry-%s.appspot.com", - Ascii.toLowerCase(RegistryEnvironment.get().name())), - 443); - } + ToolsServiceUrl url = CONFIG_SETTINGS.get().appEngine.toolsServiceUrl; + return HostAndPort.fromParts(url.hostName, url.port); } /** Returns the amount of time a singleton should be cached, before expiring. */ diff --git a/java/google/registry/config/YamlUtils.java b/java/google/registry/config/YamlUtils.java index f9af34d1f..5bda3015e 100644 --- a/java/google/registry/config/YamlUtils.java +++ b/java/google/registry/config/YamlUtils.java @@ -14,62 +14,52 @@ package google.registry.config; -import static google.registry.config.RegistryEnvironment.UNITTEST; +import static com.google.common.base.Ascii.toLowerCase; import static google.registry.util.FormattingLogger.getLoggerForCallerClass; import static google.registry.util.ResourceUtils.readResourceUtf8; import com.google.common.base.Optional; -import com.google.common.io.CharStreams; import google.registry.util.FormattingLogger; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; import java.util.Map; import org.yaml.snakeyaml.Yaml; -/** Utility methods for dealing with YAML. */ +/** + * Utility methods for dealing with YAML. + * + *
There are always two YAML configuration files that are used: the {@code default-config.yaml} + * file, which contains default configuration for all environments, and the environment-specific + * {@code nomulus-config-ENVIRONMENT.yaml} file, which contains overrides for the default values for + * environment-specific settings such as the App Engine project ID. The environment-specific + * configuration can be blank, but it must exist. + */ public final class YamlUtils { private static final FormattingLogger logger = getLoggerForCallerClass(); - private static final String CUSTOM_CONFIG_PATH = "WEB-INF/nomulus-config.yaml"; + private static final String ENVIRONMENT_CONFIG_FORMAT = "files/nomulus-config-%s.yaml"; private static final String YAML_CONFIG_PROD = - readResourceUtf8(RegistryConfig.class, "default-config.yaml"); - private static final String YAML_CONFIG_UNITTEST = - readResourceUtf8(RegistryConfig.class, "unittest-config.yaml"); + readResourceUtf8(RegistryConfig.class, "files/default-config.yaml"); /** - * Loads the {@link RegistryConfigSettings} POJO from the YAML configuration file(s). + * 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 custom config - * file located in {@code WEB-INF/nomulus-config.yaml} is also loaded and those values merged into - * the POJO. If the custom config file does not exist then an info notice is logged, but if it - * does exist and is invalid then a fatal error is thrown. + * 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. * - *
Unit tests load the {@code unittest-config.yaml} file for custom config.
+ * @throws IllegalStateException if the configuration files don't exist or are invalid
*/
static RegistryConfigSettings getConfigSettings() {
- String yaml = YAML_CONFIG_PROD;
- if (RegistryEnvironment.get() == UNITTEST) {
- yaml = mergeYaml(yaml, YAML_CONFIG_UNITTEST);
- } else {
- try {
- // We have to load the file this way because App Engine does not allow loading files in the
- // WEB-INF directory using a class loader.
- FileInputStream fin = new FileInputStream(new File(CUSTOM_CONFIG_PATH));
- String customYaml = CharStreams.toString(new InputStreamReader(fin, "UTF-8"));
- yaml = mergeYaml(yaml, customYaml);
- } catch (IOException e) {
- logger.warningfmt(
- "There was no custom configuration file to load at %s", CUSTOM_CONFIG_PATH);
- }
- }
+ String configFilePath =
+ String.format(ENVIRONMENT_CONFIG_FORMAT, toLowerCase(RegistryEnvironment.get().name()));
+ String customYaml = readResourceUtf8(RegistryConfig.class, configFilePath);
try {
- return new Yaml().loadAs(yaml, RegistryConfigSettings.class);
+ String mergedYaml = mergeYaml(YAML_CONFIG_PROD, customYaml);
+ return new Yaml().loadAs(mergedYaml, RegistryConfigSettings.class);
} catch (Exception e) {
- throw new IllegalStateException("Fatal error: Custom YAML configuration file is invalid", e);
+ throw new IllegalStateException(
+ "Fatal error: Environment configuration YAML file is invalid", e);
}
}
@@ -89,18 +79,14 @@ public final class YamlUtils {
static String mergeYaml(String defaultYaml, String customYaml) {
Yaml yaml = new Yaml();
Map