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";
}
}

View file

@ -16,7 +16,6 @@ package google.registry.export;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static google.registry.export.ExportUtils.exportReservedTerms;
import static google.registry.request.Action.Method.POST;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
@ -41,6 +40,7 @@ public class ExportReservedTermsAction implements Runnable {
static final String RESERVED_TERMS_FILENAME = "reserved_terms.txt";
@Inject DriveConnection driveConnection;
@Inject ExportUtils exportUtils;
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
@Inject Response response;
@Inject ExportReservedTermsAction() {}
@ -70,7 +70,7 @@ public class ExportReservedTermsAction implements Runnable {
RESERVED_TERMS_FILENAME,
EXPORT_MIME_TYPE,
registry.getDriveFolderId(),
exportReservedTerms(registry).getBytes(UTF_8));
exportUtils.exportReservedTerms(registry).getBytes(UTF_8));
logger.infofmt("Exporting reserved terms succeeded for TLD %s, response was: %s",
tld, resultMsg);
}

View file

@ -18,22 +18,28 @@ import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import com.google.common.base.Joiner;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryEnvironment;
import google.registry.config.ConfigModule.Config;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedList.ReservedListEntry;
import java.util.Set;
import java.util.TreeSet;
import javax.inject.Inject;
/** Container class for exported-related static utility methods. */
public class ExportUtils {
/** Container class for exported-related utility methods. */
public final class ExportUtils {
private ExportUtils() {}
private final String reservedTermsExportDisclaimer;
@Inject
public ExportUtils(
@Config("reservedTermsExportDisclaimer") String reservedTermsExportDisclaimer) {
this.reservedTermsExportDisclaimer = reservedTermsExportDisclaimer;
}
/** Returns the file contents of the auto-export reserved terms document for the given TLD. */
public static String exportReservedTerms(Registry registry) {
StringBuilder termsBuilder =
new StringBuilder(RegistryEnvironment.get().config().getReservedTermsExportDisclaimer());
public String exportReservedTerms(Registry registry) {
StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer);
Set<String> reservedTerms = new TreeSet<>();
for (Key<ReservedList> key : registry.getReservedLists()) {
ReservedList reservedList = ReservedList.load(key).get();

View file

@ -35,7 +35,7 @@ import com.google.template.soy.SoyFileSet;
import com.google.template.soy.tofu.SoyTofu;
import dagger.Module;
import dagger.Provides;
import google.registry.config.RegistryConfig;
import google.registry.config.ConfigModule.Config;
import google.registry.flows.soy.DomainCheckFeeEppSoyInfo;
import google.registry.model.domain.fee.FeeCheckResponseExtension;
import google.registry.model.eppoutput.CheckData.DomainCheck;
@ -69,7 +69,7 @@ public class CheckApiAction implements Runnable {
@Inject @Parameter("domain") String domain;
@Inject Response response;
@Inject EppController eppController;
@Inject RegistryConfig config;
@Inject @Config("checkApiServletRegistrarClientId") String checkApiServletRegistrarClientId;
@Inject CheckApiAction() {}
@Override
@ -96,9 +96,8 @@ public class CheckApiAction implements Runnable {
.setData(ImmutableMap.of("domainName", domainString))
.render()
.getBytes(UTF_8);
SessionMetadata sessionMetadata = new StatelessRequestSessionMetadata(
config.getCheckApiServletRegistrarClientId(),
FEE_EXTENSION_URIS);
SessionMetadata sessionMetadata =
new StatelessRequestSessionMetadata(checkApiServletRegistrarClientId, FEE_EXTENSION_URIS);
EppResponse response = eppController
.handleEppCommand(
sessionMetadata,

View file

@ -14,12 +14,13 @@
package google.registry.model.index;
import static google.registry.config.RegistryConfig.getEppResourceIndexBucketCount;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import google.registry.config.RegistryEnvironment;
import google.registry.model.EppResource;
import google.registry.model.ImmutableObject;
import google.registry.model.annotations.VirtualEntity;
@ -38,7 +39,7 @@ public class EppResourceIndexBucket extends ImmutableObject {
* change the number of buckets and utilize a random distribution once we do.
*/
private static long getBucketIdFromEppResource(Key<? extends EppResource> resourceKey) {
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
int numBuckets = getEppResourceIndexBucketCount();
// IDs can't be 0, so add 1 to the hash.
return Hashing.consistentHash(resourceKey.getName().hashCode(), numBuckets) + 1;
}
@ -56,8 +57,7 @@ public class EppResourceIndexBucket extends ImmutableObject {
/** Returns the keys to all buckets. */
public static Iterable<Key<EppResourceIndexBucket>> getAllBuckets() {
ImmutableList.Builder<Key<EppResourceIndexBucket>> builder = new ImmutableList.Builder<>();
int numBuckets = RegistryEnvironment.get().config().getEppResourceIndexBucketCount();
for (int bucketId = 1; bucketId <= numBuckets; bucketId++) {
for (int bucketId = 1; bucketId <= getEppResourceIndexBucketCount(); bucketId++) {
builder.add(getBucketKey(bucketId));
}
return builder.build();

View file

@ -24,6 +24,7 @@ import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.io.BaseEncoding.base64;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
@ -446,10 +447,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}
public String getWhoisServer() {
if (whoisServer == null) {
return ENVIRONMENT.config().getRegistrarDefaultWhoisServer();
}
return whoisServer;
return firstNonNull(whoisServer, getRegistrarDefaultWhoisServer());
}
public boolean getBlockPremiumNames() {

View file

@ -29,7 +29,6 @@ import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import google.registry.config.ConfigModule.Config;
import google.registry.config.RegistryConfig;
import google.registry.keyring.api.KeyModule.Key;
import google.registry.request.HttpException.InternalServerErrorException;
import google.registry.util.FormattingLogger;
@ -62,7 +61,6 @@ public class RdeReporter {
* ICANN Registry Interfaces - Interface details</a>*/
private static final String REPORT_MIME = "text/xml";
@Inject RegistryConfig config;
@Inject Retrier retrier;
@Inject URLFetchService urlFetchService;
@Inject @Config("rdeReportUrlPrefix") String reportUrlPrefix;