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
This commit is contained in:
mcilwain 2018-09-06 13:20:21 -07:00 committed by jianglai
parent 72bfd43e00
commit 22e1d905b6
5 changed files with 52 additions and 8 deletions

View file

@ -18,9 +18,11 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.template.soy.data.SoyMapData; import com.google.template.soy.data.SoyMapData;
import google.registry.config.RegistryConfig.Config;
import google.registry.tools.soy.DomainCheckClaimsSoyInfo; import google.registry.tools.soy.DomainCheckClaimsSoyInfo;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import javax.inject.Inject;
/** A command to execute a domain check claims epp command. */ /** A command to execute a domain check claims epp command. */
@Parameters(separators = " =", commandDescription = "Check claims on domain(s)") @Parameters(separators = " =", commandDescription = "Check claims on domain(s)")
@ -28,8 +30,8 @@ final class CheckDomainClaimsCommand extends NonMutatingEppToolCommand {
@Parameter( @Parameter(
names = {"-c", "--client"}, names = {"-c", "--client"},
description = "Client identifier of the registrar to execute the command as", description =
required = true) "Client ID of the registrar to execute the command as, otherwise the registry registrar")
String clientId; String clientId;
@Parameter( @Parameter(
@ -37,8 +39,17 @@ final class CheckDomainClaimsCommand extends NonMutatingEppToolCommand {
required = true) required = true)
private List<String> mainParameters; private List<String> mainParameters;
@Inject
@Config("registryAdminClientId")
String registryAdminClientId;
@Override @Override
void initEppToolCommand() { void initEppToolCommand() {
// Default clientId to the registry registrar account if otherwise unspecified.
if (clientId == null) {
clientId = registryAdminClientId;
}
Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters); Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters);
for (Collection<String> values : domainNameMap.asMap().values()) { for (Collection<String> values : domainNameMap.asMap().values()) {
setSoyTemplate( setSoyTemplate(

View file

@ -18,9 +18,11 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.template.soy.data.SoyMapData; import com.google.template.soy.data.SoyMapData;
import google.registry.config.RegistryConfig.Config;
import google.registry.tools.soy.DomainCheckSoyInfo; import google.registry.tools.soy.DomainCheckSoyInfo;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import javax.inject.Inject;
/** A command to execute a domain check EPP command (including cost of a 1 year create). */ /** A command to execute a domain check EPP command (including cost of a 1 year create). */
@Parameters(separators = " =", commandDescription = "Check domain availability") @Parameters(separators = " =", commandDescription = "Check domain availability")
@ -28,8 +30,8 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand {
@Parameter( @Parameter(
names = {"-c", "--client"}, names = {"-c", "--client"},
description = "Client identifier of the registrar to execute the command as", description =
required = true) "Client ID of the registrar to execute the command as, otherwise the registry registrar")
String clientId; String clientId;
@Parameter( @Parameter(
@ -37,8 +39,17 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand {
required = true) required = true)
private List<String> mainParameters; private List<String> mainParameters;
@Inject
@Config("registryAdminClientId")
String registryAdminClientId;
@Override @Override
void initEppToolCommand() { void initEppToolCommand() {
// Default clientId to the registry registrar account if otherwise unspecified.
if (clientId == null) {
clientId = registryAdminClientId;
}
Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters); Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters);
for (Collection<String> values : domainNameMap.asMap().values()) { for (Collection<String> values : domainNameMap.asMap().values()) {
setSoyTemplate(DomainCheckSoyInfo.getInstance(), DomainCheckSoyInfo.DOMAINCHECK); setSoyTemplate(DomainCheckSoyInfo.getInstance(), DomainCheckSoyInfo.DOMAINCHECK);

View file

@ -76,6 +76,8 @@ import javax.inject.Singleton;
WhoisModule.class, WhoisModule.class,
}) })
interface RegistryToolComponent { interface RegistryToolComponent {
void inject(CheckDomainClaimsCommand command);
void inject(CheckDomainCommand command);
void inject(CheckSnapshotCommand command); void inject(CheckSnapshotCommand command);
void inject(CountDomainsCommand command); void inject(CountDomainsCommand command);
void inject(CreateAnchorTenantCommand command); void inject(CreateAnchorTenantCommand command);

View file

@ -14,14 +14,23 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.model.registrar.Registrar.Type;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** Unit tests for {@link CheckDomainClaimsCommand}. */ /** Unit tests for {@link CheckDomainClaimsCommand}. */
public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDomainClaimsCommand> { public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDomainClaimsCommand> {
@Before
public void before() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
@Test @Test
public void testSuccess() throws Exception { public void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "example.tld"); runCommand("--client=NewRegistrar", "example.tld");
@ -62,8 +71,9 @@ public class CheckDomainClaimsCommandTest extends EppToolCommandTestCase<CheckDo
} }
@Test @Test
public void testFailure_missingClientId() { public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
assertThrows(ParameterException.class, () -> runCommand("example.tld")); runCommand("example.tld");
eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_claims.xml");
} }
@Test @Test

View file

@ -14,14 +14,23 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.model.registrar.Registrar.Type;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** Unit tests for {@link CheckDomainCommand}. */ /** Unit tests for {@link CheckDomainCommand}. */
public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCommand> { public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCommand> {
@Before
public void before() {
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
@Test @Test
public void testSuccess() throws Exception { public void testSuccess() throws Exception {
runCommand("--client=NewRegistrar", "example.tld"); runCommand("--client=NewRegistrar", "example.tld");
@ -62,8 +71,9 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCo
} }
@Test @Test
public void testFailure_missingClientId() { public void testSuccess_unspecifiedClientId_defaultsToRegistryRegistrar() throws Exception {
assertThrows(ParameterException.class, () -> runCommand("example.tld")); runCommand("example.tld");
eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_fee.xml");
} }
@Test @Test