From e18dba472be85f1efdfdb62318be2880d229133e Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Mon, 10 Apr 2023 14:43:56 -0400 Subject: [PATCH] Add tool commands to modify TTLs on a TLD (#1985) * Add tool commands to modify TTLs on a TLD * Small changes * Add an example to the parameter description --- .../google/registry/model/tld/Registry.java | 8 +++---- .../tools/CreateOrUpdateTldCommand.java | 21 +++++++++++++++++++ .../registry/tools/CreateTldCommandTest.java | 16 ++++++++++++++ .../registry/tools/UpdateTldCommandTest.java | 13 ++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/google/registry/model/tld/Registry.java b/core/src/main/java/google/registry/model/tld/Registry.java index 2dedcaaa2..85ac28f11 100644 --- a/core/src/main/java/google/registry/model/tld/Registry.java +++ b/core/src/main/java/google/registry/model/tld/Registry.java @@ -785,13 +785,13 @@ public class Registry extends ImmutableObject implements Buildable, UnsafeSerial return this; } - public Builder setDnsNsAtl(Duration dnsNsAtl) { - getInstance().dnsNsTtl = dnsNsAtl; + public Builder setDnsNsTtl(Duration dnsNsTtl) { + getInstance().dnsNsTtl = dnsNsTtl; return this; } - public Builder setDnsDsAtl(Duration dnsDsAtl) { - getInstance().dnsDsTtl = dnsDsAtl; + public Builder setDnsDsTtl(Duration dnsDsTtl) { + getInstance().dnsDsTtl = dnsDsTtl; return this; } diff --git a/core/src/main/java/google/registry/tools/CreateOrUpdateTldCommand.java b/core/src/main/java/google/registry/tools/CreateOrUpdateTldCommand.java index 7356e06b3..4d8addff0 100644 --- a/core/src/main/java/google/registry/tools/CreateOrUpdateTldCommand.java +++ b/core/src/main/java/google/registry/tools/CreateOrUpdateTldCommand.java @@ -237,6 +237,24 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { ) Integer numDnsPublishShards; + @Nullable + @Parameter( + names = {"--dns_a_plus_aaaa_ttl"}, + description = "The time to live for DNS A and AAAA records (Ex: PT240S)") + Duration dnsAPlusAaaaTtl; + + @Nullable + @Parameter( + names = {"--dns_ns_ttl"}, + description = "The time to live for DNS NS records (Ex: PT240S)") + Duration dnsNsTtl; + + @Nullable + @Parameter( + names = {"--dns_ds_ttl"}, + description = "The time to live for DNS DS records (Ex: PT240S)") + Duration dnsDsTtl; + @Nullable @Parameter( names = "--default_tokens", @@ -364,6 +382,9 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand { Optional.ofNullable(lordnUsername).ifPresent(u -> builder.setLordnUsername(u.orElse(null))); Optional.ofNullable(claimsPeriodEnd).ifPresent(builder::setClaimsPeriodEnd); Optional.ofNullable(numDnsPublishShards).ifPresent(builder::setNumDnsPublishLocks); + Optional.ofNullable(dnsAPlusAaaaTtl).ifPresent(builder::setDnsAPlusAaaaTtl); + Optional.ofNullable(dnsNsTtl).ifPresent(builder::setDnsNsTtl); + Optional.ofNullable(dnsDsTtl).ifPresent(builder::setDnsDsTtl); if (premiumListName != null) { if (premiumListName.isPresent()) { diff --git a/core/src/test/java/google/registry/tools/CreateTldCommandTest.java b/core/src/test/java/google/registry/tools/CreateTldCommandTest.java index fcb60a83c..1fbda5776 100644 --- a/core/src/test/java/google/registry/tools/CreateTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateTldCommandTest.java @@ -76,6 +76,22 @@ class CreateTldCommandTest extends CommandTestCase { .isEqualTo(Registry.DEFAULT_REGISTRY_LOCK_OR_UNLOCK_BILLING_COST); } + @Test + void testSuccess_ttls() throws Exception { + runCommandForced( + "xn--q9jyb4c", + "--roid_suffix=Q9JYB4C", + "--dns_writers=FooDnsWriter", + "--dns_a_plus_aaaa_ttl=PT300S", + "--dns_ds_ttl=PT240S", + "--dns_ns_ttl=PT180S"); + Registry registry = Registry.get("xn--q9jyb4c"); + assertThat(registry).isNotNull(); + assertThat(registry.getDnsAPlusAaaaTtl()).isEqualTo(standardMinutes(5)); + assertThat(registry.getDnsDsTtl()).isEqualTo(standardMinutes(4)); + assertThat(registry.getDnsNsTtl()).isEqualTo(standardMinutes(3)); + } + @Test void testFailure_multipleArguments() { IllegalArgumentException thrown = diff --git a/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java b/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java index 7df7a3bf2..64c6cad95 100644 --- a/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateTldCommandTest.java @@ -1095,6 +1095,19 @@ class UpdateTldCommandTest extends CommandTestCase { assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist"); } + @Test + void testSuccess_setTtls() throws Exception { + runCommandForced( + "--dns_a_plus_aaaa_ttl=PT300S", + "--dns_ds_ttl=PT240S", + "--dns_ns_ttl=PT180S", + "xn--q9jyb4c"); + Registry registry = Registry.get("xn--q9jyb4c"); + assertThat(registry.getDnsAPlusAaaaTtl()).isEqualTo(standardMinutes(5)); + assertThat(registry.getDnsDsTtl()).isEqualTo(standardMinutes(4)); + assertThat(registry.getDnsNsTtl()).isEqualTo(standardMinutes(3)); + } + private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { runCommandForced("--reserved_lists", reservedLists, "xn--q9jyb4c"); }