Make all but one field on RegistryConfig static

The next step will be to get rid of RegistryConfig descendants and RegistryConfigLoader entirely.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143812815
This commit is contained in:
mcilwain 2017-01-06 14:06:01 -08:00 committed by Ben McIlwain
parent 7fba7c1e4f
commit c5c74961bb
23 changed files with 224 additions and 324 deletions

View file

@ -15,6 +15,7 @@
package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.appengine.api.utils.SystemProperty;
import com.google.common.base.Optional;
@ -73,11 +74,6 @@ public final class ConfigModule {
return REGISTRY_ENVIRONMENT;
}
@Provides
public static RegistryConfig provideConfig(RegistryEnvironment environment) {
return environment.config();
}
@Provides
@Config("projectId")
public static String provideProjectId() {
@ -356,8 +352,8 @@ public final class ConfigModule {
*/
@Provides
@Config("eppResourceIndexBucketCount")
public static int provideEppResourceIndexBucketCount(RegistryConfig config) {
return config.getEppResourceIndexBucketCount();
public static int provideEppResourceIndexBucketCount() {
return RegistryConfig.getEppResourceIndexBucketCount();
}
/**
@ -897,14 +893,15 @@ public final class ConfigModule {
}
/**
* The time between a contact transfer request and its expiration date.
* The global automatic transfer length for contacts. After this amount of time has
* elapsed, the transfer is automatically approved.
*
* @see google.registry.flows.contact.ContactTransferRequestFlow
*/
@Provides
@Config("contactAutomaticTransferLength")
public static Duration provideContactAutomaticTransferLength(RegistryConfig config) {
return config.getContactAutomaticTransferLength();
public static Duration provideContactAutomaticTransferLength() {
return standardDays(5);
}
/**
@ -960,6 +957,33 @@ public final class ConfigModule {
return "google.registry.flows.custom.CustomLogicFactory";
}
private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = ""
+ "# This list contains reserve terms for the TLD. Other terms may be reserved\n"
+ "# but not included in this list, including terms EXAMPLE REGISTRY chooses not\n"
+ "# to publish, and terms that ICANN commonly mandates to be reserved. This\n"
+ "# list is subject to change and the most up-to-date source is always to\n"
+ "# check availability directly with the Registry server.\n";
/**
* Returns the header text at the top of the reserved terms exported list.
*
* @see google.registry.export.ExportUtils#exportReservedTerms
*/
@Provides
@Config("reservedTermsExportDisclaimer")
public static String provideReservedTermsExportDisclaimer() {
return RESERVED_TERMS_EXPORT_DISCLAIMER;
}
/**
* Returns the clientId of the registrar used by the {@code CheckApiServlet}.
*/
@Provides
@Config("checkApiServletRegistrarClientId")
public static String provideCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
/**
* Returns the help path for the RDAP terms of service.
*
@ -1050,8 +1074,12 @@ public final class ConfigModule {
public static final String CONTACT_AND_HOST_ROID_SUFFIX = "ROID";
public static final String RESERVED_TERMS_TEST_EXPORT_DISCLAIMER = "This is a disclaimer.\n";
public static final String GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS = "noreply@testing.example";
public static final String GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME = "Testing Nomulus";
public static final Duration CONTACT_AUTOMATIC_TRANSFER_LENGTH = standardDays(5);
}
}

View file

@ -15,14 +15,9 @@
package google.registry.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.common.base.Optional;
import com.google.common.net.HostAndPort;
import java.net.URL;
import javax.annotation.concurrent.Immutable;
import org.joda.time.Duration;
/**
* Default production configuration for global constants that can't be injected.
@ -34,15 +29,9 @@ import org.joda.time.Duration;
@Immutable
public final class ProductionRegistryConfigExample extends RegistryConfig {
@SuppressWarnings("unused")
private final RegistryEnvironment environment;
private static final String RESERVED_TERMS_EXPORT_DISCLAIMER = ""
+ "# This list contains reserve terms for the TLD. Other terms may be reserved\n"
+ "# but not included in this list, including terms EXAMPLE REGISTRY chooses not\n"
+ "# to publish, and terms that ICANN commonly mandates to be reserved. This\n"
+ "# list is subject to change and the most up-to-date source is always to\n"
+ "# check availability directly with the Registry server.\n";
public ProductionRegistryConfigExample(RegistryEnvironment environment) {
this.environment = checkNotNull(environment);
}
@ -51,50 +40,4 @@ public final class ProductionRegistryConfigExample extends RegistryConfig {
public Optional<String> getECatcherAddress() {
throw new UnsupportedOperationException(); // n/a
}
@Override
public HostAndPort getServer() {
switch (environment) {
case LOCAL:
return HostAndPort.fromParts("localhost", 8080);
default:
return HostAndPort.fromParts(
String.format("tools-dot-%s.appspot.com", getProjectId()), 443);
}
}
@Override
public String getReservedTermsExportDisclaimer() {
return RESERVED_TERMS_EXPORT_DISCLAIMER;
}
@Override
public String getRegistrarDefaultWhoisServer() {
return "whois.nic.registry.example";
}
@Override
public URL getRegistrarDefaultReferralUrl() {
return makeUrl("https://www.registry.example");
}
@Override
public int getEppResourceIndexBucketCount() {
return 997;
}
@Override
public Duration getBaseOfyRetryDuration() {
return Duration.millis(100);
}
@Override
public Duration getContactAutomaticTransferLength() {
return standardDays(5);
}
@Override
public String getCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
}

View file

@ -14,6 +14,8 @@
package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl;
import com.google.common.base.Ascii;
import com.google.common.base.Optional;
import com.google.common.net.HostAndPort;
@ -109,7 +111,17 @@ public abstract class RegistryConfig {
*
* <p>This is used by the {@code nomulus} tool to connect to the App Engine remote API.
*/
public abstract HostAndPort getServer();
public static HostAndPort getServer() {
switch (RegistryEnvironment.get()) {
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-%s.appspot.com", getProjectId()), 443);
}
}
/** Returns the amount of time a singleton should be cached, before expiring. */
public static Duration getSingletonCacheRefreshDuration() {
@ -148,46 +160,56 @@ public abstract class RegistryConfig {
}
}
/**
* Returns the header text at the top of the reserved terms exported list.
*
* @see google.registry.export.ExportUtils#exportReservedTerms
*/
public abstract String getReservedTermsExportDisclaimer();
/**
* Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}.
*
* @see "google.registry.whois.DomainWhoisResponse"
* @see "google.registry.whois.RegistrarWhoisResponse"
*/
public abstract String getRegistrarDefaultWhoisServer();
public static String getRegistrarDefaultWhoisServer() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return "whois.nic.fakewhois.example";
default:
return "whois.nic.registry.example";
}
}
/**
* Returns the default referral URL that is used unless registrars have specified otherwise.
*/
public abstract URL getRegistrarDefaultReferralUrl();
public static URL getRegistrarDefaultReferralUrl() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return makeUrl("http://www.referral.example/path");
default:
return makeUrl("https://www.registry.example");
}
}
/**
* Returns the number of EppResourceIndex buckets to be used.
* Returns the number of {@code EppResourceIndex} buckets to be used.
*/
public abstract int getEppResourceIndexBucketCount();
public static int getEppResourceIndexBucketCount() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return 3;
default:
return 997;
}
}
/**
* Returns the base duration that gets doubled on each retry within {@code Ofy}.
* Returns the base retry duration that gets doubled after each failure within {@code Ofy}.
*/
public abstract Duration getBaseOfyRetryDuration();
/**
* Returns the global automatic transfer length for contacts. After this amount of time has
* elapsed, the transfer is automatically approved.
*/
public abstract Duration getContactAutomaticTransferLength();
/**
* Returns the clientId of the registrar used by the {@code CheckApiServlet}.
*/
public abstract String getCheckApiServletRegistrarClientId();
public static Duration getBaseOfyRetryDuration() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return Duration.ZERO;
default:
return Duration.millis(100);
}
}
// XXX: Please consider using ConfigModule instead of adding new methods to this file.
}

View file

@ -14,13 +14,7 @@
package google.registry.config;
import static google.registry.config.ConfigUtils.makeUrl;
import static org.joda.time.Duration.standardDays;
import com.google.common.base.Optional;
import com.google.common.net.HostAndPort;
import java.net.URL;
import org.joda.time.Duration;
/**
* An implementation of RegistryConfig for unit testing that contains suitable testing data.
@ -33,44 +27,4 @@ public class TestRegistryConfig extends RegistryConfig {
public Optional<String> getECatcherAddress() {
throw new UnsupportedOperationException();
}
@Override
public HostAndPort getServer() {
throw new UnsupportedOperationException();
}
@Override
public String getReservedTermsExportDisclaimer() {
return "This is a disclaimer.\n";
}
@Override
public String getRegistrarDefaultWhoisServer() {
return "whois.nic.fakewhois.example";
}
@Override
public URL getRegistrarDefaultReferralUrl() {
return makeUrl("http://www.referral.example/path");
}
@Override
public int getEppResourceIndexBucketCount() {
return 2;
}
@Override
public Duration getBaseOfyRetryDuration() {
return Duration.ZERO;
}
@Override
public Duration getContactAutomaticTransferLength() {
return standardDays(5);
}
@Override
public String getCheckApiServletRegistrarClientId() {
return "TheRegistrar";
}
}