Move ROID suffix handling from RegistryConfig to ConfigModule

This is the first in a decently long series of commits to delete RegistryConfig
entirely and centralize all configuration in ConfigModule using Dagger. Once
this is done, then the text-based YAML configuration work can begin in earnest.

Note that the configuration settings from TestRegistryConfig will be moving
into ConfigModule.LocalTestConfig. This way they can be referred to in a static
context from test and test utility helpers, rather than having to be injected
everywhere, which we don't typically bother with for tests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143473089
This commit is contained in:
mcilwain 2017-01-03 12:30:12 -08:00 committed by Ben McIlwain
parent ab3f352782
commit 0b112f17a7
11 changed files with 43 additions and 46 deletions

View file

@ -113,6 +113,19 @@ public final class ConfigModule {
return "Nomulus"; return "Nomulus";
} }
/**
* Returns the roid suffix to be used for the roids of all contacts and hosts. E.g. a value of
* "ROID" would end up creating roids that look like "ABC123-ROID".
*
* @see <a href="http://www.iana.org/assignments/epp-repository-ids/epp-repository-ids.xhtml">
* Extensible Provisioning Protocol (EPP) Repository Identifiers</a>
*/
@Provides
@Config("contactAndHostRoidSuffix")
public static String provideContactAndHostRoidSuffix(RegistryEnvironment environment) {
return LocalTestConfig.CONTACT_AND_HOST_ROID_SUFFIX;
}
/** /**
* The e-mail address for questions about integrating with the registry. Used in the * The e-mail address for questions about integrating with the registry. Used in the
* "contact-us" section of the registrar console. * "contact-us" section of the registrar console.
@ -1007,4 +1020,10 @@ public final class ConfigModule {
.build()) .build())
.build(); .build();
} }
/** Config values used for local and unit test environments. */
public static class LocalTestConfig {
public static final String CONTACT_AND_HOST_ROID_SUFFIX = "ROID";
}
} }

View file

