ibmcloud: add support for subdomains (#1779)

Co-authored-by: Ludovic Fernandez <ldez@users.noreply.github.com>
This commit is contained in:
Thomas Hofmann 2022-12-06 18:51:44 +01:00 committed by GitHub
parent 7095aa66a2
commit c754882704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package internal
import (
"fmt"
"strings"
"github.com/softlayer/softlayer-go/datatypes"
"github.com/softlayer/softlayer-go/services"
@ -66,7 +67,16 @@ func getDomainID(service services.Dns_Domain, domain string) (*int, error) {
return r.Id, nil
}
return nil, fmt.Errorf("no data found of domain: %s", domain)
// The domain was not found by name.
// For subdomains this is not unusual in softlayer.
// So in case a subdomain like `sub.toplevel.tld` was used try again using the parent domain
// (strip the first part in the domain string -> `toplevel.tld`).
_, parent, found := strings.Cut(domain, ".")
if !found || !strings.Contains(parent, ".") {
return nil, fmt.Errorf("no data found for domain: %s", domain)
}
return getDomainID(service, parent)
}
func findTxtRecords(service services.Dns_Domain, fqdn string) ([]datatypes.Dns_Domain_ResourceRecord, error) {