Переглянути джерело

Better DNS listing APIs usage

pull/14/head
Kristijan Mitrovic 4 роки тому
джерело
коміт
e289929f21
2 змінених файлів з 26 додано та 20 видалено
  1. +14
    -10
      bubble-server/src/main/java/bubble/cloud/dns/godaddy/GoDaddyDnsDriver.java
  2. +12
    -10
      bubble-server/src/main/java/bubble/cloud/dns/route53/Route53DnsDriver.java

+ 14
- 10
bubble-server/src/main/java/bubble/cloud/dns/godaddy/GoDaddyDnsDriver.java Переглянути файл

@@ -32,6 +32,7 @@ import static org.cobbzilla.util.http.HttpMethods.PATCH;
import static org.cobbzilla.util.http.HttpMethods.PUT;
import static org.cobbzilla.util.json.JsonUtil.COMPACT_MAPPER;
import static org.cobbzilla.util.json.JsonUtil.json;
import static org.cobbzilla.wizard.resources.ResourceUtil.invalidEx;

public class GoDaddyDnsDriver extends DnsDriverBase<GoDaddyDnsConfig> {

@@ -165,18 +166,21 @@ public class GoDaddyDnsDriver extends DnsDriverBase<GoDaddyDnsConfig> {
if (domain == null) return emptyList();

// iterate over all records, return matches
String url = config.getBaseUri()+domain.getName()+"/records";
if (matcher != null) {
if (matcher.hasType()) {
url += "/" + matcher.getType().name();
}
if (matcher.hasFqdn()) {
String fqdn = matcher.getFqdn();
fqdn = domain.dropDomainSuffix(fqdn);
url += "/" + fqdn;
final var url = new StringBuilder(config.getBaseUri()).append(domain.getName()).append("/records");
if (matcher != null && (matcher.hasType() || matcher.hasFqdn())) {
if (!matcher.hasType() || !matcher.hasPattern()) {
// as per GoDaddy's docs both type and fqdn must be set here
// https://developer.godaddy.com/doc/endpoint/domains#/v1/recordGet
throw invalidEx("err.request.invalid", "Both type and pattern are required");
}

url.append("/").append(matcher.getType().name());

var fqdn = matcher.getPattern();
fqdn = domain.dropDomainSuffix(fqdn);
url.append("/").append(fqdn);
}
return readRecords(domain, url, matcher);
return readRecords(domain, url.toString(), matcher);
}

public Collection<DnsRecord> readRecords(BubbleDomain domain, String url, DnsRecordMatch matcher) {


+ 12
- 10
bubble-server/src/main/java/bubble/cloud/dns/route53/Route53DnsDriver.java Переглянути файл

@@ -18,10 +18,7 @@ import org.cobbzilla.util.dns.DnsRecord;
import org.cobbzilla.util.dns.DnsRecordMatch;
import org.cobbzilla.util.dns.DnsType;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
@@ -57,15 +54,20 @@ public class Route53DnsDriver extends DnsDriverBase<Route53DnsConfig> {
@Getter(lazy=true) private final Map<String, HostedZone> cachedZoneLookups = new ExpirationMap<>();
private HostedZone getHostedZone(BubbleDomain domain) {
return getCachedZoneLookups().computeIfAbsent(domain.getName(), key -> {
final var keyDot = key + ".";

final Optional<HostedZone> found;
try {
final ListHostedZonesResult zones = getRoute53client().listHostedZones(new ListHostedZonesRequest().withMaxItems(MAX_ITEMS));
for (HostedZone z : zones.getHostedZones()) {
if (z.getName().equalsIgnoreCase(key + ".")) return z;
}
return die("HostedZone with name '"+key+".' not found");
found = getRoute53client().listHostedZones(new ListHostedZonesRequest().withMaxItems(MAX_ITEMS))
.getHostedZones()
.stream()
.filter(z -> z.getName().equalsIgnoreCase(keyDot))
.findFirst();
} catch (Exception e) {
return die("getHostedZone: "+e);
return die("getHostedZone: " + e);
}

return found.isPresent() ? found.get() : die("getHostedZone: HostedZone not found with name: " + keyDot);
});
}



Завантаження…
Відмінити
Зберегти