mirror of
https://github.com/google/nomulus.git
synced 2025-06-29 15:53:35 +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.Strings.isNullOrEmpty;
|
||||
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
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.util.StringGenerator;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** A command to 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(
|
||||
names = "--period",
|
||||
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
|
||||
StringGenerator passwordGenerator;
|
||||
|
@ -49,17 +60,36 @@ final class CreateDomainCommand extends CreateOrUpdateDomainCommand {
|
|||
}
|
||||
|
||||
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);
|
||||
addSoyRecord(
|
||||
clientId,
|
||||
new SoyMapData(
|
||||
"domain", domain,
|
||||
"period", period == null ? null : period.toString(),
|
||||
"period", period,
|
||||
"nameservers", nameservers,
|
||||
"registrant", registrant,
|
||||
"admins", admins,
|
||||
"techs", techs,
|
||||
"password", password,
|
||||
"currency", currency,
|
||||
"price", cost,
|
||||
"dsRecords", DsRecord.convertToSoy(dsRecords)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
*/
|
||||
{template .domaincreate stricthtml="false"}
|
||||
{@param domain: string}
|
||||
{@param? period: string}
|
||||
{@param period: int}
|
||||
{@param nameservers: list<string>}
|
||||
{@param registrant: string}
|
||||
{@param admins: list<string>}
|
||||
{@param techs: list<string>}
|
||||
{@param password: string}
|
||||
{@param? currency: string}
|
||||
{@param? price: string}
|
||||
{@param dsRecords: list<[keyTag:int, alg:int, digestType:int, digest:string]>}
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
|
@ -32,9 +34,7 @@
|
|||
<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}
|
||||
<domain:period unit="y">{$period}</domain:period>
|
||||
{if length($nameservers) > 0}
|
||||
<domain:ns>
|
||||
{for $s in $nameservers}
|
||||
|
@ -54,18 +54,26 @@
|
|||
</domain:authInfo>
|
||||
</domain:create>
|
||||
</create>
|
||||
{if length($dsRecords) > 0}
|
||||
{if length($dsRecords) > 0 or $price != null}
|
||||
<extension>
|
||||
<secDNS:create xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1">
|
||||
{for $dsRecord in $dsRecords}
|
||||
<secDNS:dsData>
|
||||
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
|
||||
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
|
||||
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
|
||||
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
|
||||
</secDNS:dsData>
|
||||
{/for}
|
||||
</secDNS:create>
|
||||
{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">
|
||||
{for $dsRecord in $dsRecords}
|
||||
<secDNS:dsData>
|
||||
<secDNS:keyTag>{$dsRecord.keyTag}</secDNS:keyTag>
|
||||
<secDNS:alg>{$dsRecord.alg}</secDNS:alg>
|
||||
<secDNS:digestType>{$dsRecord.digestType}</secDNS:digestType>
|
||||
<secDNS:digest>{$dsRecord.digest}</secDNS:digest>
|
||||
</secDNS:dsData>
|
||||
{/for}
|
||||
</secDNS:create>
|
||||
{/if}
|
||||
</extension>
|
||||
{/if}
|
||||
<clTRID>RegistryTool</clTRID>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue