mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Add create_domain command to gtech_tool
Support creating domain with gtech_tool, instead of creating temporary epp file and run execute_epp manually. Also changes CreateContactCommand for consistency. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130127280
This commit is contained in:
parent
0066a03709
commit
5f26196993
9 changed files with 331 additions and 12 deletions
|
@ -37,43 +37,43 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech
|
||||||
String clientIdentifier;
|
String clientIdentifier;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--id"},
|
names = {"-i", "--id"},
|
||||||
description = "Contact ID.")
|
description = "Contact ID.")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--name"},
|
names = {"-n", "--name"},
|
||||||
description = "Contact name.")
|
description = "Contact name.")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--org"},
|
names = {"-o", "--org"},
|
||||||
description = "Organization")
|
description = "Organization")
|
||||||
private String org;
|
private String org;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--street"},
|
names = "--street",
|
||||||
description = "Street lines of address. Can take up to 3 lines.",
|
description = "Street lines of address. Can take up to 3 lines.",
|
||||||
variableArity = true)
|
variableArity = true)
|
||||||
private List<String> street;
|
private List<String> street;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--city"},
|
names = "--city",
|
||||||
description = "City of address.")
|
description = "City of address.")
|
||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--state"},
|
names = "--state",
|
||||||
description = "State of address.")
|
description = "State of address.")
|
||||||
private String state;
|
private String state;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--zip"},
|
names = {"-z", "--zip"},
|
||||||
description = "Postal code of address.")
|
description = "Postal code of address.")
|
||||||
private String zip;
|
private String zip;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--cc"},
|
names = "--cc",
|
||||||
description = "Country code of address.")
|
description = "Country code of address.")
|
||||||
private String cc;
|
private String cc;
|
||||||
|
|
||||||
|
@ -92,12 +92,12 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech
|
||||||
String fax;
|
String fax;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--email"},
|
names = {"-e", "--email"},
|
||||||
description = "Email address.")
|
description = "Email address.")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"--password"},
|
names = {"-p", "--password"},
|
||||||
description = "Password. Optional, randomly generated if not provided.")
|
description = "Password. Optional, randomly generated if not provided.")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
99
java/google/registry/tools/CreateDomainCommand.java
Normal file
99
java/google/registry/tools/CreateDomainCommand.java
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package google.registry.tools;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
|
|
||||||
|
import com.beust.jcommander.Parameter;
|
||||||
|
import com.beust.jcommander.Parameters;
|
||||||
|
import com.google.template.soy.data.SoyMapData;
|
||||||
|
import google.registry.tools.Command.GtechCommand;
|
||||||
|
import google.registry.tools.soy.CreateDomainSoyInfo;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/** A command to create a new domain via EPP. */
|
||||||
|
@Parameters(separators = " =", commandDescription = "Create a new domain via EPP.")
|
||||||
|
final class CreateDomainCommand extends MutatingEppToolCommand implements GtechCommand {
|
||||||
|
@Parameter(names = {"-c", "--client"},
|
||||||
|
description = "Client identifier of the registrar to execute the command as",
|
||||||
|
required = true)
|
||||||
|
String clientIdentifier;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = "--domain",
|
||||||
|
description = "Domain name",
|
||||||
|
required = true)
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = "--period",
|
||||||
|
description = "Initial registration period, in years.")
|
||||||
|
private Integer period;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"-n", "--nameservers"},
|
||||||
|
description = "List of nameservers, up to 13.",
|
||||||
|
variableArity = true)
|
||||||
|
private List<String> ns;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"-r", "--registrant"},
|
||||||
|
description = "Domain registrant.",
|
||||||
|
required = true)
|
||||||
|
private String registrant;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"-a", "--admin"},
|
||||||
|
description = "Admin contact.",
|
||||||
|
required = true)
|
||||||
|
private String admin;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"-t", "--tech"},
|
||||||
|
description = "Technical contact.",
|
||||||
|
required = true)
|
||||||
|
private String tech;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = {"-p", "--password"},
|
||||||
|
description = "Password. Optional, randomly generated if not provided.")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PasswordGenerator passwordGenerator;
|
||||||
|
|
||||||
|
private static final int PASSWORD_LENGTH = 16;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initMutatingEppToolCommand() {
|
||||||
|
if (isNullOrEmpty(password)) {
|
||||||
|
password = passwordGenerator.createPassword(PASSWORD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkArgument(ns == null || ns.size() <= 13, "There can be at most 13 nameservers.");
|
||||||
|
|
||||||
|
setSoyTemplate(CreateDomainSoyInfo.getInstance(), CreateDomainSoyInfo.CREATEDOMAIN);
|
||||||
|
addSoyRecord(clientIdentifier, new SoyMapData(
|
||||||
|
"domain", domain,
|
||||||
|
"period", period == null ? null : period.toString(),
|
||||||
|
"ns", ns,
|
||||||
|
"registrant", registrant,
|
||||||
|
"admin", admin,
|
||||||
|
"tech", tech,
|
||||||
|
"password", password));
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ public final class GtechTool {
|
||||||
.put("create_contact", CreateContactCommand.class)
|
.put("create_contact", CreateContactCommand.class)
|
||||||
.put("create_credit", CreateCreditCommand.class)
|
.put("create_credit", CreateCreditCommand.class)
|
||||||
.put("create_credit_balance", CreateCreditBalanceCommand.class)
|
.put("create_credit_balance", CreateCreditBalanceCommand.class)
|
||||||
|
.put("create_domain", CreateDomainCommand.class)
|
||||||
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
|
.put("create_registrar_groups", CreateRegistrarGroupsCommand.class)
|
||||||
.put("create_registrar", CreateRegistrarCommand.class)
|
.put("create_registrar", CreateRegistrarCommand.class)
|
||||||
.put("create_sandbox_tld", CreateSandboxTldCommand.class)
|
.put("create_sandbox_tld", CreateSandboxTldCommand.class)
|
||||||
|
|
|
@ -50,6 +50,7 @@ import google.registry.util.SystemClock.SystemClockModule;
|
||||||
interface RegistryToolComponent {
|
interface RegistryToolComponent {
|
||||||
void inject(CreateAnchorTenantCommand command);
|
void inject(CreateAnchorTenantCommand command);
|
||||||
void inject(CreateContactCommand command);
|
void inject(CreateContactCommand command);
|
||||||
|
void inject(CreateDomainCommand command);
|
||||||
void inject(CreateTldCommand command);
|
void inject(CreateTldCommand command);
|
||||||
void inject(EncryptEscrowDepositCommand command);
|
void inject(EncryptEscrowDepositCommand command);
|
||||||
void inject(GenerateApplicationsReportCommand command);
|
void inject(GenerateApplicationsReportCommand command);
|
||||||
|
|
56
java/google/registry/tools/soy/CreateDomain.soy
Normal file
56
java/google/registry/tools/soy/CreateDomain.soy
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
{namespace domain.registry.tools autoescape="strict"}
|
||||||
|
/**
|
||||||
|
* Create domain
|
||||||
|
*/
|
||||||
|
{template .createdomain}
|
||||||
|
{@param domain: string}
|
||||||
|
{@param? period: string}
|
||||||
|
{@param? ns: list<string>}
|
||||||
|
{@param registrant: string}
|
||||||
|
{@param admin: string}
|
||||||
|
{@param tech: string}
|
||||||
|
{@param password: string}
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<create>
|
||||||
|
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
|
<domain:name>{$domain}</domain:name>
|
||||||
|
{if $period}
|
||||||
|
<domain:period unit="y">{$period}</domain:period>
|
||||||
|
{/if}
|
||||||
|
{if $ns}
|
||||||
|
<domain:ns>
|
||||||
|
{foreach $s in $ns}
|
||||||
|
<domain:hostObj>{$s}</domain:hostObj>
|
||||||
|
{/foreach}
|
||||||
|
</domain:ns>
|
||||||
|
{/if}
|
||||||
|
<domain:registrant>{$registrant}</domain:registrant>
|
||||||
|
<domain:contact type="admin">{$admin}</domain:contact>
|
||||||
|
<domain:contact type="tech">{$tech}</domain:contact>
|
||||||
|
<domain:authInfo>
|
||||||
|
<domain:pw>{$password}</domain:pw>
|
||||||
|
</domain:authInfo>
|
||||||
|
</domain:create>
|
||||||
|
</create>
|
||||||
|
<clTRID>GTechTool</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
{/template}
|
||||||
|
|
|
@ -19,8 +19,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/** Unit tests for {@link CreateContactCommand}. */
|
/** Unit tests for {@link CreateContactCommand}. */
|
||||||
public class CreateContactCommandTest
|
public class CreateContactCommandTest extends EppToolCommandTestCase<CreateContactCommand> {
|
||||||
extends EppToolCommandTestCase<CreateContactCommand> {
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void initCommand() {
|
public void initCommand() {
|
||||||
|
|
120
javatests/google/registry/tools/CreateDomainCommandTest.java
Normal file
120
javatests/google/registry/tools/CreateDomainCommandTest.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package google.registry.tools;
|
||||||
|
|
||||||
|
import com.beust.jcommander.ParameterException;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** Unit tests for {@link CreateDomainCommand}. */
|
||||||
|
public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand> {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initCommand() {
|
||||||
|
command.passwordGenerator = new FakePasswordGenerator("abcdefghijklmnopqrstuvwxyz");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_complete() throws Exception {
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--period=1",
|
||||||
|
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech",
|
||||||
|
"--password=2fooBAR");
|
||||||
|
eppVerifier().verifySent("domain_create_complete.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_minimal() throws Exception {
|
||||||
|
// Test that each optional field can be omitted. Also tests the auto-gen password.
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech");
|
||||||
|
eppVerifier().verifySent("domain_create_minimal.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_missingClientId() throws Exception {
|
||||||
|
thrown.expect(ParameterException.class);
|
||||||
|
runCommandForced(
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--registrant=crr-admin");
|
||||||
|
runCommandForced();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_missingDomain() throws Exception {
|
||||||
|
thrown.expect(ParameterException.class);
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech");
|
||||||
|
|
||||||
|
runCommandForced();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_missingRegistrant() throws Exception {
|
||||||
|
thrown.expect(ParameterException.class);
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech");
|
||||||
|
|
||||||
|
runCommandForced();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_tooManyNameServers() throws Exception {
|
||||||
|
thrown.expect(IllegalArgumentException.class);
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech",
|
||||||
|
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google",
|
||||||
|
"--nameservers=ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google",
|
||||||
|
"--nameservers=ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google",
|
||||||
|
"--nameservers=ns13.zdns.google,ns14.zdns.google");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_badPeriod() throws Exception {
|
||||||
|
thrown.expect(ParameterException.class);
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--domain=example.tld",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admin=crr-admin",
|
||||||
|
"--tech=crr-tech",
|
||||||
|
"--period=x");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_badFax() throws Exception {
|
||||||
|
thrown.expect(ParameterException.class);
|
||||||
|
runCommandForced("--client=NewRegistrar", "--fax=3");
|
||||||
|
}
|
||||||
|
}
|
25
javatests/google/registry/tools/testdata/domain_create_complete.xml
vendored
Normal file
25
javatests/google/registry/tools/testdata/domain_create_complete.xml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<create>
|
||||||
|
<domain:create
|
||||||
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
|
<domain:name>example.tld</domain:name>
|
||||||
|
<domain:period unit="y">1</domain:period>
|
||||||
|
<domain:ns>
|
||||||
|
<domain:hostObj>ns1.zdns.google</domain:hostObj>
|
||||||
|
<domain:hostObj>ns2.zdns.google</domain:hostObj>
|
||||||
|
<domain:hostObj>ns3.zdns.google</domain:hostObj>
|
||||||
|
<domain:hostObj>ns4.zdns.google</domain:hostObj>
|
||||||
|
</domain:ns>
|
||||||
|
<domain:registrant>crr-admin</domain:registrant>
|
||||||
|
<domain:contact type="admin">crr-admin</domain:contact>
|
||||||
|
<domain:contact type="tech">crr-tech</domain:contact>
|
||||||
|
<domain:authInfo>
|
||||||
|
<domain:pw>2fooBAR</domain:pw>
|
||||||
|
</domain:authInfo>
|
||||||
|
</domain:create>
|
||||||
|
</create>
|
||||||
|
<clTRID>GTechTool</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
18
javatests/google/registry/tools/testdata/domain_create_minimal.xml
vendored
Normal file
18
javatests/google/registry/tools/testdata/domain_create_minimal.xml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||||
|
<command>
|
||||||
|
<create>
|
||||||
|
<domain:create
|
||||||
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
|
<domain:name>example.tld</domain:name>
|
||||||
|
<domain:registrant>crr-admin</domain:registrant>
|
||||||
|
<domain:contact type="admin">crr-admin</domain:contact>
|
||||||
|
<domain:contact type="tech">crr-tech</domain:contact>
|
||||||
|
<domain:authInfo>
|
||||||
|
<domain:pw>abcdefghijklmnop</domain:pw>
|
||||||
|
</domain:authInfo>
|
||||||
|
</domain:create>
|
||||||
|
</create>
|
||||||
|
<clTRID>GTechTool</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue