forked from TrueCloudLab/lego
commit
948483535f
1 changed files with 20 additions and 10 deletions
|
@ -172,12 +172,17 @@ func (d *DNSProvider) logout() error {
|
||||||
|
|
||||||
// Present creates a TXT record using the specified parameters
|
// Present creates a TXT record using the specified parameters
|
||||||
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
||||||
err := d.login()
|
fqdn, value, ttl := acme.DNS01Record(domain, keyAuth)
|
||||||
|
|
||||||
|
authZone, err := acme.FindZoneByFqdn(fqdn, acme.RecursiveNameservers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdn, value, ttl := acme.DNS01Record(domain, keyAuth)
|
err = d.login()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"rdata": map[string]string{
|
"rdata": map[string]string{
|
||||||
|
@ -186,13 +191,13 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
||||||
"ttl": strconv.Itoa(ttl),
|
"ttl": strconv.Itoa(ttl),
|
||||||
}
|
}
|
||||||
|
|
||||||
resource := fmt.Sprintf("TXTRecord/%s/%s/", domain, fqdn)
|
resource := fmt.Sprintf("TXTRecord/%s/%s/", authZone, fqdn)
|
||||||
_, err = d.sendRequest("POST", resource, data)
|
_, err = d.sendRequest("POST", resource, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d.publish(domain, "Added TXT record for ACME dns-01 challenge using lego client")
|
err = d.publish(authZone, "Added TXT record for ACME dns-01 challenge using lego client")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -205,14 +210,14 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProvider) publish(domain, notes string) error {
|
func (d *DNSProvider) publish(zone, notes string) error {
|
||||||
type publish struct {
|
type publish struct {
|
||||||
Publish bool `json:"publish"`
|
Publish bool `json:"publish"`
|
||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
pub := &publish{Publish: true, Notes: notes}
|
pub := &publish{Publish: true, Notes: notes}
|
||||||
resource := fmt.Sprintf("Zone/%s/", domain)
|
resource := fmt.Sprintf("Zone/%s/", zone)
|
||||||
_, err := d.sendRequest("PUT", resource, pub)
|
_, err := d.sendRequest("PUT", resource, pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -223,14 +228,19 @@ func (d *DNSProvider) publish(domain, notes string) error {
|
||||||
|
|
||||||
// CleanUp removes the TXT record matching the specified parameters
|
// CleanUp removes the TXT record matching the specified parameters
|
||||||
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||||
err := d.login()
|
fqdn, _, _ := acme.DNS01Record(domain, keyAuth)
|
||||||
|
|
||||||
|
authZone, err := acme.FindZoneByFqdn(fqdn, acme.RecursiveNameservers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdn, _, _ := acme.DNS01Record(domain, keyAuth)
|
err = d.login()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
resource := fmt.Sprintf("TXTRecord/%s/%s/", domain, fqdn)
|
resource := fmt.Sprintf("TXTRecord/%s/%s/", authZone, fqdn)
|
||||||
url := fmt.Sprintf("%s/%s", dynBaseURL, resource)
|
url := fmt.Sprintf("%s/%s", dynBaseURL, resource)
|
||||||
req, err := http.NewRequest("DELETE", url, nil)
|
req, err := http.NewRequest("DELETE", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -250,7 +260,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||||
return fmt.Errorf("Dyn API request failed to delete TXT record HTTP status code %d", resp.StatusCode)
|
return fmt.Errorf("Dyn API request failed to delete TXT record HTTP status code %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d.publish(domain, "Removed TXT record for ACME dns-01 challenge using lego client")
|
err = d.publish(authZone, "Removed TXT record for ACME dns-01 challenge using lego client")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue