Skip to content

Commit

Permalink
Add Namecheap as DNS provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Fenby committed Apr 10, 2017
1 parent b7293e3 commit daa8584
Show file tree
Hide file tree
Showing 7 changed files with 457 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ A [Rancher](http://rancher.com/rancher/) service that obtains free SSL/TLS certi
* `DNSimple`
* `Dyn`
* `Gandi`
* `Namecheap`
* `NS1`
* `Ovh`
* `Vultr`
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),
NamecheapApiUser: getEnvOption("NAMECHEAP_API_USER", false),
NamecheapApiKey: getEnvOption("NAMECHEAP_API_KEY", false),
}

c.Acme, err = letsencrypt.NewClient(emailParam, keyType, apiVersion, providerOpts)
Expand Down
24 changes: 24 additions & 0 deletions letsencrypt/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/xenolf/lego/providers/dns/dnsimple"
"github.com/xenolf/lego/providers/dns/dyn"
"github.com/xenolf/lego/providers/dns/gandi"
"github.com/xenolf/lego/providers/dns/namecheap"
"github.com/xenolf/lego/providers/dns/ns1"
"github.com/xenolf/lego/providers/dns/ovh"
"github.com/xenolf/lego/providers/dns/route53"
Expand Down Expand Up @@ -58,6 +59,10 @@ type ProviderOpts struct {
// Gandi credentials
GandiApiKey string

// Namecheap credentials
NamecheapApiUser string
NamecheapApiKey string

// NS1 credentials
NS1ApiKey string

Expand All @@ -80,6 +85,7 @@ const (
DNSIMPLE = Provider("DNSimple")
DYN = Provider("Dyn")
GANDI = Provider("Gandi")
NAMECHEAP = Provider("Namecheap")
NS1 = Provider("NS1")
OVH = Provider("Ovh")
ROUTE53 = Provider("Route53")
Expand All @@ -100,6 +106,7 @@ var providerFactory = map[Provider]ProviderFactory{
DNSIMPLE: ProviderFactory{makeDNSimpleProvider, lego.DNS01},
DYN: ProviderFactory{makeDynProvider, lego.DNS01},
GANDI: ProviderFactory{makeGandiProvider, lego.DNS01},
NAMECHEAP: ProviderFactory{makeNamecheapProvider, lego.DNS01},
NS1: ProviderFactory{makeNS1Provider, lego.DNS01},
OVH: ProviderFactory{makeOvhProvider, lego.DNS01},
ROUTE53: ProviderFactory{makeRoute53Provider, lego.DNS01},
Expand Down Expand Up @@ -319,3 +326,20 @@ func makeNS1Provider(opts ProviderOpts) (lego.ChallengeProvider, error) {
}
return provider, nil
}

// returns a preconfigured Namecheap lego.ChallengeProvider
func makeNamecheapProvider(opts ProviderOpts) (lego.ChallengeProvider, error) {
if len(opts.NamecheapApiUser) == 0 {
return nil, fmt.Errorf("Namecheap API user is not set")
}

if len(opts.NamecheapApiKey) == 0 {
return nil, fmt.Errorf("Namecheap API key is not set")
}

provider, err := namecheap.NewDNSProviderCredentials(opts.NamecheapApiUser, opts.NamecheapApiKey)
if err != nil {
return nil, err
}
return provider, nil
}
Loading

0 comments on commit daa8584

Please sign in to comment.