@ -158,11 +158,6 @@ public final class ProductionRegistryConfigExample implements RegistryConfig {
return Duration.millis(100); return Duration.millis(100);
} }
@Override
public String getContactAndHostRepositoryIdentifier() {
return "ROID";
}
@Override @Override
public Duration getContactAutomaticTransferLength() { public Duration getContactAutomaticTransferLength() {
return standardDays(5); return standardDays(5);

View file

@ -118,15 +118,6 @@ public interface RegistryConfig {
*/ */
public String getGoogleAppsSendFromEmailAddress(); public String getGoogleAppsSendFromEmailAddress();
/**
* Returns the roid suffix to be used for the roids of all contacts and hosts. E.g. a value of
* "ROID" would end up creating roids that look like "ABC123-ROID".
*
* @see <a href="http://www.iana.org/assignments/epp-repository-ids/epp-repository-ids.xhtml">
* Extensible Provisioning Protocol (EPP) Repository Identifiers</a>
*/
public String getContactAndHostRepositoryIdentifier();
/** /**
* Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}. * Returns default WHOIS server to use when {@code Registrar#getWhoisServer()} is {@code null}.
* *

View file

@ -116,11 +116,6 @@ public class TestRegistryConfig implements RegistryConfig {
return Duration.ZERO; return Duration.ZERO;
} }
@Override
public String getContactAndHostRepositoryIdentifier() {
return "ROID";
}
@Override @Override
public Duration getContactAutomaticTransferLength() { public Duration getContactAutomaticTransferLength() {
return standardDays(5); return standardDays(5);

View file

@ -18,10 +18,11 @@ import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist; import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist;
import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo; import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo;
import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy; import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy;
import static google.registry.model.EppResourceUtils.createContactHostRoid; import static google.registry.model.EppResourceUtils.createRepoId;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.ConfigModule.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.ExtensionManager; import google.registry.flows.ExtensionManager;
import google.registry.flows.FlowModule.ClientId; import google.registry.flows.FlowModule.ClientId;
@ -56,6 +57,7 @@ public final class ContactCreateFlow implements TransactionalFlow {
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject @Config("contactAndHostRoidSuffix") String roidSuffix;
@Inject ContactCreateFlow() {} @Inject ContactCreateFlow() {}
@Override @Override
@ -71,7 +73,7 @@ public final class ContactCreateFlow implements TransactionalFlow {
.setAuthInfo(command.getAuthInfo()) .setAuthInfo(command.getAuthInfo())
.setCreationClientId(clientId) .setCreationClientId(clientId)
.setCurrentSponsorClientId(clientId) .setCurrentSponsorClientId(clientId)
.setRepoId(createContactHostRoid(ObjectifyService.allocateId())) .setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix))
.setFaxNumber(command.getFax()) .setFaxNumber(command.getFax())
.setVoiceNumber(command.getVoice()) .setVoiceNumber(command.getVoice())
.setDisclose(command.getDisclose()) .setDisclose(command.getDisclose())

View file

@ -28,7 +28,7 @@ import static google.registry.flows.domain.DomainFlowUtils.validateDomainName;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables; import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables;
import static google.registry.flows.domain.DomainFlowUtils.validateSecDnsExtension; import static google.registry.flows.domain.DomainFlowUtils.validateSecDnsExtension;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears; import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.model.EppResourceUtils.createDomainRoid; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation; import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
@ -140,7 +140,7 @@ public class DomainAllocateFlow implements TransactionalFlow {
eppInput.getSingleExtension(AllocateCreateExtension.class); eppInput.getSingleExtension(AllocateCreateExtension.class);
DomainApplication application = DomainApplication application =
loadAndValidateApplication(allocateCreate.getApplicationRoid(), now); loadAndValidateApplication(allocateCreate.getApplicationRoid(), now);
String repoId = createDomainRoid(ObjectifyService.allocateId(), registry.getTldStr()); String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>(); ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
HistoryEntry historyEntry = buildHistory(repoId, period, now); HistoryEntry historyEntry = buildHistory(repoId, period, now);
entitiesToSave.add(historyEntry); entitiesToSave.add(historyEntry);

View file

@ -38,7 +38,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo
import static google.registry.flows.domain.DomainFlowUtils.verifyRegistryStateAllowsLaunchFlows; import static google.registry.flows.domain.DomainFlowUtils.verifyRegistryStateAllowsLaunchFlows;
import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks; import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears; import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.model.EppResourceUtils.createDomainRoid; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation; import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
@ -232,7 +232,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
.setCreationTrid(trid) .setCreationTrid(trid)
.setCreationClientId(clientId) .setCreationClientId(clientId)
.setCurrentSponsorClientId(clientId) .setCurrentSponsorClientId(clientId)
.setRepoId(createDomainRoid(ObjectifyService.allocateId(), tld)) .setRepoId(createDomainRepoId(ObjectifyService.allocateId(), tld))
.setLaunchNotice(launchCreate == null ? null : launchCreate.getNotice()) .setLaunchNotice(launchCreate == null ? null : launchCreate.getNotice())
.setIdnTableName(idnTableName) .setIdnTableName(idnTableName)
.setPhase(launchCreate.getPhase()) .setPhase(launchCreate.getPhase())

View file

@ -36,7 +36,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyNotReserved;
import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNotBlocked; import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNotBlocked;
import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks; import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears; import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.model.EppResourceUtils.createDomainRoid; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation; import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
@ -233,7 +233,7 @@ public class DomainCreateFlow implements TransactionalFlow {
} }
SecDnsCreateExtension secDnsCreate = SecDnsCreateExtension secDnsCreate =
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class)); validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
String repoId = createDomainRoid(ObjectifyService.allocateId(), registry.getTldStr()); String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
DateTime registrationExpirationTime = leapSafeAddYears(now, years); DateTime registrationExpirationTime = leapSafeAddYears(now, years);
HistoryEntry historyEntry = buildHistory(repoId, period, now); HistoryEntry historyEntry = buildHistory(repoId, period, now);
// Bill for the create. // Bill for the create.

View file

@ -19,7 +19,7 @@ import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist
import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain; import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain;
import static google.registry.flows.host.HostFlowUtils.validateHostName; import static google.registry.flows.host.HostFlowUtils.validateHostName;
import static google.registry.flows.host.HostFlowUtils.verifyDomainIsSameRegistrar; import static google.registry.flows.host.HostFlowUtils.verifyDomainIsSameRegistrar;
import static google.registry.model.EppResourceUtils.createContactHostRoid; import static google.registry.model.EppResourceUtils.createRepoId;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.CollectionUtils.isNullOrEmpty;
import static google.registry.util.CollectionUtils.union; import static google.registry.util.CollectionUtils.union;
@ -27,6 +27,7 @@ import static google.registry.util.CollectionUtils.union;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.ConfigModule.Config;
import google.registry.dns.DnsQueue; import google.registry.dns.DnsQueue;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.EppException.ParameterValueRangeErrorException; import google.registry.flows.EppException.ParameterValueRangeErrorException;
@ -81,6 +82,7 @@ public final class HostCreateFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject DnsQueue dnsQueue; @Inject DnsQueue dnsQueue;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject @Config("contactAndHostRoidSuffix") String roidSuffix;
@Inject HostCreateFlow() {} @Inject HostCreateFlow() {}
@Override @Override
@ -110,7 +112,7 @@ public final class HostCreateFlow implements TransactionalFlow {
.setCurrentSponsorClientId(clientId) .setCurrentSponsorClientId(clientId)
.setFullyQualifiedHostName(targetId) .setFullyQualifiedHostName(targetId)
.setInetAddresses(command.getInetAddresses()) .setInetAddresses(command.getInetAddresses())
.setRepoId(createContactHostRoid(ObjectifyService.allocateId())) .setRepoId(createRepoId(ObjectifyService.allocateId(), roidSuffix))
.setSuperordinateDomain( .setSuperordinateDomain(
superordinateDomain.isPresent() ? Key.create(superordinateDomain.get()) : null) superordinateDomain.isPresent() ? Key.create(superordinateDomain.get()) : null)
.build(); .build();

View file

@ -27,7 +27,6 @@ import com.google.common.base.Function;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.Result; import com.googlecode.objectify.Result;
import com.googlecode.objectify.util.ResultNow; import com.googlecode.objectify.util.ResultNow;
import google.registry.config.RegistryEnvironment;
import google.registry.model.EppResource.Builder; import google.registry.model.EppResource.Builder;
import google.registry.model.EppResource.BuilderWithTransferData; import google.registry.model.EppResource.BuilderWithTransferData;
import google.registry.model.EppResource.ForeignKeyedEppResource; import google.registry.model.EppResource.ForeignKeyedEppResource;
@ -55,20 +54,13 @@ public final class EppResourceUtils {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/** Returns the full domain repoId of the format HEX-TLD for the specified long id and tld. */ /** Returns the full domain repoId in the format HEX-TLD for the specified long id and tld. */
public static String createDomainRoid(long repoId, String tld) { public static String createDomainRepoId(long repoId, String tld) {
return createRoid(repoId, getRoidSuffixForTld(tld)); return createRepoId(repoId, getRoidSuffixForTld(tld));
} }
/** /** Returns the full repoId in the format HEX-TLD for the specified long id and ROID suffix. */
* Returns the full contact/host repoId of the format HEX-GOOGLE for the specified long repo id. public static String createRepoId(long repoId, String roidSuffix) {
*/
public static String createContactHostRoid(long repoId) {
return createRoid(
repoId, RegistryEnvironment.get().config().getContactAndHostRepositoryIdentifier());
}
private static String createRoid(long repoId, String roidSuffix) {
// %X is uppercase hexadecimal. // %X is uppercase hexadecimal.
return String.format("%X-%s", repoId, roidSuffix); return String.format("%X-%s", repoId, roidSuffix);
} }

View file

@ -20,9 +20,10 @@ import static com.google.common.base.Suppliers.memoize;
import static com.google.common.collect.Iterables.toArray; import static com.google.common.collect.Iterables.toArray;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.config.ConfigModule.LocalTestConfig.CONTACT_AND_HOST_ROID_SUFFIX;
import static google.registry.flows.ResourceFlowUtils.createTransferResponse; import static google.registry.flows.ResourceFlowUtils.createTransferResponse;
import static google.registry.model.EppResourceUtils.createContactHostRoid; import static google.registry.model.EppResourceUtils.createDomainRepoId;
import static google.registry.model.EppResourceUtils.createDomainRoid; import static google.registry.model.EppResourceUtils.createRepoId;
import static google.registry.model.domain.launch.ApplicationStatus.VALIDATED; import static google.registry.model.domain.launch.ApplicationStatus.VALIDATED;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost; import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
@ -736,7 +737,7 @@ public class DatastoreHelper {
/** Returns a newly allocated, globally unique domain repoId of the format HEX-TLD. */ /** Returns a newly allocated, globally unique domain repoId of the format HEX-TLD. */
public static String generateNewDomainRoid(String tld) { public static String generateNewDomainRoid(String tld) {
return createDomainRoid(ObjectifyService.allocateId(), tld); return createDomainRepoId(ObjectifyService.allocateId(), tld);
} }
/** /**
@ -744,7 +745,7 @@ public class DatastoreHelper {
* HEX_TLD-ROID. * HEX_TLD-ROID.
*/ */
public static String generateNewContactHostRoid() { public static String generateNewContactHostRoid() {
return createContactHostRoid(ObjectifyService.allocateId()); return createRepoId(ObjectifyService.allocateId(), CONTACT_AND_HOST_ROID_SUFFIX);
} }
/** /**