forked from TrueCloudLab/lego
Move duplicate code to a function
Signed-off-by: xenolf <xenolf@users.noreply.github.com>
This commit is contained in:
parent
239a7005ef
commit
44d92633c6
1 changed files with 13 additions and 16 deletions
|
@ -214,14 +214,7 @@ func FindZoneByFqdn(fqdn, nameserver string) (string, error) {
|
||||||
// We have a success, so one of the answers has to be a SOA RR
|
// We have a success, so one of the answers has to be a SOA RR
|
||||||
for _, ans := range in.Answer {
|
for _, ans := range in.Answer {
|
||||||
if soa, ok := ans.(*dns.SOA); ok {
|
if soa, ok := ans.(*dns.SOA); ok {
|
||||||
zone := soa.Hdr.Name
|
return checkIfTLD(fqdn, soa)
|
||||||
// If we ended up on one of the TLDs, it means the domain did not exist.
|
|
||||||
publicsuffix, _ := publicsuffix.PublicSuffix(UnFqdn(zone))
|
|
||||||
if publicsuffix == UnFqdn(zone) {
|
|
||||||
return "", fmt.Errorf("Could not determine zone authoritatively")
|
|
||||||
}
|
|
||||||
fqdnToZone[fqdn] = zone
|
|
||||||
return zone, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Or it is NODATA, fall through to NXDOMAIN
|
// Or it is NODATA, fall through to NXDOMAIN
|
||||||
|
@ -229,19 +222,23 @@ func FindZoneByFqdn(fqdn, nameserver string) (string, error) {
|
||||||
// Search the authority section for our precious SOA RR
|
// Search the authority section for our precious SOA RR
|
||||||
for _, ns := range in.Ns {
|
for _, ns := range in.Ns {
|
||||||
if soa, ok := ns.(*dns.SOA); ok {
|
if soa, ok := ns.(*dns.SOA); ok {
|
||||||
zone := soa.Hdr.Name
|
return checkIfTLD(fqdn, soa)
|
||||||
// If we ended up on one of the TLDs, it means the domain did not exist.
|
|
||||||
publicsuffix, _ := publicsuffix.PublicSuffix(UnFqdn(zone))
|
|
||||||
if publicsuffix == UnFqdn(zone) {
|
|
||||||
return "", fmt.Errorf("Could not determine zone authoritatively")
|
|
||||||
}
|
|
||||||
fqdnToZone[fqdn] = zone
|
|
||||||
return zone, nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("NS %s did not return the expected SOA record in the authority section", nameserver)
|
return "", fmt.Errorf("NS %s did not return the expected SOA record in the authority section", nameserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkIfTLD(fqdn string, soa *dns.SOA) (string, error) {
|
||||||
|
zone := soa.Hdr.Name
|
||||||
|
// If we ended up on one of the TLDs, it means the domain did not exist.
|
||||||
|
publicsuffix, _ := publicsuffix.PublicSuffix(UnFqdn(zone))
|
||||||
|
if publicsuffix == UnFqdn(zone) {
|
||||||
|
return "", fmt.Errorf("Could not determine zone authoritatively")
|
||||||
|
}
|
||||||
|
fqdnToZone[fqdn] = zone
|
||||||
|
return zone, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ClearFqdnCache clears the cache of fqdn to zone mappings. Primarily used in testing.
|
// ClearFqdnCache clears the cache of fqdn to zone mappings. Primarily used in testing.
|
||||||
func ClearFqdnCache() {
|
func ClearFqdnCache() {
|
||||||
fqdnToZone = map[string]string{}
|
fqdnToZone = map[string]string{}
|
||||||
|
|
Loading…
Reference in a new issue