mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 04:27:51 +02:00
There was no reason to have several different modules all providing a single thing. This approach, which creates a single UtilsModule for everything in the util package, is cleaner. This also removes provisioning of Random and StringGenerator objects in RegistryConfig.ConfigModule, which don't belong there because they aren't configuration options. This also removes insecure random entirely; it was only used in a single place to generate 24 bytes a couple times per day. We can live with the lower speed if it means we don't have to worry about multiple types of Random, or possibly using an insecure random accidentally in a place that security actually does matter. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=229751915
98 lines
3.7 KiB
Java
98 lines
3.7 KiB
Java
// Copyright 2017 The Nomulus 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 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.soy.DomainCreateSoyInfo;
|
|
import google.registry.util.StringGenerator;
|
|
import javax.inject.Inject;
|
|
import javax.inject.Named;
|
|
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
|
|
implements CommandWithRemoteApi {
|
|
|
|
@Parameter(
|
|
names = "--period",
|
|
description = "Initial registration period, in years.")
|
|
private int period = 1;
|
|
|
|
@Parameter(
|
|
names = "--force_premiums",
|
|
description = "Force the creation of premium domains.")
|
|
private boolean forcePremiums;
|
|
|
|
@Inject
|
|
@Named("base64StringGenerator")
|
|
StringGenerator passwordGenerator;
|
|
|
|
private static final int PASSWORD_LENGTH = 16;
|
|
|
|
@Override
|
|
protected void initMutatingEppToolCommand() {
|
|
checkArgumentNotNull(registrant, "Registrant must be specified");
|
|
checkArgument(!admins.isEmpty(), "At least one admin must be specified");
|
|
checkArgument(!techs.isEmpty(), "At least one tech must be specified");
|
|
if (isNullOrEmpty(password)) {
|
|
password = passwordGenerator.createString(PASSWORD_LENGTH);
|
|
}
|
|
|
|
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,
|
|
"nameservers", nameservers,
|
|
"registrant", registrant,
|
|
"admins", admins,
|
|
"techs", techs,
|
|
"password", password,
|
|
"currency", currency,
|
|
"price", cost,
|
|
"dsRecords", DsRecord.convertToSoy(dsRecords)));
|
|
}
|
|
}
|
|
}
|