Add dagger map for injecting DnsWriter implementations

This is one of several CLs in a sequence for allowing per-TLD DNS
implementations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129445641
This commit is contained in:
Greg Shikhman 2016-08-05 08:45:02 -07:00 committed by Justine Tunney
parent 770fd35e20
commit a620d06239
24 changed files with 173 additions and 215 deletions

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.model.RoidSuffixes.isRoidSuffixUsed;
import static google.registry.util.CollectionUtils.findDuplicates;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
@ -26,6 +27,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import google.registry.dns.writer.DnsWriter;
import google.registry.model.pricing.StaticPremiumListPricingEngine;
import google.registry.model.registry.Registries;
import google.registry.model.registry.Registry;
@ -39,6 +41,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
@ -46,6 +49,8 @@ import org.joda.time.Duration;
/** Shared base class for commands to create or update a TLD. */
abstract class CreateOrUpdateTldCommand extends MutatingCommand {
@Inject Map<String, DnsWriter> dnsWriters;
@Parameter(
description = "Names of the TLDs",
required = true)
@ -205,6 +210,15 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
description = "The end of the claims period")
DateTime claimsPeriodEnd;
@Nullable
@Parameter(
names = "--dns_writer",
description = "The name of the DnsWriter implementation to use",
converter = OptionalStringParameter.class,
validateWith = OptionalStringParameter.class
)
Optional<String> dnsWriter;
/** Returns the existing registry (for update) or null (for creates). */
@Nullable
abstract Registry getOldRegistry(String tld);
@ -361,6 +375,16 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
}
}
if (dnsWriter != null) {
if (dnsWriter.isPresent()) {
checkNotNull(
dnsWriters.get(dnsWriter.get()),
"The DNS writer '%s' doesn't exist",
dnsWriter.get());
builder.setDnsWriter(dnsWriter.get());
}
}
ImmutableSet<String> newReservedListNames = getReservedLists(oldRegistry);
checkReservedListValidityForTld(tld, newReservedListNames);
builder.setReservedListsByName(newReservedListNames);