From 6e6a3401136198f966e2f0bff923053fae5dfe90 Mon Sep 17 00:00:00 2001 From: jianglai Date: Fri, 12 May 2017 07:17:26 -0700 Subject: [PATCH] Allow multiple domain creation in nomulus tool This helps creating test domains. Also fixed a bunch of bad test cases. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=155864065 --- docs/first-steps-tutorial.md | 13 ++- .../registry/tools/CreateDomainCommand.java | 42 +++++---- .../tools/CreateDomainCommandTest.java | 91 ++++++++++++------- .../testdata/domain_create_minimal_abc.xml | 18 ++++ 4 files changed, 108 insertions(+), 56 deletions(-) create mode 100644 javatests/google/registry/tools/testdata/domain_create_minimal_abc.xml diff --git a/docs/first-steps-tutorial.md b/docs/first-steps-tutorial.md index 4e13c9298..779031957 100644 --- a/docs/first-steps-tutorial.md +++ b/docs/first-steps-tutorial.md @@ -160,21 +160,20 @@ To tie it all together, let's create a domain name that uses the above contact and host. ```shell -$ nomulus -e alpha create_domain -c acme --domain fake.example \ - --admin abcd1234 --tech abcd1234 --registrant abcd1234 \ - --nameservers ns1.google.com +$ nomulus -e alpha create_domain fake.example --client acme --admin abcd1234 \ + --tech abcd1234 --registrant abcd1234 --nameservers ns1.google.com [ ... snip EPP response ... ] ``` Where: -* `create_domain` is the subcommand to create a domain name. -* `-c` is used to define the registrar. -* `--domain` is used to identify the domain name to be created. +* `create_domain` is the subcommand to create a domain name. It accepts a + whitespace-separted list of domain names to be created +* `--client` is used to define the registrar. * `--admin` is the administrative contact's id. * `--tech` is the technical contact's id. * `--registrant` is the registrant contact's id. -* `--nameservers` identifies the host. +* `--nameservers` is a comma-separated list of hosts. Note how the same contact id is used for the administrative, technical, and registrant contact. It is common for domain names to use the same details for diff --git a/java/google/registry/tools/CreateDomainCommand.java b/java/google/registry/tools/CreateDomainCommand.java index b4289e81d..72c9d7534 100644 --- a/java/google/registry/tools/CreateDomainCommand.java +++ b/java/google/registry/tools/CreateDomainCommand.java @@ -16,13 +16,17 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.isNullOrEmpty; +import static google.registry.util.CollectionUtils.findDuplicates; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; import com.google.template.soy.data.SoyMapData; import google.registry.tools.soy.DomainCreateSoyInfo; import google.registry.util.StringGenerator; import java.util.List; +import java.util.Set; import javax.inject.Inject; /** A command to create a new domain via EPP. */ @@ -35,11 +39,8 @@ final class CreateDomainCommand extends MutatingEppToolCommand { required = true) String clientId; - @Parameter( - names = "--domain", - description = "Domain name", - required = true) - private String domain; + @Parameter(description = "Names of the domains", required = true) + private List mainParameters; @Parameter( names = "--period", @@ -47,9 +48,9 @@ final class CreateDomainCommand extends MutatingEppToolCommand { private Integer period; @Parameter( - names = {"-n", "--nameservers"}, - description = "List of nameservers, up to 13.", - variableArity = true) + names = {"-n", "--nameservers"}, + description = "Comma-separated list of nameservers, up to 13." + ) private List ns; @Parameter( @@ -86,15 +87,22 @@ final class CreateDomainCommand extends MutatingEppToolCommand { password = passwordGenerator.createString(PASSWORD_LENGTH); } checkArgument(ns == null || ns.size() <= 13, "There can be at most 13 nameservers."); + String duplicates = Joiner.on(", ").join(findDuplicates(mainParameters)); + checkArgument(duplicates.isEmpty(), "Duplicate arguments found: '%s'", duplicates); + Set domains = ImmutableSet.copyOf(mainParameters); - setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE); - addSoyRecord(clientId, new SoyMapData( - "domain", domain, - "period", period == null ? null : period.toString(), - "ns", ns, - "registrant", registrant, - "admin", admin, - "tech", tech, - "password", password)); + for (String domain : domains) { + setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE); + addSoyRecord( + clientId, + new SoyMapData( + "domain", domain, + "period", period == null ? null : period.toString(), + "ns", ns, + "registrant", registrant, + "admin", admin, + "tech", tech, + "password", password)); + } } } diff --git a/javatests/google/registry/tools/CreateDomainCommandTest.java b/javatests/google/registry/tools/CreateDomainCommandTest.java index 2b092df98..8a0556b05 100644 --- a/javatests/google/registry/tools/CreateDomainCommandTest.java +++ b/javatests/google/registry/tools/CreateDomainCommandTest.java @@ -31,13 +31,13 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase + + + + + example.abc + crr-admin + crr-admin + crr-tech + + abcdefghijklmnop + + + + RegistryTool + +