forked from TrueCloudLab/lego
Move dyn provider out of acme package per #144
This commit is contained in:
parent
b90b31980a
commit
1de97a90da
4 changed files with 23 additions and 18 deletions
1
cli.go
1
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, "\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, "\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, "\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()
|
w.Flush()
|
||||||
|
|
||||||
fmt.Println(`
|
fmt.Println(`
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/xenolf/lego/providers/dns/namecheap"
|
"github.com/xenolf/lego/providers/dns/namecheap"
|
||||||
"github.com/xenolf/lego/providers/dns/rfc2136"
|
"github.com/xenolf/lego/providers/dns/rfc2136"
|
||||||
"github.com/xenolf/lego/providers/dns/route53"
|
"github.com/xenolf/lego/providers/dns/route53"
|
||||||
|
"github.com/xenolf/lego/providers/dns/dyn"
|
||||||
"github.com/xenolf/lego/providers/http/webroot"
|
"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")
|
dynUserName := os.Getenv("DYN_USER_NAME")
|
||||||
dynPassword := os.Getenv("DYN_PASSWORD")
|
dynPassword := os.Getenv("DYN_PASSWORD")
|
||||||
|
|
||||||
provider, err = acme.NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword)
|
provider, err = dyn.NewDNSProvider(dynCustomerName, dynUserName, dynPassword)
|
||||||
case "manual":
|
case "manual":
|
||||||
provider, err = acme.NewDNSProviderManual()
|
provider, err = acme.NewDNSProviderManual()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -6,6 +7,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/xenolf/lego/acme"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dynBaseURL = "https://api.dynect.net/REST"
|
var dynBaseURL = "https://api.dynect.net/REST"
|
||||||
|
@ -24,27 +27,27 @@ type DynResponse struct {
|
||||||
Messages json.RawMessage `json:"msgs"`
|
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.
|
// Dyn's Managed DNS API to manage TXT records for a domain.
|
||||||
type DNSProviderDyn struct {
|
type DNSProvider struct {
|
||||||
customerName string
|
customerName string
|
||||||
userName string
|
userName string
|
||||||
password string
|
password string
|
||||||
token 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 customer name of the Dyn account. userName is the user name. password is
|
||||||
// the password.
|
// the password.
|
||||||
func NewDNSProviderDyn(customerName, userName, password string) (*DNSProviderDyn, error) {
|
func NewDNSProvider(customerName, userName, password string) (*DNSProvider, error) {
|
||||||
return &DNSProviderDyn{
|
return &DNSProvider{
|
||||||
customerName: customerName,
|
customerName: customerName,
|
||||||
userName: userName,
|
userName: userName,
|
||||||
password: password,
|
password: password,
|
||||||
}, nil
|
}, 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)
|
url := fmt.Sprintf("%s/%s", dynBaseURL, resource)
|
||||||
|
|
||||||
body, err := json.Marshal(payload)
|
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,
|
// Starts a new Dyn API Session. Authenticates using customerName, userName,
|
||||||
// password and receives a token to be used in for subsequent requests.
|
// 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 {
|
type creds struct {
|
||||||
Customer string `json:"customer_name"`
|
Customer string `json:"customer_name"`
|
||||||
User string `json:"user_name"`
|
User string `json:"user_name"`
|
||||||
|
@ -120,7 +123,7 @@ func (d *DNSProviderDyn) login() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroys Dyn Session
|
// Destroys Dyn Session
|
||||||
func (d *DNSProviderDyn) logout() error {
|
func (d *DNSProvider) logout() error {
|
||||||
if len(d.token) == 0 {
|
if len(d.token) == 0 {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return nil
|
return nil
|
||||||
|
@ -149,13 +152,13 @@ func (d *DNSProviderDyn) logout() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Present creates a TXT record using the specified parameters
|
// 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()
|
err := d.login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdn, value, ttl := DNS01Record(domain, keyAuth)
|
fqdn, value, ttl := acme.DNS01Record(domain, keyAuth)
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"rdata": map[string]string{
|
"rdata": map[string]string{
|
||||||
|
@ -183,7 +186,7 @@ func (d *DNSProviderDyn) Present(domain, token, keyAuth string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProviderDyn) publish(domain, notes string) error {
|
func (d *DNSProvider) publish(domain, 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"`
|
||||||
|
@ -200,13 +203,13 @@ func (d *DNSProviderDyn) 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 *DNSProviderDyn) CleanUp(domain, token, keyAuth string) error {
|
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||||
err := d.login()
|
err := d.login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fqdn, _, _ := DNS01Record(domain, keyAuth)
|
fqdn, _, _ := acme.DNS01Record(domain, keyAuth)
|
||||||
|
|
||||||
resource := fmt.Sprintf("TXTRecord/%s/%s/", domain, fqdn)
|
resource := fmt.Sprintf("TXTRecord/%s/%s/", domain, fqdn)
|
||||||
url := fmt.Sprintf("%s/%s", dynBaseURL, resource)
|
url := fmt.Sprintf("%s/%s", dynBaseURL, resource)
|
|
@ -1,4 +1,4 @@
|
||||||
package acme
|
package dyn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -31,7 +31,7 @@ func TestLiveDynPresent(t *testing.T) {
|
||||||
t.Skip("skipping live test")
|
t.Skip("skipping live test")
|
||||||
}
|
}
|
||||||
|
|
||||||
provider, err := NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword)
|
provider, err := NewDNSProvider(dynCustomerName, dynUserName, dynPassword)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = provider.Present(dynDomain, "", "123d==")
|
err = provider.Present(dynDomain, "", "123d==")
|
||||||
|
@ -45,7 +45,7 @@ func TestLiveDynCleanUp(t *testing.T) {
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|
||||||
provider, err := NewDNSProviderDyn(dynCustomerName, dynUserName, dynPassword)
|
provider, err := NewDNSProvider(dynCustomerName, dynUserName, dynPassword)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = provider.CleanUp(dynDomain, "", "123d==")
|
err = provider.CleanUp(dynDomain, "", "123d==")
|
Loading…
Reference in a new issue