diff --git a/cli.go b/cli.go index ecf1c500..6771ba6b 100644 --- a/cli.go +++ b/cli.go @@ -167,6 +167,7 @@ Here is an example bash command using the CloudFlare DNS provider: fmt.Fprintln(w, "\tnamecheap:\tNAMECHEAP_API_USER, NAMECHEAP_API_KEY") fmt.Fprintln(w, "\trfc2136:\tRFC2136_TSIG_KEY, RFC2136_TSIG_SECRET,\n\t\tRFC2136_TSIG_ALGORITHM, RFC2136_NAMESERVER") fmt.Fprintln(w, "\troute53:\tAWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION") + fmt.Fprintln(w, "\tdyn:\tDYN_CUSTOMER_NAME, DYN_USER_NAME, DYN_PASSWORD") w.Flush() fmt.Println(` diff --git a/cli_handlers.go b/cli_handlers.go index 003d0db9..4e5c3ee2 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -18,6 +18,7 @@ import ( "github.com/xenolf/lego/providers/dns/namecheap" "github.com/xenolf/lego/providers/dns/rfc2136" "github.com/xenolf/lego/providers/dns/route53" + "github.com/xenolf/lego/providers/dns/dyn" "github.com/xenolf/lego/providers/http/webroot" ) @@ -114,7 +115,7 @@ func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) { dynUserName := os.Getenv("DYN_USER_NAME") dynPassword := os.Getenv("DYN_PASSWORD") - provider, err = acme.NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword) + provider, err = dyn.NewDNSProvider(dynCustomerName, dynUserName, dynPassword) case "manual": provider, err = acme.NewDNSProviderManual() } diff --git a/acme/dns_challenge_dyn.go b/providers/dns/dyn/dyn.go similarity index 84% rename from acme/dns_challenge_dyn.go rename to providers/dns/dyn/dyn.go index 8210fb09..e13eb3c7 100644 --- a/acme/dns_challenge_dyn.go +++ b/providers/dns/dyn/dyn.go @@ -1,4 +1,5 @@ -package acme +// Package dyn implements a DNS provider for solving the DNS-01 challenge using Dyn Managed DNS. +package dyn import ( "bytes" @@ -6,6 +7,8 @@ import ( "fmt" "net/http" "strconv" + + "github.com/xenolf/lego/acme" ) var dynBaseURL = "https://api.dynect.net/REST" @@ -24,27 +27,27 @@ type DynResponse struct { Messages json.RawMessage `json:"msgs"` } -// DNSProviderDyn is an implementation of the DNSProvider interface that uses +// DNSProvider is an implementation of the acme.ChallengeProvider interface that uses // Dyn's Managed DNS API to manage TXT records for a domain. -type DNSProviderDyn struct { +type DNSProvider struct { customerName string userName string password string token string } -// NewDNSProviderDyn returns a new DNSProviderDyn instance. customerName is +// NewDNSProvider returns a new DNSProvider instance. customerName is // the customer name of the Dyn account. userName is the user name. password is // the password. -func NewDNSProviderDyn(customerName, userName, password string) (*DNSProviderDyn, error) { - return &DNSProviderDyn{ +func NewDNSProvider(customerName, userName, password string) (*DNSProvider, error) { + return &DNSProvider{ customerName: customerName, userName: userName, password: password, }, nil } -func (d *DNSProviderDyn) sendRequest(method, resource string, payload interface{}) (*DynResponse, error) { +func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) (*DynResponse, error) { url := fmt.Sprintf("%s/%s", dynBaseURL, resource) body, err := json.Marshal(payload) @@ -90,7 +93,7 @@ func (d *DNSProviderDyn) sendRequest(method, resource string, payload interface{ // Starts a new Dyn API Session. Authenticates using customerName, userName, // password and receives a token to be used in for subsequent requests. -func (d *DNSProviderDyn) login() error { +func (d *DNSProvider) login() error { type creds struct { Customer string `json:"customer_name"` User string `json:"user_name"` @@ -120,7 +123,7 @@ func (d *DNSProviderDyn) login() error { } // Destroys Dyn Session -func (d *DNSProviderDyn) logout() error { +func (d *DNSProvider) logout() error { if len(d.token) == 0 { // nothing to do return nil @@ -149,13 +152,13 @@ func (d *DNSProviderDyn) logout() error { } // Present creates a TXT record using the specified parameters -func (d *DNSProviderDyn) Present(domain, token, keyAuth string) error { +func (d *DNSProvider) Present(domain, token, keyAuth string) error { err := d.login() if err != nil { return err } - fqdn, value, ttl := DNS01Record(domain, keyAuth) + fqdn, value, ttl := acme.DNS01Record(domain, keyAuth) data := map[string]interface{}{ "rdata": map[string]string{ @@ -183,7 +186,7 @@ func (d *DNSProviderDyn) Present(domain, token, keyAuth string) error { return nil } -func (d *DNSProviderDyn) publish(domain, notes string) error { +func (d *DNSProvider) publish(domain, notes string) error { type publish struct { Publish bool `json:"publish"` Notes string `json:"notes"` @@ -200,13 +203,13 @@ func (d *DNSProviderDyn) publish(domain, notes string) error { } // CleanUp removes the TXT record matching the specified parameters -func (d *DNSProviderDyn) CleanUp(domain, token, keyAuth string) error { +func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { err := d.login() if err != nil { return err } - fqdn, _, _ := DNS01Record(domain, keyAuth) + fqdn, _, _ := acme.DNS01Record(domain, keyAuth) resource := fmt.Sprintf("TXTRecord/%s/%s/", domain, fqdn) url := fmt.Sprintf("%s/%s", dynBaseURL, resource) diff --git a/acme/dns_challenge_dyn_test.go b/providers/dns/dyn/dyn_test.go similarity index 84% rename from acme/dns_challenge_dyn_test.go rename to providers/dns/dyn/dyn_test.go index 06a8628f..fcc3d63e 100644 --- a/acme/dns_challenge_dyn_test.go +++ b/providers/dns/dyn/dyn_test.go @@ -1,4 +1,4 @@ -package acme +package dyn import ( "os" @@ -31,7 +31,7 @@ func TestLiveDynPresent(t *testing.T) { t.Skip("skipping live test") } - provider, err := NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword) + provider, err := NewDNSProvider(dynCustomerName, dynUserName, dynPassword) assert.NoError(t, err) err = provider.Present(dynDomain, "", "123d==") @@ -45,7 +45,7 @@ func TestLiveDynCleanUp(t *testing.T) { time.Sleep(time.Second * 1) - provider, err := NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword) + provider, err := NewDNSProvider(dynCustomerName, dynUserName, dynPassword) assert.NoError(t, err) err = provider.CleanUp(dynDomain, "", "123d==")