diff --git a/java/google/registry/config/ConfigModule.java b/java/google/registry/config/ConfigModule.java index 4311d8791..c71d60b51 100644 --- a/java/google/registry/config/ConfigModule.java +++ b/java/google/registry/config/ConfigModule.java @@ -16,6 +16,7 @@ package google.registry.config; import static google.registry.config.ConfigUtils.makeUrl; +import com.google.appengine.api.utils.SystemProperty; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -214,8 +215,8 @@ public final class ConfigModule { /** @see RegistryConfig#getCommitLogDatastoreRetention() */ @Provides @Config("commitLogDatastoreRetention") - public static Duration provideCommitLogDatastoreRetention(RegistryConfig config) { - return config.getCommitLogDatastoreRetention(); + public static Duration provideCommitLogDatastoreRetention() { + return RegistryConfig.getCommitLogDatastoreRetention(); } /** @@ -423,8 +424,8 @@ public final class ConfigModule { */ @Provides @Config("tmchCaTestingMode") - public static boolean provideTmchCaTestingMode(RegistryConfig config) { - return config.getTmchCaTestingMode(); + public static boolean provideTmchCaTestingMode() { + return RegistryConfig.getTmchCaTestingMode(); } /** @@ -467,6 +468,29 @@ public final class ConfigModule { } } + /** + * The email address that outgoing emails from the app are sent from. + * + * @see google.registry.util.SendEmailUtils + */ + @Provides + @Config("googleAppsSendFromEmailAddress") + public static String provideGoogleAppsSendFromEmailAddress() { + return String.format("noreply@%s.appspotmail.com", SystemProperty.applicationId.get()); + } + + /** + * The display name that is used on outgoing emails sent by Nomulus. + * + * @see google.registry.util.SendEmailUtils + */ + @Provides + @Config("googleAppsAdminEmailDisplayName") + public static String provideGoogleAppsAdminEmailDisplayName() { + // Production example: "Example Registry" + return "Google Domain Registry"; + } + /** * Returns the Google Cloud Storage bucket for staging escrow deposits pending upload. * @@ -1025,5 +1049,9 @@ public final class ConfigModule { public static class LocalTestConfig { public static final String CONTACT_AND_HOST_ROID_SUFFIX = "ROID"; + + 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"; } } diff --git a/java/google/registry/config/ProductionRegistryConfigExample.java b/java/google/registry/config/ProductionRegistryConfigExample.java index 1b9754245..3cb595457 100644 --- a/java/google/registry/config/ProductionRegistryConfigExample.java +++ b/java/google/registry/config/ProductionRegistryConfigExample.java @@ -18,7 +18,6 @@ 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.appengine.api.utils.SystemProperty; import com.google.common.base.Optional; import com.google.common.net.HostAndPort; import java.net.URL; @@ -48,33 +47,6 @@ public final class ProductionRegistryConfigExample extends RegistryConfig { this.environment = checkNotNull(environment); } - /** - * {@inheritDoc} - * - *

Thirty days makes a sane default, because it's highly unlikely we'll ever need to generate a - * deposit older than that. And if we do, we could always bring up a separate App Engine instance - * and replay the commit logs off GCS. - */ - @Override - public Duration getCommitLogDatastoreRetention() { - return Duration.standardDays(30); - } - - @Override - public String getSnapshotsBucket() { - return RegistryConfig.getProjectId() + "-snapshots"; - } - - @Override - public boolean getTmchCaTestingMode() { - switch (environment) { - case PRODUCTION: - return false; - default: - return true; - } - } - @Override public Optional getECatcherAddress() { throw new UnsupportedOperationException(); // n/a @@ -91,36 +63,11 @@ public final class ProductionRegistryConfigExample extends RegistryConfig { } } - @Override - public Duration getSingletonCacheRefreshDuration() { - return Duration.standardMinutes(10); - } - - @Override - public Duration getDomainLabelListCacheDuration() { - return Duration.standardHours(1); - } - - @Override - public Duration getSingletonCachePersistDuration() { - return Duration.standardDays(365); - } - @Override public String getReservedTermsExportDisclaimer() { return RESERVED_TERMS_EXPORT_DISCLAIMER; } - @Override - public String getGoogleAppsAdminEmailDisplayName() { - return "Example Registry"; - } - - @Override - public String getGoogleAppsSendFromEmailAddress() { - return String.format("noreply@%s.appspotmail.com", SystemProperty.applicationId.get()); - } - @Override public String getRegistrarDefaultWhoisServer() { return "whois.nic.registry.example"; diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index f3e5e4e76..1f1b1f171 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -49,7 +49,9 @@ public abstract class RegistryConfig { * * @see google.registry.export.ExportSnapshotServlet */ - public abstract String getSnapshotsBucket(); + public static String getSnapshotsBucket() { + return getProjectId() + "-snapshots"; + } /** * Number of sharded commit log buckets. @@ -82,14 +84,23 @@ public abstract class RegistryConfig { * @see google.registry.backup.DeleteOldCommitLogsAction * @see google.registry.model.translators.CommitLogRevisionsTranslatorFactory */ - public abstract Duration getCommitLogDatastoreRetention(); + public static Duration getCommitLogDatastoreRetention() { + return Duration.standardDays(30); + } /** * Returns {@code true} if TMCH certificate authority should be in testing mode. * * @see google.registry.tmch.TmchCertificateAuthority */ - public abstract boolean getTmchCaTestingMode(); + public static boolean getTmchCaTestingMode() { + switch (RegistryEnvironment.get()) { + case PRODUCTION: + return false; + default: + return true; + } + } public abstract Optional getECatcherAddress(); @@ -101,7 +112,16 @@ public abstract class RegistryConfig { public abstract HostAndPort getServer(); /** Returns the amount of time a singleton should be cached, before expiring. */ - public abstract Duration getSingletonCacheRefreshDuration(); + public static Duration getSingletonCacheRefreshDuration() { + switch (RegistryEnvironment.get()) { + case UNITTEST: + // All cache durations are set to zero so that unit tests can update and then retrieve data + // immediately without failure. + return Duration.ZERO; + default: + return Duration.standardMinutes(10); + } + } /** * Returns the amount of time a domain label list should be cached in memory before expiring. @@ -109,10 +129,24 @@ public abstract class RegistryConfig { * @see google.registry.model.registry.label.ReservedList * @see google.registry.model.registry.label.PremiumList */ - public abstract Duration getDomainLabelListCacheDuration(); + public static Duration getDomainLabelListCacheDuration() { + switch (RegistryEnvironment.get()) { + case UNITTEST: + return Duration.ZERO; + default: + return Duration.standardHours(1); + } + } /** Returns the amount of time a singleton should be cached in persist mode, before expiring. */ - public abstract Duration getSingletonCachePersistDuration(); + public static Duration getSingletonCachePersistDuration() { + switch (RegistryEnvironment.get()) { + case UNITTEST: + return Duration.ZERO; + default: + return Duration.standardDays(365); + } + } /** * Returns the header text at the top of the reserved terms exported list. @@ -121,20 +155,6 @@ public abstract class RegistryConfig { */ public abstract String getReservedTermsExportDisclaimer(); - /** - * Returns a display name that is used on outgoing emails sent by Nomulus. - * - * @see google.registry.util.SendEmailUtils - */ - public abstract String getGoogleAppsAdminEmailDisplayName(); - - /** - * Returns the email address that outgoing emails from the app are sent from. - * - * @see google.registry.util.SendEmailUtils - */ - public abstract String getGoogleAppsSendFromEmailAddress(); - /** * Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}. * diff --git a/java/google/registry/config/RegistryConfigLoader.java b/java/google/registry/config/RegistryConfigLoader.java index d8ac3ad4f..4b534001c 100644 --- a/java/google/registry/config/RegistryConfigLoader.java +++ b/java/google/registry/config/RegistryConfigLoader.java @@ -28,6 +28,7 @@ import javax.annotation.concurrent.ThreadSafe; * passing the {@link RegistryEnvironment} as a single parameter. */ @ThreadSafe +@Deprecated // will be replaced by YAML config; see b/33386530 for details public final class RegistryConfigLoader { public static final String REGISTRY_CONFIG_PROPERTY = "google.registry.config"; diff --git a/java/google/registry/config/RegistryEnvironment.java b/java/google/registry/config/RegistryEnvironment.java index d485863e4..9ee148c08 100644 --- a/java/google/registry/config/RegistryEnvironment.java +++ b/java/google/registry/config/RegistryEnvironment.java @@ -72,14 +72,19 @@ public enum RegistryEnvironment { /** Globally override registry configuration from within a unit test. */ @VisibleForTesting + @Deprecated public static void overrideConfigurationForTesting(@Nullable RegistryConfig newConfig) { configOverride = newConfig; } @Nullable + @Deprecated private static RegistryConfig configOverride; + @Deprecated private static final RegistryConfig testingConfig = new TestRegistryConfig(); + + @Deprecated private final RegistryConfig config = RegistryConfigLoader.load(this); /** System property for configuring which environment we should use. */ diff --git a/java/google/registry/config/TestRegistryConfig.java b/java/google/registry/config/TestRegistryConfig.java index f8e5f3bf2..d24644f54 100644 --- a/java/google/registry/config/TestRegistryConfig.java +++ b/java/google/registry/config/TestRegistryConfig.java @@ -29,21 +29,6 @@ public class TestRegistryConfig extends RegistryConfig { public TestRegistryConfig() {} - @Override - public Duration getCommitLogDatastoreRetention() { - return Duration.standardDays(30); - } - - @Override - public String getSnapshotsBucket() { - return RegistryConfig.getProjectId() + "-snapshots"; - } - - @Override - public boolean getTmchCaTestingMode() { - return true; - } - @Override public Optional getECatcherAddress() { throw new UnsupportedOperationException(); @@ -54,38 +39,11 @@ public class TestRegistryConfig extends RegistryConfig { throw new UnsupportedOperationException(); } - @Override - public Duration getSingletonCacheRefreshDuration() { - // All cache durations are set to zero so that unit tests can update and then retrieve data - // immediately without failure. - return Duration.ZERO; - } - - @Override - public Duration getDomainLabelListCacheDuration() { - return Duration.ZERO; - } - - @Override - public Duration getSingletonCachePersistDuration() { - return Duration.ZERO; - } - @Override public String getReservedTermsExportDisclaimer() { return "This is a disclaimer.\n"; } - @Override - public String getGoogleAppsAdminEmailDisplayName() { - return "Testing Nomulus"; - } - - @Override - public String getGoogleAppsSendFromEmailAddress() { - return "noreply@testing.example"; - } - @Override public String getRegistrarDefaultWhoisServer() { return "whois.nic.fakewhois.example"; diff --git a/java/google/registry/export/ExportSnapshotServlet.java b/java/google/registry/export/ExportSnapshotServlet.java index 4c5e82a5f..3212c3073 100644 --- a/java/google/registry/export/ExportSnapshotServlet.java +++ b/java/google/registry/export/ExportSnapshotServlet.java @@ -21,7 +21,7 @@ import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR; import static javax.servlet.http.HttpServletResponse.SC_OK; import com.google.common.net.MediaType; -import google.registry.config.RegistryEnvironment; +import google.registry.config.RegistryConfig; import google.registry.util.Clock; import google.registry.util.FormattingLogger; import google.registry.util.NonFinalForTesting; @@ -44,8 +44,6 @@ import javax.servlet.http.HttpServletResponse; */ public class ExportSnapshotServlet extends HttpServlet { - private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get(); - /** Queue to use for enqueuing the task that will actually launch the backup. */ static final String QUEUE = "export-snapshot"; // See queue.xml. @@ -71,7 +69,7 @@ public class ExportSnapshotServlet extends HttpServlet { backupService.launchNewBackup( QUEUE, snapshotName, - ENVIRONMENT.config().getSnapshotsBucket(), + RegistryConfig.getSnapshotsBucket(), ExportConstants.getBackupKinds()); // Enqueue a poll task to monitor the backup and load reporting-related kinds into bigquery. checkSnapshotServlet.enqueuePollTask(snapshotName, ExportConstants.getReportingKinds()); diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index 548deca10..499611e3e 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.equalTo; import static com.google.common.base.Predicates.not; +import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; 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; @@ -49,7 +50,6 @@ import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Mapify; import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.Parent; -import google.registry.config.RegistryEnvironment; import google.registry.model.Buildable; import google.registry.model.CreateAutoTimestamp; import google.registry.model.ImmutableObject; @@ -211,24 +211,23 @@ public class Registry extends ImmutableObject implements Buildable { } /** A cache that loads the {@link Registry} for a given tld. */ - private static final LoadingCache> CACHE = CacheBuilder.newBuilder() - .expireAfterWrite( - RegistryEnvironment.get().config().getSingletonCacheRefreshDuration().getMillis(), - MILLISECONDS) - .build(new CacheLoader>() { - @Override - public Optional load(final String tld) { - // Enter a transactionless context briefly; we don't want to enroll every TLD in a - // transaction that might be wrapping this call, and memcached results are fine here. - return Optional.fromNullable(ofy().doTransactionless(new Work() { - @Override - public Registry run() { - return ofy() - .load() - .key(Key.create(getCrossTldKey(), Registry.class, tld)) - .now(); - }})); - }}); + private static final LoadingCache> CACHE = + CacheBuilder.newBuilder() + .expireAfterWrite(getSingletonCacheRefreshDuration().getMillis(), MILLISECONDS) + .build(new CacheLoader>() { + @Override + public Optional load(final String tld) { + // Enter a transactionless context briefly; we don't want to enroll every TLD in a + // transaction that might be wrapping this call, and memcached results are fine here + return Optional.fromNullable(ofy().doTransactionless(new Work() { + @Override + public Registry run() { + return ofy() + .load() + .key(Key.create(getCrossTldKey(), Registry.class, tld)) + .now(); + }})); + }}); /** Returns the registry for a given TLD, throwing if none exists. */ public static Registry get(String tld) { diff --git a/java/google/registry/model/registry/label/PremiumList.java b/java/google/registry/model/registry/label/PremiumList.java index a3647739c..d6cee7933 100644 --- a/java/google/registry/model/registry/label/PremiumList.java +++ b/java/google/registry/model/registry/label/PremiumList.java @@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.Iterables.partition; +import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration; import static google.registry.model.common.EntityGroupRoot.getCrossTldKey; import static google.registry.model.ofy.ObjectifyService.allocateId; import static google.registry.model.ofy.ObjectifyService.ofy; @@ -48,7 +49,6 @@ import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.OnLoad; import com.googlecode.objectify.annotation.Parent; import com.googlecode.objectify.cmd.Query; -import google.registry.config.RegistryEnvironment; import google.registry.model.Buildable; import google.registry.model.ImmutableObject; import google.registry.model.annotations.ReportedOn; @@ -97,24 +97,22 @@ public final class PremiumList extends BaseDomainLabelList cache = CacheBuilder - .newBuilder() - .expireAfterWrite( - RegistryEnvironment.get().config().getDomainLabelListCacheDuration().getMillis(), - MILLISECONDS) - .build(new CacheLoader() { - @Override - public PremiumList load(final String listName) { - return ofy().doTransactionless(new Work() { + private static LoadingCache cache = + CacheBuilder.newBuilder() + .expireAfterWrite(getDomainLabelListCacheDuration().getMillis(), MILLISECONDS) + .build(new CacheLoader() { @Override - public PremiumList run() { - return ofy().load() - .type(PremiumList.class) - .parent(getCrossTldKey()) - .id(listName) - .now(); + public PremiumList load(final String listName) { + return ofy().doTransactionless(new Work() { + @Override + public PremiumList run() { + return ofy().load() + .type(PremiumList.class) + .parent(getCrossTldKey()) + .id(listName) + .now(); + }}); }}); - }}); /** * Gets the premium price for the specified label on the specified tld, or returns Optional.absent diff --git a/java/google/registry/model/registry/label/ReservedList.java b/java/google/registry/model/registry/label/ReservedList.java index 9c0764d96..5d2c8aa3c 100644 --- a/java/google/registry/model/registry/label/ReservedList.java +++ b/java/google/registry/model/registry/label/ReservedList.java @@ -16,6 +16,7 @@ package google.registry.model.registry.label; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration; 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; @@ -40,7 +41,6 @@ import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Mapify; import com.googlecode.objectify.mapper.Mapper; -import google.registry.config.RegistryEnvironment; import google.registry.model.registry.Registry; import java.util.List; import java.util.Map; @@ -221,16 +221,20 @@ public final class ReservedList return builder.build(); } - private static LoadingCache cache = CacheBuilder - .newBuilder() - .expireAfterWrite( - RegistryEnvironment.get().config().getDomainLabelListCacheDuration().getMillis(), - MILLISECONDS) - .build(new CacheLoader() { - @Override - public ReservedList load(String listName) { - return ofy().load().type(ReservedList.class).parent(getCrossTldKey()).id(listName).now(); - }}); + private static LoadingCache cache = + CacheBuilder.newBuilder() + .expireAfterWrite(getDomainLabelListCacheDuration().getMillis(), MILLISECONDS) + .build( + new CacheLoader() { + @Override + public ReservedList load(String listName) { + return ofy() + .load() + .type(ReservedList.class) + .parent(getCrossTldKey()) + .id(listName) + .now(); + }}); /** * Gets the {@link ReservationType} of a label in a single ReservedList, or returns an absent diff --git a/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java b/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java index fb1e1fb4b..c47f3e2f8 100644 --- a/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java +++ b/java/google/registry/model/translators/CommitLogRevisionsTranslatorFactory.java @@ -15,13 +15,13 @@ package google.registry.model.translators; import static com.google.common.base.MoreObjects.firstNonNull; +import static google.registry.config.RegistryConfig.getCommitLogDatastoreRetention; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; import com.googlecode.objectify.Key; -import google.registry.config.RegistryEnvironment; import google.registry.model.ofy.CommitLogManifest; import org.joda.time.DateTime; @@ -47,8 +47,6 @@ import org.joda.time.DateTime; public final class CommitLogRevisionsTranslatorFactory extends ImmutableSortedMapTranslatorFactory> { - private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get(); - /** * Add a reference to the current commit log to the resource's revisions map. * @@ -65,7 +63,7 @@ public final class CommitLogRevisionsTranslatorFactory ImmutableSortedMap> transformBeforeSave( ImmutableSortedMap> revisions) { DateTime now = ofy().getTransactionTime(); - DateTime threshold = now.minus(ENVIRONMENT.config().getCommitLogDatastoreRetention()); + DateTime threshold = now.minus(getCommitLogDatastoreRetention()); DateTime preThresholdTime = firstNonNull(revisions.floorKey(threshold), START_OF_TIME); return new ImmutableSortedMap.Builder>(Ordering.natural()) .putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false)) diff --git a/java/google/registry/tmch/TmchCertificateAuthority.java b/java/google/registry/tmch/TmchCertificateAuthority.java index 76600712b..373a684d5 100644 --- a/java/google/registry/tmch/TmchCertificateAuthority.java +++ b/java/google/registry/tmch/TmchCertificateAuthority.java @@ -14,6 +14,8 @@ package google.registry.tmch; +import static google.registry.config.RegistryConfig.getSingletonCachePersistDuration; +import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; import static google.registry.util.ResourceUtils.readResourceUtf8; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -21,7 +23,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import google.registry.config.ConfigModule.Config; -import google.registry.config.RegistryEnvironment; import google.registry.model.tmch.TmchCrl; import google.registry.util.Clock; import google.registry.util.NonFinalForTesting; @@ -46,8 +47,6 @@ import javax.inject.Inject; @ThreadSafe public final class TmchCertificateAuthority { - private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get(); - private static final String ROOT_CRT_FILE = "icann-tmch.crt"; private static final String TEST_ROOT_CRT_FILE = "icann-tmch-test.crt"; private static final String CRL_FILE = "icann-tmch.crl"; @@ -71,8 +70,7 @@ public final class TmchCertificateAuthority { */ private static final LoadingCache CRL_CACHE = CacheBuilder.newBuilder() - .expireAfterWrite( - ENVIRONMENT.config().getSingletonCacheRefreshDuration().getMillis(), MILLISECONDS) + .expireAfterWrite(getSingletonCacheRefreshDuration().getMillis(), MILLISECONDS) .build( new CacheLoader() { @Override @@ -102,8 +100,7 @@ public final class TmchCertificateAuthority { /** A cached function that loads the CRT from a jar resource. */ private static final LoadingCache ROOT_CACHE = CacheBuilder.newBuilder() - .expireAfterWrite( - ENVIRONMENT.config().getSingletonCachePersistDuration().getMillis(), MILLISECONDS) + .expireAfterWrite(getSingletonCachePersistDuration().getMillis(), MILLISECONDS) .build( new CacheLoader() { @Override diff --git a/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java b/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java index ef7dec491..396130479 100644 --- a/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java +++ b/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java @@ -71,9 +71,10 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA private static final String ARGS_PARAM = "args"; @Inject HttpServletRequest request; - @Inject SessionUtils sessionUtils; @Inject JsonActionRunner jsonActionRunner; @Inject Registrar initialRegistrar; + @Inject SendEmailUtils sendEmailUtils; + @Inject SessionUtils sessionUtils; @Inject @Config("registrarChangesNotificationEmailAddresses") ImmutableList registrarChangesNotificationEmailAddresses; @Inject RegistrarSettingsAction() {} @@ -285,7 +286,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA } SyncRegistrarsSheetAction.enqueueBackendTask(); if (!registrarChangesNotificationEmailAddresses.isEmpty()) { - SendEmailUtils.sendEmail( + sendEmailUtils.sendEmail( registrarChangesNotificationEmailAddresses, String.format("Registrar %s updated", registrarName), "The following changes were made to the registrar:\n" diff --git a/java/google/registry/util/CacheUtils.java b/java/google/registry/util/CacheUtils.java index b42abad78..645607ff7 100644 --- a/java/google/registry/util/CacheUtils.java +++ b/java/google/registry/util/CacheUtils.java @@ -15,18 +15,17 @@ package google.registry.util; import static com.google.common.base.Suppliers.memoizeWithExpiration; +import static google.registry.config.RegistryConfig.getSingletonCachePersistDuration; +import static google.registry.config.RegistryConfig.getSingletonCacheRefreshDuration; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.joda.time.Duration.ZERO; import com.google.common.base.Supplier; -import google.registry.config.RegistryEnvironment; import org.joda.time.Duration; /** Utility methods related to caching. */ public class CacheUtils { - private static final RegistryEnvironment ENVIRONMENT = RegistryEnvironment.get(); - /** * Memoize a supplier, with a short expiration specified in the environment config. * @@ -34,7 +33,7 @@ public class CacheUtils { * lists downloaded from the TMCH get updated in datastore and the caches need to be refreshed.) */ public static Supplier memoizeWithShortExpiration(Supplier original) { - return memoizeForDuration(original, ENVIRONMENT.config().getSingletonCacheRefreshDuration()); + return memoizeForDuration(original, getSingletonCacheRefreshDuration()); } /** @@ -45,7 +44,7 @@ public class CacheUtils { * while allowing the production config to set the expiration to forever. */ public static Supplier memoizeWithLongExpiration(Supplier original) { - return memoizeForDuration(original, ENVIRONMENT.config().getSingletonCachePersistDuration()); + return memoizeForDuration(original, getSingletonCachePersistDuration()); } /** Memoize a supplier, with a given expiration. */ diff --git a/java/google/registry/util/SendEmailUtils.java b/java/google/registry/util/SendEmailUtils.java index 835254485..f297f6011 100644 --- a/java/google/registry/util/SendEmailUtils.java +++ b/java/google/registry/util/SendEmailUtils.java @@ -20,10 +20,9 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Predicates; import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import google.registry.config.RegistryConfig; -import google.registry.config.RegistryEnvironment; +import google.registry.config.ConfigModule.Config; import java.util.List; +import javax.inject.Inject; import javax.mail.Message; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; @@ -33,30 +32,31 @@ import javax.mail.internet.InternetAddress; */ public class SendEmailUtils { - private static final RegistryConfig CONFIG = RegistryEnvironment.get().config(); private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); + private final String googleAppsSendFromEmailAddress; + private final String googleAppsAdminEmailDisplayName; + + @Inject + public SendEmailUtils( + @Config("googleAppsSendFromEmailAddress") String googleAppsSendFromEmailAddress, + @Config("googleAppsAdminEmailDisplayName") String googleAppsAdminEmailDisplayName) { + this.googleAppsSendFromEmailAddress = googleAppsSendFromEmailAddress; + this.googleAppsAdminEmailDisplayName = googleAppsAdminEmailDisplayName; + } + @NonFinalForTesting private static SendEmailService emailService = new SendEmailService(); /** - * Sends an email from Nomulus to the specified recipient. Returns true iff sending was + * Sends an email from Nomulus to the specified recipient(s). Returns true iff sending was * successful. */ - public static boolean sendEmail(String address, String subject, String body) { - return sendEmail(ImmutableList.of(address), subject, body); - } - - /** - * Sends an email from Nomulus to the specified recipients. Returns true iff sending was - * successful. - */ - public static boolean sendEmail(Iterable addresses, final String subject, String body) { + public boolean sendEmail(Iterable addresses, final String subject, String body) { try { Message msg = emailService.createMessage(); - msg.setFrom(new InternetAddress( - CONFIG.getGoogleAppsSendFromEmailAddress(), - CONFIG.getGoogleAppsAdminEmailDisplayName())); + msg.setFrom( + new InternetAddress(googleAppsSendFromEmailAddress, googleAppsAdminEmailDisplayName)); List emails = FluentIterable .from(addresses) .transform(new Function() { diff --git a/javatests/google/registry/config/RegistryEnvironmentTest.java b/javatests/google/registry/config/RegistryEnvironmentTest.java index 2ac763b9f..4a8a2267e 100644 --- a/javatests/google/registry/config/RegistryEnvironmentTest.java +++ b/javatests/google/registry/config/RegistryEnvironmentTest.java @@ -14,8 +14,6 @@ package google.registry.config; -import static com.google.common.truth.Truth.assertThat; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -28,14 +26,4 @@ public class RegistryEnvironmentTest { public void testGet() throws Exception { RegistryEnvironment.get(); } - - @Test - public void testOverride() throws Exception { - RegistryEnvironment.overrideConfigurationForTesting(new TestRegistryConfig() { - @Override - public String getSnapshotsBucket() { - return "black velvet"; - }}); - assertThat(RegistryEnvironment.get().config().getSnapshotsBucket()).isEqualTo("black velvet"); - } } diff --git a/javatests/google/registry/export/ExportSnapshotServletTest.java b/javatests/google/registry/export/ExportSnapshotServletTest.java index 9b26f2393..dbac0f174 100644 --- a/javatests/google/registry/export/ExportSnapshotServletTest.java +++ b/javatests/google/registry/export/ExportSnapshotServletTest.java @@ -19,10 +19,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import google.registry.config.TestRegistryConfig; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; -import google.registry.testing.RegistryConfigRule; import java.io.PrintWriter; import java.io.StringWriter; import javax.servlet.ServletConfig; @@ -43,12 +41,6 @@ public class ExportSnapshotServletTest { @Rule public final InjectRule inject = new InjectRule(); - @Rule - public final RegistryConfigRule configRule = new RegistryConfigRule(new TestRegistryConfig() { - @Override public String getSnapshotsBucket() { - return "Bucket-Id"; - }}); - @Mock private HttpServletRequest req; @@ -87,7 +79,7 @@ public class ExportSnapshotServletTest { verify(backupService).launchNewBackup( ExportSnapshotServlet.QUEUE, "auto_snapshot_20140801_010203", - "Bucket-Id", + "domain-registry-snapshots", ExportConstants.getBackupKinds()); verify(checkSnapshotServlet) .enqueuePollTask("auto_snapshot_20140801_010203", ExportConstants.getReportingKinds()); diff --git a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java index ffaca4f2c..f45431f1c 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -117,7 +117,6 @@ import google.registry.model.registry.label.ReservedList; import google.registry.model.reporting.HistoryEntry; import google.registry.model.smd.SignedMarkRevocationList; import google.registry.testing.DatastoreHelper; -import google.registry.testing.RegistryConfigRule; import google.registry.tmch.TmchCertificateAuthority; import java.util.Collections; import java.util.Comparator; @@ -128,7 +127,6 @@ import org.joda.time.DateTime; import org.joda.time.Interval; import org.junit.Before; import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; /** Unit tests for {@link DomainApplicationCreateFlow}. */ @@ -137,9 +135,6 @@ public class DomainApplicationCreateFlowTest private static final String CLAIMS_KEY = "2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001"; - @Rule - public final RegistryConfigRule configRule = new RegistryConfigRule(); - /** This is the id of the SMD stored in "domain_create_sunrise_encoded_signed_mark.xml". */ public static final String SMD_ID = "0000001761376042759136-65535"; diff --git a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java index b3817c299..64a2aabe9 100644 --- a/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java +++ b/javatests/google/registry/model/translators/CommitLogRevisionsTranslatorFactoryTest.java @@ -26,7 +26,6 @@ import com.googlecode.objectify.ObjectifyService; import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; import com.googlecode.objectify.annotation.Entity; -import google.registry.config.TestRegistryConfig; import google.registry.model.common.CrossTldSingleton; import google.registry.model.ofy.CommitLogManifest; import google.registry.model.ofy.Ofy; @@ -34,10 +33,8 @@ import google.registry.testing.AppEngineRule; import google.registry.testing.ExceptionRule; import google.registry.testing.FakeClock; import google.registry.testing.InjectRule; -import google.registry.testing.RegistryConfigRule; import java.util.List; import org.joda.time.DateTime; -import org.joda.time.Duration; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -66,15 +63,6 @@ public class CommitLogRevisionsTranslatorFactoryTest { @Rule public final ExceptionRule thrown = new ExceptionRule(); - @Rule - public final RegistryConfigRule configRule = new RegistryConfigRule( - new TestRegistryConfig() { - @Override - public Duration getCommitLogDatastoreRetention() { - return Duration.standardDays(30); - } - }); - private final FakeClock clock = new FakeClock(START_TIME); @Before diff --git a/javatests/google/registry/testing/RegistryConfigRule.java b/javatests/google/registry/testing/RegistryConfigRule.java index 9e7e3b4c0..d7fffa49b 100644 --- a/javatests/google/registry/testing/RegistryConfigRule.java +++ b/javatests/google/registry/testing/RegistryConfigRule.java @@ -22,6 +22,7 @@ import google.registry.config.RegistryEnvironment; import org.junit.rules.ExternalResource; /** JUnit Rule for overriding Nomulus configuration values. */ +@Deprecated // is obsoleted by YAML config; see b/33386530 for details public final class RegistryConfigRule extends ExternalResource { private final Optional override; diff --git a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java index b0c630541..bd1243e81 100644 --- a/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java +++ b/javatests/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java @@ -14,6 +14,8 @@ package google.registry.ui.server.registrar; +import static google.registry.config.ConfigModule.LocalTestConfig.GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME; +import static google.registry.config.ConfigModule.LocalTestConfig.GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS; import static google.registry.security.JsonHttpTestUtils.createJsonPayload; import static google.registry.security.JsonHttpTestUtils.createJsonResponseSupplier; import static google.registry.security.XsrfTokenManager.generateToken; @@ -100,6 +102,9 @@ public class RegistrarSettingsActionTestCase { ImmutableMap.of(), new JsonResponse(new ResponseImpl(rsp))); action.registrarChangesNotificationEmailAddresses = ImmutableList.of( "notification@test.example", "notification2@test.example"); + action.sendEmailUtils = + new SendEmailUtils( + GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS, GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME); inject.setStaticField(Ofy.class, "clock", clock); inject.setStaticField(SendEmailUtils.class, "emailService", emailService); inject.setStaticField(SyncRegistrarsSheetAction.class, "modulesService", modulesService); diff --git a/javatests/google/registry/util/BUILD b/javatests/google/registry/util/BUILD index 0725042bf..4b515a264 100644 --- a/javatests/google/registry/util/BUILD +++ b/javatests/google/registry/util/BUILD @@ -11,6 +11,7 @@ java_library( name = "util", srcs = glob(["*.java"]), deps = [ + "//java/google/registry/config", "//java/google/registry/util", "//javatests/google/registry/testing", "@com_google_appengine_api_1_0_sdk", diff --git a/javatests/google/registry/util/SendEmailUtilsTest.java b/javatests/google/registry/util/SendEmailUtilsTest.java index 5fea2a842..3190515cd 100644 --- a/javatests/google/registry/util/SendEmailUtilsTest.java +++ b/javatests/google/registry/util/SendEmailUtilsTest.java @@ -15,7 +15,6 @@ package google.registry.util; import static com.google.common.truth.Truth.assertThat; -import static google.registry.util.SendEmailUtils.sendEmail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; @@ -23,6 +22,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; +import google.registry.config.ConfigModule.LocalTestConfig; import google.registry.testing.ExceptionRule; import google.registry.testing.InjectRule; import java.util.Properties; @@ -53,20 +53,26 @@ public class SendEmailUtilsTest { private SendEmailService emailService; private Message message; + private SendEmailUtils sendEmailUtils; @Before public void init() throws Exception { inject.setStaticField(SendEmailUtils.class, "emailService", emailService); message = new MimeMessage(Session.getDefaultInstance(new Properties(), null)); when(emailService.createMessage()).thenReturn(message); + sendEmailUtils = new SendEmailUtils( + LocalTestConfig.GOOGLE_APPS_SEND_FROM_EMAIL_ADDRESS, + LocalTestConfig.GOOGLE_APPS_ADMIN_EMAIL_DISPLAY_NAME); } @Test public void testSuccess_sendToOneAddress() throws Exception { - assertThat(sendEmail( - "johnny@fakesite.tld", - "Welcome to the Internet", - "It is a dark and scary place.")).isTrue(); + assertThat( + sendEmailUtils.sendEmail( + ImmutableList.of("johnny@fakesite.tld"), + "Welcome to the Internet", + "It is a dark and scary place.")) + .isTrue(); verifyMessageSent(); assertThat(message.getRecipients(RecipientType.TO)).asList() .containsExactly(new InternetAddress("johnny@fakesite.tld")); @@ -76,10 +82,12 @@ public class SendEmailUtilsTest { @Test public void testSuccess_sendToMultipleAddresses() throws Exception { - assertThat(sendEmail( - ImmutableList.of("foo@example.com", "bar@example.com"), - "Welcome to the Internet", - "It is a dark and scary place.")).isTrue(); + assertThat( + sendEmailUtils.sendEmail( + ImmutableList.of("foo@example.com", "bar@example.com"), + "Welcome to the Internet", + "It is a dark and scary place.")) + .isTrue(); verifyMessageSent(); assertThat(message.getAllRecipients()).asList().containsExactly( new InternetAddress("foo@example.com"), @@ -88,10 +96,12 @@ public class SendEmailUtilsTest { @Test public void testSuccess_ignoresMalformedEmailAddress() throws Exception { - assertThat(sendEmail( - ImmutableList.of("foo@example.com", "1iñvalidemail"), - "Welcome to the Internet", - "It is a dark and scary place.")).isTrue(); + assertThat( + sendEmailUtils.sendEmail( + ImmutableList.of("foo@example.com", "1iñvalidemail"), + "Welcome to the Internet", + "It is a dark and scary place.")) + .isTrue(); verifyMessageSent(); assertThat(message.getAllRecipients()).asList() .containsExactly(new InternetAddress("foo@example.com")); @@ -99,22 +109,27 @@ public class SendEmailUtilsTest { @Test public void testFailure_onlyGivenMalformedAddress() throws Exception { - assertThat(sendEmail( - ImmutableList.of("1iñvalidemail"), - "Welcome to the Internet", - "It is a dark and scary place.")).isFalse(); + assertThat( + sendEmailUtils.sendEmail( + ImmutableList.of("1iñvalidemail"), + "Welcome to the Internet", + "It is a dark and scary place.")) + .isFalse(); verify(emailService, never()).sendMessage(any(Message.class)); } @Test public void testFailure_exceptionThrownDuringSend() throws Exception { doThrow(new MessagingException()).when(emailService).sendMessage(any(Message.class)); - assertThat(sendEmail( - ImmutableList.of("foo@example.com"), - "Welcome to the Internet", - "It is a dark and scary place.")).isFalse(); + assertThat( + sendEmailUtils.sendEmail( + ImmutableList.of("foo@example.com"), + "Welcome to the Internet", + "It is a dark and scary place.")) + .isFalse(); verifyMessageSent(); - assertThat(message.getAllRecipients()).asList() + assertThat(message.getAllRecipients()) + .asList() .containsExactly(new InternetAddress("foo@example.com")); }