Move registry policy settings and some others into YAML config

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145571850
This commit is contained in:
mcilwain 2017-01-25 11:19:47 -08:00 committed by Ben McIlwain
parent efedc03d45
commit f647ea1190
15 changed files with 131 additions and 109 deletions

View file

@ -20,7 +20,6 @@ import static google.registry.config.YamlUtils.getConfigSettings;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.joda.time.Duration.standardDays;
import com.google.appengine.api.utils.SystemProperty;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
@ -132,9 +131,8 @@ public final class RegistryConfig {
*/
@Provides
@Config("integrationEmail")
public static String provideIntegrationEmail(RegistryEnvironment environment) {
// Change this to your integration email address.
return "integration@example.com";
public static String provideIntegrationEmail(RegistryConfigSettings config) {
return config.registrarConsole.integrationEmailAddress;
}
/**
@ -145,9 +143,8 @@ public final class RegistryConfig {
*/
@Provides
@Config("supportEmail")
public static String provideSupportEmail(RegistryEnvironment environment) {
// Change this to your support email address.
return "support@example.com";
public static String provideSupportEmail(RegistryConfigSettings config) {
return config.registrarConsole.supportEmailAddress;
}
/**
@ -158,9 +155,8 @@ public final class RegistryConfig {
*/
@Provides
@Config("announcementsEmail")
public static String provideAnnouncementsEmail(RegistryEnvironment environment) {
// Change this to your announcements e-mail.
return "announcements@example.com";
public static String provideAnnouncementsEmail(RegistryConfigSettings config) {
return config.registrarConsole.announcementsEmailAddress;
}
/**
@ -170,9 +166,8 @@ public final class RegistryConfig {
*/
@Provides
@Config("supportPhoneNumber")
public static String provideSupportPhoneNumber(RegistryEnvironment environment) {
// Change this to your phone number.
return "+1 (888) 555 0123";
public static String provideSupportPhoneNumber(RegistryConfigSettings config) {
return config.registrarConsole.supportPhoneNumber;
}
/**
@ -183,9 +178,8 @@ public final class RegistryConfig {
*/
@Provides
@Config("technicalDocsUrl")
public static String provideTechnicalDocsUrl(RegistryEnvironment environment) {
// Change this to your support docs link.
return "http://example.com/your_support_docs/";
public static String provideTechnicalDocsUrl(RegistryConfigSettings config) {
return config.registrarConsole.technicalDocsUrl;
}
/**
@ -372,15 +366,15 @@ public final class RegistryConfig {
}
/**
* Gets the email address of the admin account for the Google App.
* Returns the email address of the admin account on the G Suite app used to perform
* administrative actions.
*
* @see google.registry.groups.DirectoryGroupsConnection
*/
@Provides
@Config("googleAppsAdminEmailAddress")
public static String provideGoogleAppsAdminEmailAddress(RegistryEnvironment environment) {
// Change this to your admin account.
return "admin@example.com";
@Config("gSuiteAdminAccountEmailAddress")
public static String provideGSuiteAdminAccountEmailAddress(RegistryConfigSettings config) {
return config.gSuite.adminAccountEmailAddress;
}
/**
@ -392,29 +386,20 @@ public final class RegistryConfig {
@Provides
@Config("registrarChangesNotificationEmailAddresses")
public static ImmutableList<String> provideRegistrarChangesNotificationEmailAddresses(
RegistryEnvironment environment) {
switch (environment) {
case PRODUCTION:
// Change this to an appropriate notification e-mail address.
return ImmutableList.of("notification@registry.example");
case UNITTEST:
return ImmutableList.of("notification@test.example", "notification2@test.example");
default:
return ImmutableList.<String>of();
}
RegistryConfigSettings config) {
return ImmutableList.copyOf(config.registryPolicy.registrarChangesNotificationEmailAddresses);
}
/**
* Returns the publicly accessible domain name for the running Google Apps instance.
* Returns the publicly accessible domain name for the running G Suite instance.
*
* @see google.registry.export.SyncGroupMembersAction
* @see google.registry.tools.server.CreateGroupsAction
*/
@Provides
@Config("publicDomainName")
public static String providePublicDomainName(RegistryEnvironment environment) {
// Change this to your domain name.
return "registry.example.com";
@Config("gSuiteDomainName")
public static String provideGSuiteDomainName(RegistryConfigSettings config) {
return config.gSuite.domainName;
}
/**
@ -490,9 +475,9 @@ public final class RegistryConfig {
* @see google.registry.ui.server.registrar.SendEmailUtils
*/
@Provides
@Config("googleAppsSendFromEmailAddress")
public static String provideGoogleAppsSendFromEmailAddress() {
return String.format("noreply@%s.appspotmail.com", SystemProperty.applicationId.get());
@Config("gSuiteOutgoingEmailAddress")
public static String provideGSuiteOutgoingEmailAddress(RegistryConfigSettings config) {
return config.gSuite.outgoingEmailAddress;
}
/**
@ -501,10 +486,9 @@ public final class RegistryConfig {
* @see google.registry.ui.server.registrar.SendEmailUtils
*/
@Provides
@Config("googleAppsAdminEmailDisplayName")
public static String provideGoogleAppsAdminEmailDisplayName() {
// Production example: "Example Registry"
return "Google Domain Registry";
@Config("gSuiteOutoingEmailDisplayName")
public static String provideGSuiteOutgoingEmailDisplayName(RegistryConfigSettings config) {
return config.gSuite.outgoingEmailDisplayName;
}
/**
@ -1214,25 +1198,15 @@ public final class RegistryConfig {
* @see "google.registry.whois.DomainWhoisResponse"
* @see "google.registry.whois.RegistrarWhoisResponse"
*/
public static String getRegistrarDefaultWhoisServer() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return "whois.nic.fakewhois.example";
default:
return "whois.nic.registry.example";
}
public static String getDefaultRegistrarWhoisServer() {
return CONFIG_SETTINGS.get().registryPolicy.defaultRegistrarWhoisServer;
}
/**
* Returns the default referral URL that is used unless registrars have specified otherwise.
*/
public static URL getRegistrarDefaultReferralUrl() {
switch (RegistryEnvironment.get()) {
case UNITTEST:
return makeUrl("http://www.referral.example/path");
default:
return makeUrl("https://www.registry.example");
}
public static String getDefaultRegistrarReferralUrl() {
return CONFIG_SETTINGS.get().registryPolicy.defaultRegistrarReferralUrl;
}
/**

View file

@ -14,54 +14,60 @@
package google.registry.config;
import java.util.List;
/** The POJO that YAML config files are deserialized into. */
public class RegistryConfigSettings {
public AppEngine appEngine;
public GSuite gSuite;
public RegistryPolicy registryPolicy;
public Datastore datastore;
public RegistrarConsole registrarConsole;
public Monitoring monitoring;
/** Configuration options that apply to the entire App Engine project. */
public static class AppEngine {
public String projectId;
}
/** Configuration options for the G Suite account used by Nomulus. */
public static class GSuite {
public String domainName;
public String outgoingEmailAddress;
public String outgoingEmailDisplayName;
public String adminAccountEmailAddress;
}
/** Configuration options for registry policy. */
public static class RegistryPolicy {
public String contactAndHostRoidSuffix;
public String productName;
public List<String> registrarChangesNotificationEmailAddresses;
public String defaultRegistrarWhoisServer;
public String defaultRegistrarReferralUrl;
}
/** Configuration for Cloud Datastore. */
public static class Datastore {
public int commitLogBucketsNum;
public int eppResourceIndexBucketsNum;
}
/** Configuration for the web-based registrar console. */
public static class RegistrarConsole {
public String logoFilename;
public String supportPhoneNumber;
public String supportEmailAddress;
public String announcementsEmailAddress;
public String integrationEmailAddress;
public String technicalDocsUrl;
}
/** Configuration for monitoring. */
public static class Monitoring {
public int stackdriverMaxQps;
public int stackdriverMaxPointsPerRequest;
public int writeIntervalSeconds;
}
}

View file

@ -7,6 +7,18 @@ appEngine:
# Globally unique App Engine project ID
projectId: domain-registry
gSuite:
# Publicly accessible domain name of the running G Suite instance.
domainName: domain-registry.example
# Display name and email address used on outgoing emails through G Suite.
outgoingEmailDisplayName: Example Registry
outgoingEmailAddress: noreply@project-id.appspotmail.com
# Email address of the admin account on the G Suite app. This is used for
# logging in to perform administrative actions, not sending emails.
adminAccountEmailAddress: admin@example.com
registryPolicy:
# Repository identifier (ROID) suffix for contacts and hosts.
contactAndHostRoidSuffix: ROID
@ -14,6 +26,16 @@ registryPolicy:
# Product name of the registry. Used throughout the registrar console.
productName: Nomulus
# List of email addresses that notifications of registrar and/or registrar
# contact updates should be sent to, or empty list for no notifications.
registrarChangesNotificationEmailAddresses: []
# Default WHOIS server used when not specified on a registrar.
defaultRegistrarWhoisServer: whois.domain-registry.example
# Default referral URL used when not changed by a registrar.
defaultRegistrarReferralUrl: https://www.domain-registry.example
datastore:
# Number of commit log buckets in Datastore. Don't change after initial
# install.
@ -28,6 +50,21 @@ registrarConsole:
# relative to ui/assets/images/
logoFilename: logo.png
# Contact phone number for support with the registry.
supportPhoneNumber: +1 (888) 555 0123
# Contact email address for support with the registry.
supportEmailAddress: support@example.com
# From: email address used to send announcements from the registry.
announcementsEmailAddress: announcements@example.com
# Contact email address for questions about integrating with the registry.
integrationEmailAddress: integration@example.com
# URL linking to directory of technical support docs on the registry.
technicalDocsUrl: http://example.com/your_support_docs/
monitoring:
# Max queries per second for the Google Cloud Monitoring V3 (aka Stackdriver)
# API. The limit can be adjusted by contacting Cloud Support.

View file

@ -1,6 +1,13 @@
# This is the configuration file used by unit tests. These values ARE NOT
# SUITABLE for use in a real deployed environment.
registryPolicy:
registrarChangesNotificationEmailAddresses:
- notification@test.example
- notification2@test.example
defaultRegistrarWhoisServer: whois.nic.fakewhois.example
defaultRegistrarReferralUrl: http://www.referral.example/path
datastore:
commitLogBucketsNum: 3
eppResourceIndexBucketsNum: 3

View file

@ -57,7 +57,6 @@ public final class SyncGroupMembersAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private enum Result {
OK(SC_OK, "Group memberships successfully updated."),
NOT_MODIFIED(SC_OK, "No registrar contacts have been updated since the last time servlet ran."),
@ -82,7 +81,7 @@ public final class SyncGroupMembersAction implements Runnable {
}
@Inject GroupsConnection groupsConnection;
@Inject @Config("publicDomainName") String publicDomainName;
@Inject @Config("gSuiteDomainName") String gSuiteDomainName;
@Inject Response response;
@Inject Retrier retrier;
@Inject SyncGroupMembersAction() {}
@ -100,13 +99,12 @@ public final class SyncGroupMembersAction implements Runnable {
* RegistrarContact.Type
*/
public static String getGroupEmailAddressForContactType(
String clientId,
RegistrarContact.Type type,
String publicDomainName) {
String clientId, RegistrarContact.Type type, String gSuiteDomainName) {
// Take the registrar's clientId, make it lowercase, and remove all characters that aren't
// alphanumeric, hyphens, or underscores.
return String.format(
"%s-%s-contacts@%s", normalizeClientId(clientId), type.getDisplayName(), publicDomainName);
"%s-%s-contacts@%s",
normalizeClientId(clientId), type.getDisplayName(), gSuiteDomainName);
}
/**
@ -188,7 +186,7 @@ public final class SyncGroupMembersAction implements Runnable {
long totalRemoved = 0;
for (final RegistrarContact.Type type : RegistrarContact.Type.values()) {
groupKey = getGroupEmailAddressForContactType(
registrar.getClientId(), type, publicDomainName);
registrar.getClientId(), type, gSuiteDomainName);
Set<String> currentMembers = groupsConnection.getMembersOfGroup(groupKey);
Set<String> desiredMembers = FluentIterable.from(registrarContacts)
.filter(new Predicate<RegistrarContact>() {

View file

@ -63,7 +63,7 @@ public class DirectoryGroupsConnection implements GroupsConnection {
@Inject Directory directory;
@Inject Groupssettings groupsSettings;
@Inject @Config("googleAppsAdminEmailAddress") String googleAppsAdminEmailAddress;
@Inject @Config("gSuiteAdminAccountEmailAddress") String gSuiteAdminAccountEmailAddress;
@Inject DirectoryGroupsConnection() {}
@Override
@ -152,7 +152,7 @@ public class DirectoryGroupsConnection implements GroupsConnection {
group.setEmail(groupKey);
try {
Group createdGroup = directory.groups().insert(group).execute();
addMemberToGroup(groupKey, googleAppsAdminEmailAddress, Role.OWNER);
addMemberToGroup(groupKey, gSuiteAdminAccountEmailAddress, Role.OWNER);
groupsSettings.groups().patch(groupKey, defaultGroupPermissions).execute();
return createdGroup;
} catch (GoogleJsonResponseException e) {

View file

@ -24,8 +24,8 @@ 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.getRegistrarDefaultReferralUrl;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
import static google.registry.config.RegistryConfig.getDefaultRegistrarWhoisServer;
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;
@ -445,7 +445,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}
public String getWhoisServer() {
return firstNonNull(whoisServer, getRegistrarDefaultWhoisServer());
return firstNonNull(whoisServer, getDefaultRegistrarWhoisServer());
}
public boolean getBlockPremiumNames() {
@ -461,7 +461,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
}
public String getReferralUrl() {
return firstNonNull(referralUrl, getRegistrarDefaultReferralUrl().toString());
return firstNonNull(referralUrl, getDefaultRegistrarReferralUrl());
}
public String getIcannReferralEmail() {

View file

@ -223,7 +223,7 @@ public final class Modules {
static GoogleCredential provideDelegatedAdminGoogleCredential(
GoogleCredential googleCredential,
HttpTransport httpTransport,
@Config("googleAppsAdminEmailAddress") String googleAppsAdminEmailAddress) {
@Config("gSuiteAdminAccountEmailAddress") String gSuiteAdminAccountEmailAddress) {
return new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(googleCredential.getJsonFactory())
@ -234,7 +234,7 @@ public final class Modules {
// is thus the responsibility of every user of a delegated admin credential to call
// createScoped() on it first to get the version with the correct scopes set.
.setServiceAccountScopes(ImmutableSet.<String>of())
.setServiceAccountUser(googleAppsAdminEmailAddress)
.setServiceAccountUser(gSuiteAdminAccountEmailAddress)
.build();
}
}

View file

@ -52,7 +52,7 @@ public class CreateGroupsAction implements Runnable {
@Inject GroupsConnection groupsConnection;
@Inject Response response;
@Inject @Config("publicDomainName") String publicDomainName;
@Inject @Config("gSuiteDomainName") String gSuiteDomainName;
@Inject @Parameter("clientId") Optional<String> clientId;
@Inject CreateGroupsAction() {}
@ -73,9 +73,9 @@ public class CreateGroupsAction implements Runnable {
public Optional<Exception> apply(Type type) {
try {
String groupKey = getGroupEmailAddressForContactType(
registrar.getClientId(), type, publicDomainName);
registrar.getClientId(), type, gSuiteDomainName);
String parentGroup =
getGroupEmailAddressForContactType("registrar", type, publicDomainName);
getGroupEmailAddressForContactType("registrar", type, gSuiteDomainName);
// Creates the group, then adds it as a member to the global registrar group for
// that type.
groupsConnection.createGroup(groupKey);

View file

@ -37,15 +37,15 @@ public class SendEmailUtils {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private final String googleAppsSendFromEmailAddress;
private final String googleAppsAdminEmailDisplayName;
private final String gSuiteOutgoingEmailAddress;
private final String gSuiteOutoingEmailDisplayName;
@Inject
public SendEmailUtils(
@Config("googleAppsSendFromEmailAddress") String googleAppsSendFromEmailAddress,
@Config("googleAppsAdminEmailDisplayName") String googleAppsAdminEmailDisplayName) {
this.googleAppsSendFromEmailAddress = googleAppsSendFromEmailAddress;
this.googleAppsAdminEmailDisplayName = googleAppsAdminEmailDisplayName;
@Config("gSuiteOutgoingEmailAddress") String gSuiteOutgoingEmailAddress,
@Config("gSuiteOutoingEmailDisplayName") String gSuiteOutoingEmailDisplayName) {
this.gSuiteOutgoingEmailAddress = gSuiteOutgoingEmailAddress;
this.gSuiteOutoingEmailDisplayName = gSuiteOutoingEmailDisplayName;
}
@NonFinalForTesting
@ -59,7 +59,7 @@ public class SendEmailUtils {
try {
Message msg = emailService.createMessage();
msg.setFrom(
new InternetAddress(googleAppsSendFromEmailAddress, googleAppsAdminEmailDisplayName));
new InternetAddress(gSuiteOutgoingEmailAddress, gSuiteOutoingEmailDisplayName));
List<InternetAddress> emails = FluentIterable
.from(addresses)
.transform(new Function<String, InternetAddress>() {

View file

@ -80,7 +80,7 @@ public class SyncGroupMembersActionTest {
private void runAction() {
SyncGroupMembersAction action = new SyncGroupMembersAction();
action.groupsConnection = connection;
action.publicDomainName = "domain-registry.example";
action.gSuiteDomainName = "domain-registry.example";
action.response = response;
action.retrier = new Retrier(new FakeSleeper(new FakeClock()), 3);
action.run();

View file

@ -16,8 +16,8 @@ package google.registry.export.sheet;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getRegistrarDefaultReferralUrl;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
import static google.registry.config.RegistryConfig.getDefaultRegistrarWhoisServer;
import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEET;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
@ -262,8 +262,8 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/aaa_registrar");
assertThat(row).containsEntry("icannReferralEmail", "");
assertThat(row).containsEntry("whoisServer", getRegistrarDefaultWhoisServer());
assertThat(row).containsEntry("referralUrl", getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("whoisServer", getDefaultRegistrarWhoisServer());
assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl());
row = rows.get(1);
assertThat(row).containsEntry("clientIdentifier", "anotherregistrar");
@ -295,7 +295,7 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "http://www.example.org/another_registrar");
assertThat(row).containsEntry("referralUrl", getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl());
assertThat(row).containsEntry("icannReferralEmail", "jim@example.net");
Cursor cursor = ofy().load().key(Cursor.createGlobalKey(SYNC_REGISTRAR_SHEET)).now();
@ -338,11 +338,11 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("phoneNumber", "");
assertThat(row).containsEntry("faxNumber", "");
assertThat(row).containsEntry("allowedTlds", "");
assertThat(row).containsEntry("whoisServer", getRegistrarDefaultWhoisServer());
assertThat(row).containsEntry("whoisServer", getDefaultRegistrarWhoisServer());
assertThat(row).containsEntry("blockPremiumNames", "false");
assertThat(row).containsEntry("ipAddressWhitelist", "");
assertThat(row).containsEntry("url", "");
assertThat(row).containsEntry("referralUrl", getRegistrarDefaultReferralUrl().toString());
assertThat(row).containsEntry("referralUrl", getDefaultRegistrarReferralUrl());
assertThat(row).containsEntry("icannReferralEmail", "");
}
}

View file

@ -114,7 +114,7 @@ public class DirectoryGroupsConnectionTest {
connection = new DirectoryGroupsConnection();
connection.directory = directory;
connection.groupsSettings = groupsSettings;
connection.googleAppsAdminEmailAddress = "admin@domain-registry.example";
connection.gSuiteAdminAccountEmailAddress = "admin@domain-registry.example";
expectedOwner.setEmail("admin@domain-registry.example");
expectedOwner.setRole("OWNER");
}

View file

@ -63,7 +63,7 @@ public class CreateGroupsActionTest {
CreateGroupsAction action = new CreateGroupsAction();
action.response = response;
action.groupsConnection = connection;
action.publicDomainName = "domain-registry.example";
action.gSuiteDomainName = "domain-registry.example";
action.clientId = Optional.fromNullable(clientId);
action.run();
}

View file

@ -15,8 +15,8 @@
package google.registry.ui.server.registrar;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.config.RegistryConfig.getRegistrarDefaultReferralUrl;
import static google.registry.config.RegistryConfig.getRegistrarDefaultWhoisServer;
import static google.registry.config.RegistryConfig.getDefaultRegistrarReferralUrl;
import static google.registry.config.RegistryConfig.getDefaultRegistrarWhoisServer;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2_HASH;
@ -52,8 +52,8 @@ public class SecuritySettingsTest extends RegistrarSettingsActionTestCase {
modified =
modified
.asBuilder()
.setWhoisServer(getRegistrarDefaultWhoisServer())
.setReferralUrl(getRegistrarDefaultReferralUrl().toString())
.setWhoisServer(getDefaultRegistrarWhoisServer())
.setReferralUrl(getDefaultRegistrarReferralUrl())
.build();
assertThat(response).containsEntry("status", "SUCCESS");
assertThat(response).containsEntry("results", asList(modified.toJsonMap()));