From 22e1d905b6704193189153e14e6d49c86e8e9324 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Thu, 6 Sep 2018 13:20:21 -0700 Subject: [PATCH] Default to admin registrar in check_domain commands The vast majority of the time this is the registrar client ID you want, so there's no reason to require specifying it everything each time. These are read-only commands anyway, so the potential negative effects are minimal. See the existing lock/unlock_domain commands for existing occurrences of this behavior. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211857712 --- .../registry/tools/CheckDomainClaimsCommand.java | 15 +++++++++++++-- .../google/registry/tools/CheckDomainCommand.java | 15 +++++++++++++-- .../registry/tools/RegistryToolComponent.java | 2 ++ .../tools/CheckDomainClaimsCommandTest.java | 14 ++++++++++++-- .../registry/tools/CheckDomainCommandTest.java | 14 ++++++++++++-- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/java/google/registry/tools/CheckDomainClaimsCommand.java b/java/google/registry/tools/CheckDomainClaimsCommand.java index 799c1aa8b..5ec82b756 100644 --- a/java/google/registry/tools/CheckDomainClaimsCommand.java +++ b/java/google/registry/tools/CheckDomainClaimsCommand.java @@ -18,9 +18,11 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.collect.Multimap; import com.google.template.soy.data.SoyMapData; +import google.registry.config.RegistryConfig.Config; import google.registry.tools.soy.DomainCheckClaimsSoyInfo; import java.util.Collection; import java.util.List; +import javax.inject.Inject; /** A command to execute a domain check claims epp command. */ @Parameters(separators = " =", commandDescription = "Check claims on domain(s)") @@ -28,8 +30,8 @@ final class CheckDomainClaimsCommand extends NonMutatingEppToolCommand { @Parameter( names = {"-c", "--client"}, - description = "Client identifier of the registrar to execute the command as", - required = true) + description = + "Client ID of the registrar to execute the command as, otherwise the registry registrar") String clientId; @Parameter( @@ -37,8 +39,17 @@ final class CheckDomainClaimsCommand extends NonMutatingEppToolCommand { required = true) private List mainParameters; + @Inject + @Config("registryAdminClientId") + String registryAdminClientId; + @Override void initEppToolCommand() { + // Default clientId to the registry registrar account if otherwise unspecified. + if (clientId == null) { + clientId = registryAdminClientId; + } + Multimap domainNameMap = validateAndGroupDomainNamesByTld(mainParameters); for (Collection values : domainNameMap.asMap().values()) { setSoyTemplate( diff --git a/java/google/registry/tools/CheckDomainCommand.java b/java/google/registry/tools/CheckDomainCommand.java index d8377698f..40ee334f4 100644 --- a/java/google/registry/tools/CheckDomainCommand.java +++ b/java/google/registry/tools/CheckDomainCommand.java @@ -18,9 +18,11 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.google.common.collect.Multimap; import com.google.template.soy.data.SoyMapData; +import google.registry.config.RegistryConfig.Config; import google.registry.tools.soy.DomainCheckSoyInfo; import java.util.Collection; import java.util.List; +import javax.inject.Inject; /** A command to execute a domain check EPP command (including cost of a 1 year create). */ @Parameters(separators = " =", commandDescription = "Check domain availability") @@ -28,8 +30,8 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand { @Parameter( names = {"-c", "--client"}, - description = "Client identifier of the registrar to execute the command as", - required = true) + description = + "Client ID of the registrar to execute the command as, otherwise the registry registrar") String clientId; @Parameter( @@ -37,8 +39,17 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand { required = true) private List mainParameters; + @Inject + @Config("registryAdminClientId") + String registryAdminClientId; + @Override void initEppToolCommand() { + // Default clientId to the registry registrar account if otherwise unspecified. + if (clientId == null) { + clientId = registryAdminClientId; + } + Multimap domainNameMap = validateAndGroupDomainNamesByTld(mainParameters); for (Collection values : domainNameMap.asMap().values()) { setSoyTemplate(DomainCheckSoyInfo.getInstance(), DomainCheckSoyInfo.DOMAINCHECK); diff --git a/java/google/registry/tools/RegistryToolComponent.java b/java/google/registry/tools/RegistryToolComponent.java index b25a9cf0b..f3b89be95 100644 --- a/java/google/registry/tools/RegistryToolComponent.java +++ b/java/google/registry/tools/RegistryToolComponent.java @@ -76,6 +76,8 @@ import javax.inject.Singleton; WhoisModule.class, }) interface RegistryToolComponent { + void inject(CheckDomainClaimsCommand command); + void inject(CheckDomainCommand command); void inject(CheckSnapshotCommand command); void inject(CountDomainsCommand command); void inject(CreateAnchorTenantCommand command); diff --git a/javatests/google/registry/tools/CheckDomainClaimsCommandTest.java b/javatests/google/registry/tools/CheckDomainClaimsCommandTest.java index 34065f7ba..dc44d8906 100644 --- a/javatests/google/registry/tools/CheckDomainClaimsCommandTest.java +++ b/javatests/google/registry/tools/CheckDomainClaimsCommandTest.java @@ -14,14 +14,23 @@ package google.registry.tools; +import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; +import google.registry.model.registrar.Registrar.Type; +import org.junit.Before; import org.junit.Test; /** Unit tests for {@link CheckDomainClaimsCommand}. */ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase { + @Before + public void before() { + persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); + command.registryAdminClientId = "adminreg"; + } + @Test public void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "example.tld"); @@ -62,8 +71,9 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase runCommand("example.tld")); + public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception { + runCommand("example.tld"); + eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_claims.xml"); } @Test diff --git a/javatests/google/registry/tools/CheckDomainCommandTest.java b/javatests/google/registry/tools/CheckDomainCommandTest.java index f4168aeda..9de882626 100644 --- a/javatests/google/registry/tools/CheckDomainCommandTest.java +++ b/javatests/google/registry/tools/CheckDomainCommandTest.java @@ -14,14 +14,23 @@ package google.registry.tools; +import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static google.registry.testing.JUnitBackports.assertThrows; import com.beust.jcommander.ParameterException; +import google.registry.model.registrar.Registrar.Type; +import org.junit.Before; import org.junit.Test; /** Unit tests for {@link CheckDomainCommand}. */ public class CheckDomainCommandTest extends EppToolCommandTestCase { + @Before + public void before() { + persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L); + command.registryAdminClientId = "adminreg"; + } + @Test public void testSuccess() throws Exception { runCommand("--client=NewRegistrar", "example.tld"); @@ -62,8 +71,9 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase runCommand("example.tld")); + public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception { + runCommand("example.tld"); + eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_fee.xml"); } @Test