mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Move YamlUtils to be under google.registry.util package
This makes it simpler to package google.registry.util as a separate project in Gradle that can be depended upon by the proxy package. Currently the proxy package depends on both google.registry.util and google.registry.config. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=221450085
This commit is contained in:
parent
e51cf3e9c7
commit
c0239b0a07
6 changed files with 29 additions and 27 deletions
|
@ -23,6 +23,5 @@ java_library(
|
||||||
"@javax_inject",
|
"@javax_inject",
|
||||||
"@joda_time",
|
"@joda_time",
|
||||||
"@org_joda_money",
|
"@org_joda_money",
|
||||||
"@org_yaml_snakeyaml",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,9 +16,11 @@ package google.registry.config;
|
||||||
|
|
||||||
import static com.google.common.base.Suppliers.memoize;
|
import static com.google.common.base.Suppliers.memoize;
|
||||||
import static google.registry.config.ConfigUtils.makeUrl;
|
import static google.registry.config.ConfigUtils.makeUrl;
|
||||||
|
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -29,6 +31,7 @@ import dagger.Provides;
|
||||||
import google.registry.util.RandomStringGenerator;
|
import google.registry.util.RandomStringGenerator;
|
||||||
import google.registry.util.StringGenerator;
|
import google.registry.util.StringGenerator;
|
||||||
import google.registry.util.TaskQueueUtils;
|
import google.registry.util.TaskQueueUtils;
|
||||||
|
import google.registry.util.YamlUtils;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -56,6 +59,10 @@ import org.joda.time.Duration;
|
||||||
*/
|
*/
|
||||||
public final class RegistryConfig {
|
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. */
|
/** Dagger qualifier for configuration settings. */
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
|
@ -64,6 +71,22 @@ public final class RegistryConfig {
|
||||||
String value() default "";
|
String value() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the {@link RegistryConfigSettings} POJO from the YAML configuration files.
|
||||||
|
*
|
||||||
|
* <p>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. */
|
/** Dagger module for providing configuration settings. */
|
||||||
@Module
|
@Module
|
||||||
public static final class ConfigModule {
|
public static final class ConfigModule {
|
||||||
|
@ -1514,7 +1537,7 @@ public final class RegistryConfig {
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
public static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
||||||
memoize(YamlUtils::getConfigSettings);
|
memoize(RegistryConfig::getConfigSettings);
|
||||||
|
|
||||||
private static String formatComments(String text) {
|
private static String formatComments(String text) {
|
||||||
return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text).stream()
|
return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text).stream()
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
package google.registry.proxy;
|
package google.registry.proxy;
|
||||||
|
|
||||||
import static google.registry.config.YamlUtils.getConfigSettings;
|
|
||||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||||
|
import static google.registry.util.YamlUtils.getConfigSettings;
|
||||||
|
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -21,5 +21,6 @@ java_library(
|
||||||
"@com_ibm_icu_icu4j",
|
"@com_ibm_icu_icu4j",
|
||||||
"@javax_inject",
|
"@javax_inject",
|
||||||
"@joda_time",
|
"@joda_time",
|
||||||
|
"@org_yaml_snakeyaml",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,10 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 com.google.common.flogger.FluentLogger;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -35,10 +33,6 @@ public final class YamlUtils {
|
||||||
|
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
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.
|
* 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.
|
|
||||||
*
|
|
||||||
* <p>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.
|
* Recursively merges two YAML documents together.
|
||||||
*
|
*
|
|
@ -12,10 +12,10 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package google.registry.config;
|
package google.registry.util;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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 com.google.common.base.Joiner;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
Loading…
Add table
Add a link
Reference in a new issue