ns1: Implement EnsureDomainExists (#1157)

API support is there, let's use it.

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Costas Drogos 2021-05-14 20:39:09 +02:00 committed by GitHub
parent 1ec61c536b
commit ce9005c7a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,7 @@ var docNotes = providers.DocumentationNotes{
providers.CanUseAlias: providers.Can(),
providers.CanUseCAA: providers.Can(),
providers.CanUsePTR: providers.Can(),
providers.DocCreateDomains: providers.Cannot(),
providers.DocCreateDomains: providers.Can(),
providers.DocDualHost: providers.Can(),
providers.DocOfficiallySupported: providers.Cannot(),
}
@ -44,6 +44,20 @@ func newProvider(creds map[string]string, meta json.RawMessage) (providers.DNSSe
return &nsone{rest.NewClient(http.DefaultClient, rest.SetAPIKey(creds["api_token"]))}, nil
}
func (n *nsone) EnsureDomainExists(domain string) error {
// This enables the create-domains subcommand
zone := dns.NewZone(domain)
_, err := n.Zones.Create(zone)
if err == rest.ErrZoneExists {
// if domain exists already, just return nil, nothing to do here.
return nil
}
return err
}
func (n *nsone) GetNameservers(domain string) ([]*models.Nameserver, error) {
z, _, err := n.Zones.Get(domain)
if err != nil {