Copied some funcs to wait.go

This commit is contained in:
Chris Stuurman 2024-04-09 18:14:47 +02:00
parent 1550d050d0
commit 824243fa77
2 changed files with 43 additions and 1 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
//"github.com/cert-manager/cert-manager/pkg/issuer/acme/dns/util"
"github.com/stuurmcp/cert-manager-webhook-sthome/pkg/dns/util"
"github.com/stuurmcp/cert-manager-webhook-sthome/pkg/util"
)
var (

View File

@ -520,3 +520,45 @@ func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error {
time.Sleep(interval)
}
}
// DNS01LookupFQDN returns a DNS name which will be updated to solve the dns-01
// challenge
// TODO: move this into the pkg/acme package
func DNS01LookupFQDN(domain string, followCNAME bool, nameservers ...string) (string, error) {
fqdn := fmt.Sprintf("_acme-challenge.%s.", domain)
// Check if the domain has CNAME then return that
if followCNAME {
var err error
fqdn, err = followCNAMEs(fqdn, nameservers)
if err != nil {
return "", err
}
}
return fqdn, nil
}
// FindBestMatch returns the longest match for a given domain within a list of domains
func FindBestMatch(query string, domains ...string) (string, error) {
var maxSoFar int
var longest string
for _, domain := range domains {
if query == domain {
// Found exact match
return domain, nil
}
maxHere := dns.CompareDomainName(query, domain)
if maxHere > maxSoFar && dns.IsSubDomain(domain, query) {
maxSoFar = maxHere
longest = domain
}
}
if len(longest) == 0 {
return "", fmt.Errorf("query: %v has no matches", query)
}
return longest, nil
}