mirror of
https://github.com/google/nomulus
synced 2026-09-12 02:56:26 +00:00
Use a TLD's configured TTLs if they are present (#1992)
* Use tld's configured TTLs if they are present * Change to optional * Use optionals better
This commit is contained in:
@@ -24,7 +24,9 @@ import google.registry.model.common.DatabaseMigrationStateSchedule;
|
||||
import google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState;
|
||||
import google.registry.model.common.DnsRefreshRequest;
|
||||
import google.registry.model.tld.Registries;
|
||||
import google.registry.model.tld.Tld;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
@@ -126,6 +128,18 @@ public class DnsUtils {
|
||||
.collect(toImmutableList())));
|
||||
}
|
||||
|
||||
public static long getDnsAPlusAAAATtlForHost(String host, Duration dnsDefaultATtl) {
|
||||
Optional<InternetDomainName> tldName = Registries.findTldForName(InternetDomainName.from(host));
|
||||
Duration dnsAPlusAaaaTtl = dnsDefaultATtl;
|
||||
if (tldName.isPresent()) {
|
||||
Tld tld = Tld.get(tldName.get().toString());
|
||||
if (tld.getDnsAPlusAaaaTtl().isPresent()) {
|
||||
dnsAPlusAaaaTtl = tld.getDnsAPlusAaaaTtl().get();
|
||||
}
|
||||
}
|
||||
return dnsAPlusAaaaTtl.getStandardSeconds();
|
||||
}
|
||||
|
||||
private boolean usePullQueue() {
|
||||
return !DatabaseMigrationStateSchedule.getValueAtTime(dnsQueue.getClock().nowUtc())
|
||||
.equals(MigrationState.DNS_SQL);
|
||||
|
||||
@@ -16,6 +16,7 @@ package google.registry.dns.writer.clouddns;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static google.registry.dns.DnsUtils.getDnsAPlusAAAATtlForHost;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.util.DomainNameUtils.getSecondLevelDomain;
|
||||
|
||||
@@ -40,6 +41,7 @@ import google.registry.model.domain.Domain;
|
||||
import google.registry.model.domain.secdns.DomainDsData;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.tld.Registries;
|
||||
import google.registry.model.tld.Tld;
|
||||
import google.registry.util.Clock;
|
||||
import google.registry.util.Concurrent;
|
||||
import google.registry.util.Retrier;
|
||||
@@ -131,6 +133,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
return;
|
||||
}
|
||||
|
||||
Tld tld = Tld.get(domain.get().getTld());
|
||||
ImmutableSet.Builder<ResourceRecordSet> domainRecords = new ImmutableSet.Builder<>();
|
||||
|
||||
// Construct DS records (if any).
|
||||
@@ -145,7 +148,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
domainRecords.add(
|
||||
new ResourceRecordSet()
|
||||
.setName(absoluteDomainName)
|
||||
.setTtl((int) defaultDsTtl.getStandardSeconds())
|
||||
.setTtl((int) tld.getDnsDsTtl().orElse(defaultDsTtl).getStandardSeconds())
|
||||
.setType("DS")
|
||||
.setKind("dns#resourceRecordSet")
|
||||
.setRrdatas(ImmutableList.copyOf(dsRrData)));
|
||||
@@ -170,7 +173,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
domainRecords.add(
|
||||
new ResourceRecordSet()
|
||||
.setName(absoluteDomainName)
|
||||
.setTtl((int) defaultNsTtl.getStandardSeconds())
|
||||
.setTtl((int) (tld.getDnsNsTtl().orElse(defaultNsTtl).getStandardSeconds()))
|
||||
.setType("NS")
|
||||
.setKind("dns#resourceRecordSet")
|
||||
.setRrdatas(ImmutableList.copyOf(nsRrData)));
|
||||
@@ -216,7 +219,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
domainRecords.add(
|
||||
new ResourceRecordSet()
|
||||
.setName(absoluteHostName)
|
||||
.setTtl((int) defaultATtl.getStandardSeconds())
|
||||
.setTtl((int) getDnsAPlusAAAATtlForHost(hostName, defaultATtl))
|
||||
.setType("A")
|
||||
.setKind("dns#resourceRecordSet")
|
||||
.setRrdatas(ImmutableList.copyOf(aRrData)));
|
||||
@@ -226,7 +229,7 @@ public class CloudDnsWriter extends BaseDnsWriter {
|
||||
domainRecords.add(
|
||||
new ResourceRecordSet()
|
||||
.setName(absoluteHostName)
|
||||
.setTtl((int) defaultATtl.getStandardSeconds())
|
||||
.setTtl((int) getDnsAPlusAAAATtlForHost(hostName, defaultATtl))
|
||||
.setType("AAAA")
|
||||
.setKind("dns#resourceRecordSet")
|
||||
.setRrdatas(ImmutableList.copyOf(aaaaRrData)));
|
||||
|
||||
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Verify.verify;
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static google.registry.dns.DnsUtils.getDnsAPlusAAAATtlForHost;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
@@ -31,6 +32,7 @@ import google.registry.model.domain.Domain;
|
||||
import google.registry.model.domain.secdns.DomainDsData;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.tld.Registries;
|
||||
import google.registry.model.tld.Tld;
|
||||
import google.registry.util.Clock;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
@@ -185,12 +187,13 @@ public class DnsUpdateWriter extends BaseDnsWriter {
|
||||
|
||||
private RRset makeDelegationSignerSet(Domain domain) {
|
||||
RRset signerSet = new RRset();
|
||||
Tld tld = Tld.get(domain.getTld());
|
||||
for (DomainDsData signerData : domain.getDsData()) {
|
||||
DSRecord dsRecord =
|
||||
new DSRecord(
|
||||
toAbsoluteName(domain.getDomainName()),
|
||||
DClass.IN,
|
||||
dnsDefaultDsTtl.getStandardSeconds(),
|
||||
tld.getDnsDsTtl().orElse(dnsDefaultDsTtl).getStandardSeconds(),
|
||||
signerData.getKeyTag(),
|
||||
signerData.getAlgorithm(),
|
||||
signerData.getDigestType(),
|
||||
@@ -224,12 +227,13 @@ public class DnsUpdateWriter extends BaseDnsWriter {
|
||||
|
||||
private RRset makeNameServerSet(Domain domain) {
|
||||
RRset nameServerSet = new RRset();
|
||||
Tld tld = Tld.get(domain.getTld());
|
||||
for (String hostName : domain.loadNameserverHostNames()) {
|
||||
NSRecord record =
|
||||
new NSRecord(
|
||||
toAbsoluteName(domain.getDomainName()),
|
||||
DClass.IN,
|
||||
dnsDefaultNsTtl.getStandardSeconds(),
|
||||
tld.getDnsNsTtl().orElse(dnsDefaultNsTtl).getStandardSeconds(),
|
||||
toAbsoluteName(hostName));
|
||||
nameServerSet.addRR(record);
|
||||
}
|
||||
@@ -244,7 +248,7 @@ public class DnsUpdateWriter extends BaseDnsWriter {
|
||||
new ARecord(
|
||||
toAbsoluteName(host.getHostName()),
|
||||
DClass.IN,
|
||||
dnsDefaultATtl.getStandardSeconds(),
|
||||
getDnsAPlusAAAATtlForHost(host.getHostName(), dnsDefaultATtl),
|
||||
address);
|
||||
addressSet.addRR(record);
|
||||
}
|
||||
@@ -260,7 +264,7 @@ public class DnsUpdateWriter extends BaseDnsWriter {
|
||||
new AAAARecord(
|
||||
toAbsoluteName(host.getHostName()),
|
||||
DClass.IN,
|
||||
dnsDefaultATtl.getStandardSeconds(),
|
||||
getDnsAPlusAAAATtlForHost(host.getHostName(), dnsDefaultATtl),
|
||||
address);
|
||||
addressSet.addRR(record);
|
||||
}
|
||||
|
||||
@@ -671,18 +671,18 @@ public class Tld extends ImmutableObject implements Buildable, UnsafeSerializabl
|
||||
}
|
||||
|
||||
/** Returns the time to live for A and AAAA records. */
|
||||
public Duration getDnsAPlusAaaaTtl() {
|
||||
return dnsAPlusAaaaTtl;
|
||||
public Optional<Duration> getDnsAPlusAaaaTtl() {
|
||||
return Optional.ofNullable(dnsAPlusAaaaTtl);
|
||||
}
|
||||
|
||||
/** Returns the time to live for NS records. */
|
||||
public Duration getDnsNsTtl() {
|
||||
return dnsNsTtl;
|
||||
public Optional<Duration> getDnsNsTtl() {
|
||||
return Optional.ofNullable(dnsNsTtl);
|
||||
}
|
||||
|
||||
/** Returns the time to live for DS records. */
|
||||
public Duration getDnsDsTtl() {
|
||||
return dnsDsTtl;
|
||||
public Optional<Duration> getDnsDsTtl() {
|
||||
return Optional.ofNullable(dnsDsTtl);
|
||||
}
|
||||
|
||||
public ImmutableSet<String> getAllowedRegistrantContactIds() {
|
||||
|
||||
@@ -31,6 +31,7 @@ import google.registry.gcs.GcsUtils;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.domain.secdns.DomainDsData;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.tld.Tld;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.request.JsonActionRunner;
|
||||
@@ -230,12 +231,13 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
||||
private String domainStanza(Domain domain, DateTime exportTime) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String domainLabel = stripTld(domain.getDomainName(), domain.getTld());
|
||||
Tld tld = Tld.get(domain.getTld());
|
||||
for (Host nameserver : tm().loadByKeys(domain.getNameservers()).values()) {
|
||||
result.append(
|
||||
String.format(
|
||||
NS_FORMAT,
|
||||
domainLabel,
|
||||
dnsDefaultNsTtl.getStandardSeconds(),
|
||||
tld.getDnsNsTtl().orElse(dnsDefaultNsTtl).getStandardSeconds(),
|
||||
// Load the nameservers at the export time in case they've been renamed or deleted.
|
||||
loadAtPointInTime(nameserver, exportTime).getHostName()));
|
||||
}
|
||||
@@ -244,7 +246,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
||||
String.format(
|
||||
DS_FORMAT,
|
||||
domainLabel,
|
||||
dnsDefaultDsTtl.getStandardSeconds(),
|
||||
tld.getDnsDsTtl().orElse(dnsDefaultDsTtl).getStandardSeconds(),
|
||||
dsData.getKeyTag(),
|
||||
dsData.getAlgorithm(),
|
||||
dsData.getDigestType(),
|
||||
@@ -265,16 +267,17 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
private String hostStanza(Host host, String tld) {
|
||||
private String hostStanza(Host host, String tldStr) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Tld tld = Tld.get(tldStr);
|
||||
for (InetAddress addr : host.getInetAddresses()) {
|
||||
// must be either IPv4 or IPv6
|
||||
String rrSetClass = (addr instanceof Inet4Address) ? "A" : "AAAA";
|
||||
result.append(
|
||||
String.format(
|
||||
A_FORMAT,
|
||||
stripTld(host.getHostName(), tld),
|
||||
dnsDefaultATtl.getStandardSeconds(),
|
||||
stripTld(host.getHostName(), tldStr),
|
||||
tld.getDnsAPlusAaaaTtl().orElse(dnsDefaultATtl).getStandardSeconds(),
|
||||
rrSetClass,
|
||||
addr.getHostAddress()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user