Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PowerDNS provider #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ A [Rancher](http://rancher.com/rancher/) service that obtains free SSL/TLS certi
* `Gandi`
* `NS1`
* `Ovh`
* `PowerDNS`
* `Vultr`

* If using the HTTP challenge, a proxy that routes `example.com/.well-known/acme-challenge` to `rancher-letsencrypt`.
Expand Down
2 changes: 2 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (c *Context) InitContext() {
OvhConsumerKey: getEnvOption("OVH_CONSUMER_KEY", false),
GandiApiKey: getEnvOption("GANDI_API_KEY", false),
NS1ApiKey: getEnvOption("NS1_API_KEY", false),
PDNSApiKey: getEnvOption("PDNS_API_KEY", false),
PDNSApiURL: getEnvOption("PDNS_API_URL", false),
}

c.Acme, err = letsencrypt.NewClient(emailParam, keyType, apiVersion, providerOpts)
Expand Down
29 changes: 29 additions & 0 deletions letsencrypt/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package letsencrypt

import (
"fmt"
"net/url"
"os"

lego "github.com/xenolf/lego/acme"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/xenolf/lego/providers/dns/gandi"
"github.com/xenolf/lego/providers/dns/ns1"
"github.com/xenolf/lego/providers/dns/ovh"
"github.com/xenolf/lego/providers/dns/pdns"
"github.com/xenolf/lego/providers/dns/route53"
"github.com/xenolf/lego/providers/dns/vultr"
)
Expand Down Expand Up @@ -68,6 +70,10 @@ type ProviderOpts struct {

// Vultr credentials
VultrApiKey string

// PowerDNS credentials
PDNSApiKey string
PDNSApiURL string
}

type Provider string
Expand All @@ -85,6 +91,7 @@ const (
ROUTE53 = Provider("Route53")
VULTR = Provider("Vultr")
HTTP = Provider("HTTP")
PDNS = Provider("PowerDNS")
)

type ProviderFactory struct {
Expand All @@ -104,6 +111,7 @@ var providerFactory = map[Provider]ProviderFactory{
OVH: ProviderFactory{makeOvhProvider, lego.DNS01},
ROUTE53: ProviderFactory{makeRoute53Provider, lego.DNS01},
VULTR: ProviderFactory{makeVultrProvider, lego.DNS01},
PDNS: ProviderFactory{makePDNSProvider, lego.DNS01},
HTTP: ProviderFactory{makeHTTPProvider, lego.HTTP01},
}

Expand Down Expand Up @@ -319,3 +327,24 @@ func makeNS1Provider(opts ProviderOpts) (lego.ChallengeProvider, error) {
}
return provider, nil
}

// returns a preconfigured PDNS lego.ChallengeProvider
func makePDNSProvider(opts ProviderOpts) (lego.ChallengeProvider, error) {
if len(opts.PDNSApiKey) == 0 {
return nil, fmt.Errorf("PDNS_API_KEY is not set")
}
if len(opts.PDNSApiURL) == 0 {
return nil, fmt.Errorf("PDNS_API_URL is not set")
}

apiURL, err := url.Parse(opts.PDNSApiURL)
if err != nil {
return nil, err
}

provider, err := pdns.NewDNSProviderCredentials(apiURL, opts.PDNSApiKey)
if err != nil {
return nil, err
}
return provider, nil
}
Loading