mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Add premium support to nomulus create_domain command
Premium prices are automatically detected and set, with an informational message displayed to the user prior to executing the command. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=199223541
This commit is contained in:
parent
61f6e666b1
commit
7c0b8cab0b
8 changed files with 165 additions and 18 deletions
|
@ -16,23 +16,34 @@ package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||||
|
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
import static org.joda.time.DateTimeZone.UTC;
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
import com.google.template.soy.data.SoyMapData;
|
import com.google.template.soy.data.SoyMapData;
|
||||||
|
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
|
||||||
|
import google.registry.tools.Command.RemoteApiCommand;
|
||||||
import google.registry.tools.soy.DomainCreateSoyInfo;
|
import google.registry.tools.soy.DomainCreateSoyInfo;
|
||||||
import google.registry.util.StringGenerator;
|
import google.registry.util.StringGenerator;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import org.joda.money.Money;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/** A command to create a new domain via EPP. */
|
/** A command to create a new domain via EPP. */
|
||||||
@Parameters(separators = " =", commandDescription = "Create a new domain via EPP.")
|
@Parameters(separators = " =", commandDescription = "Create a new domain via EPP.")
|
||||||
final class CreateDomainCommand extends CreateOrUpdateDomainCommand {
|
final class CreateDomainCommand extends CreateOrUpdateDomainCommand implements RemoteApiCommand {
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = "--period",
|
names = "--period",
|
||||||
description = "Initial registration period, in years.")
|
description = "Initial registration period, in years.")
|
||||||
private Integer period;
|
private int period = 1;
|
||||||
|
|
||||||
|
@Parameter(
|
||||||
|
names = "--force_premiums",
|
||||||
|
description = "Force the creation of premium domains.")
|
||||||
|
private boolean forcePremiums;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
StringGenerator passwordGenerator;
|
StringGenerator passwordGenerator;
|
||||||
|
@ -49,17 +60,36 @@ final class CreateDomainCommand extends CreateOrUpdateDomainCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String domain : domains) {
|
for (String domain : domains) {
|
||||||
|
String currency = null;
|
||||||
|
String cost = null;
|
||||||
|
DomainPrices prices = getPricesForDomainName(domain, DateTime.now(UTC));
|
||||||
|
|
||||||
|
// Check if the domain is premium and set the fee on the create command if so.
|
||||||
|
if (prices.isPremium()) {
|
||||||
|
checkArgument(
|
||||||
|
!force || forcePremiums,
|
||||||
|
"Forced creates on premium domain(s) require --force_premiums");
|
||||||
|
Money createCost = prices.getCreateCost();
|
||||||
|
currency = createCost.getCurrencyUnit().getCurrencyCode();
|
||||||
|
cost = createCost.multipliedBy(period).getAmount().toString();
|
||||||
|
System.out.printf(
|
||||||
|
"NOTE: %s is premium at %s per year; sending total cost for %d year(s) of %s %s.\n",
|
||||||
|
domain, createCost, period, currency, cost);
|
||||||
|
}
|
||||||
|
|
||||||
setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE);
|
setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE);
|
||||||
addSoyRecord(
|
addSoyRecord(
|
||||||
clientId,
|
clientId,
|
||||||
new SoyMapData(
|
new SoyMapData(
|
||||||
"domain", domain,
|
"domain", domain,
|
||||||
"period", period == null ? null : period.toString(),
|
"period", period,
|
||||||
"nameservers", nameservers,
|
"nameservers", nameservers,
|
||||||
"registrant", registrant,
|
"registrant", registrant,
|
||||||
"admins", admins,
|
"admins", admins,
|
||||||
"techs", techs,
|
"techs", techs,
|
||||||
"password", password,
|
"password", password,
|
||||||
|
"currency", currency,
|
||||||
|
"price", cost,
|
||||||
"dsRecords", DsRecord.convertToSoy(dsRecords)));
|
"dsRecords", DsRecord.convertToSoy(dsRecords)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
*/
|
*/
|
||||||
{template .domaincreate stricthtml="false"}
|
{template .domaincreate stricthtml="false"}
|
||||||
{@param domain: string}
|
{@param domain: string}
|
||||||
{@param? period: string}
|
{@param period: int}
|
||||||
{@param nameservers: list<string>}
|
{@param nameservers: list<string>}
|
||||||
{@param registrant: string}
|
{@param registrant: string}
|
||||||
{@param admins: list<string>}
|
{@param admins: list<string>}
|
||||||
{@param techs: list<string>}
|
{@param techs: list<string>}
|
||||||
{@param password: string}
|
{@param password: string}
|
||||||
|
{@param? currency: string}
|
||||||
|
{@param? price: string}
|
||||||
{@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
|
{@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
@ -32,9 +34,7 @@
|
||||||
<create>
|
<create>
|
||||||
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
<domain:name>{$domain}</domain:name>
|
<domain:name>{$domain}</domain:name>
|
||||||
{if $period}
|
|
||||||
<domain:period unit="y">{$period}</domain:period>
|
<domain:period unit="y">{$period}</domain:period>
|
||||||
{/if}
|
|
||||||
{if length($nameservers) > 0}
|
{if length($nameservers) > 0}
|
||||||
<domain:ns>
|
<domain:ns>
|
||||||
{for $s in $nameservers}
|
{for $s in $nameservers}
|
||||||
|
@ -54,8 +54,15 @@
|
||||||
</domain:authInfo>
|
</domain:authInfo>
|
||||||
</domain:create>
|
</domain:create>
|
||||||
</create>
|
</create>
|
||||||
{if length($dsRecords) > 0}
|
{if length($dsRecords) > 0 or $price != null}
|
||||||
<extension>
|
<extension>
|
||||||
|
{if $price != null}
|
||||||
|
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
|
||||||
|
<fee:currency>{$currency}</fee:currency>
|
||||||
|
<fee:fee>{$price}</fee:fee>
|
||||||
|
</fee:create>
|
||||||
|
{/if}
|
||||||
|
{if length($dsRecords) > 0}
|
||||||
<secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
|
<secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
|
||||||
{for $dsRecord in $dsRecords}
|
{for $dsRecord in $dsRecords}
|
||||||
<secDNS:dsData>
|
<secDNS:dsData>
|
||||||
|
@ -66,6 +73,7 @@
|
||||||
</secDNS:dsData>
|
</secDNS:dsData>
|
||||||
{/for}
|
{/for}
|
||||||
</secDNS:create>
|
</secDNS:create>
|
||||||
|
{/if}
|
||||||
</extension>
|
</extension>
|
||||||
{/if}
|
{/if}
|
||||||
<clTRID>RegistryTool</clTRID>
|
<clTRID>RegistryTool</clTRID>
|
||||||
|
|
|
@ -10,3 +10,4 @@ palladium,USD 877
|
||||||
aluminum,USD 11
|
aluminum,USD 11
|
||||||
copper,USD 15
|
copper,USD 15
|
||||||
brass,USD 20
|
brass,USD 20
|
||||||
|
parajiumu,JPY 96083
|
||||||
|
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
|
|
||||||
import com.beust.jcommander.ParameterException;
|
import com.beust.jcommander.ParameterException;
|
||||||
|
@ -60,6 +61,7 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_multipleDomains() throws Exception {
|
public void testSuccess_multipleDomains() throws Exception {
|
||||||
|
createTld("abc");
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
"--client=NewRegistrar",
|
"--client=NewRegistrar",
|
||||||
"--registrant=crr-admin",
|
"--registrant=crr-admin",
|
||||||
|
@ -72,6 +74,43 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
|
||||||
.verifySent("domain_create_minimal_abc.xml");
|
.verifySent("domain_create_minimal_abc.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_premiumDomain() throws Exception {
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admins=crr-admin",
|
||||||
|
"--techs=crr-tech",
|
||||||
|
"--period=3",
|
||||||
|
"--force_premiums",
|
||||||
|
"parajiumu.tld");
|
||||||
|
eppVerifier.verifySent("domain_create_parajiumu_3yrs.xml");
|
||||||
|
assertInStdout(
|
||||||
|
"parajiumu.tld is premium at JPY 96083 per year; "
|
||||||
|
+ "sending total cost for 3 year(s) of JPY 288249.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_multipleDomainsWithPremium() throws Exception {
|
||||||
|
createTld("abc");
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admins=crr-admin",
|
||||||
|
"--techs=crr-tech",
|
||||||
|
"--force_premiums",
|
||||||
|
"example.tld",
|
||||||
|
"palladium.tld",
|
||||||
|
"example.abc");
|
||||||
|
eppVerifier
|
||||||
|
.verifySent("domain_create_minimal.xml")
|
||||||
|
.verifySent("domain_create_palladium.xml")
|
||||||
|
.verifySent("domain_create_minimal_abc.xml");
|
||||||
|
assertInStdout(
|
||||||
|
"palladium.tld is premium at USD 877.00 per year; "
|
||||||
|
+ "sending total cost for 1 year(s) of USD 877.00.");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_duplicateDomains() throws Exception {
|
public void testFailure_duplicateDomains() throws Exception {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -288,4 +327,21 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
|
||||||
"example.tld"));
|
"example.tld"));
|
||||||
assertThat(thrown).hasMessageThat().contains("length 5");
|
assertThat(thrown).hasMessageThat().contains("length 5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_cantForceCreatePremiumDomain_withoutForcePremiums() {
|
||||||
|
IllegalArgumentException thrown =
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() ->
|
||||||
|
runCommandForced(
|
||||||
|
"--client=NewRegistrar",
|
||||||
|
"--registrant=crr-admin",
|
||||||
|
"--admins=crr-admin",
|
||||||
|
"--techs=crr-tech",
|
||||||
|
"gold.tld"));
|
||||||
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo("Forced creates on premium domain(s) require --force_premiums");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<domain:create
|
<domain:create
|
||||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
<domain:name>example.tld</domain:name>
|
<domain:name>example.tld</domain:name>
|
||||||
|
<domain:period unit="y">1</domain:period>
|
||||||
<domain:registrant>crr-admin</domain:registrant>
|
<domain:registrant>crr-admin</domain:registrant>
|
||||||
<domain:contact type="admin">crr-admin</domain:contact>
|
<domain:contact type="admin">crr-admin</domain:contact>
|
||||||
<domain:contact type="tech">crr-tech</domain:contact>
|
<domain:contact type="tech">crr-tech</domain:contact>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<domain:create
|
<domain:create
|
||||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||||
<domain:name>example.abc</domain:name>
|
<domain:name>example.abc</domain:name>
|
||||||
|
<domain:period unit="y">1</domain:period>
|
||||||
<domain:registrant>crr-admin</domain:registrant>
|
<domain:registrant>crr-admin</domain:registrant>
|
||||||
<domain:contact type="admin">crr-admin</domain:contact>
|
<domain:contact type="admin">crr-admin</domain:contact>
|
||||||
<domain:contact type="tech">crr-tech</domain:contact>
|
<domain:contact type="tech">crr-tech</domain:contact>
|
||||||
|
|
25
javatests/google/registry/tools/server/testdata/domain_create_palladium.xml
vendored
Normal file
25
javatests/google/registry/tools/server/testdata/domain_create_palladium.xml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<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>palladium.tld</domain:name>
|
||||||
|
<domain:period unit="y">1</domain:period>
|
||||||
|
<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>
|
||||||
|
<extension>
|
||||||
|
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
|
||||||
|
<fee:currency>USD</fee:currency>
|
||||||
|
<fee:fee>877.00</fee:fee>
|
||||||
|
</fee:create>
|
||||||
|
</extension>
|
||||||
|
<clTRID>RegistryTool</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
25
javatests/google/registry/tools/server/testdata/domain_create_parajiumu_3yrs.xml
vendored
Normal file
25
javatests/google/registry/tools/server/testdata/domain_create_parajiumu_3yrs.xml
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<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>parajiumu.tld</domain:name>
|
||||||
|
<domain:period unit="y">3</domain:period>
|
||||||
|
<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>
|
||||||
|
<extension>
|
||||||
|
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.12">
|
||||||
|
<fee:currency>JPY</fee:currency>
|
||||||
|
<fee:fee>288249</fee:fee>
|
||||||
|
</fee:create>
|
||||||
|
</extension>
|
||||||
|
<clTRID>RegistryTool</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue