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 DNS provider for Combell (reseller only) #1581

Open
wants to merge 2 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
53 changes: 27 additions & 26 deletions README.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func allDNSCodes() string {
"cloudns",
"cloudru",
"cloudxns",
"combell",
"conoha",
"constellix",
"derak",
Expand Down Expand Up @@ -561,6 +562,27 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/cloudxns`)

case "combell":
// generated from: providers/dns/combell/combell.toml
ew.writeln(`Configuration for Combell.`)
ew.writeln(`Code: 'combell'`)
ew.writeln(`Since: 'v4.14.0'`)
ew.writeln()

ew.writeln(`Credentials:`)
ew.writeln(` - "COMBELL_API_KEY": The API key`)
ew.writeln(` - "COMBELL_API_SECRET": The API secret`)
ew.writeln()

ew.writeln(`Additional Configuration:`)
ew.writeln(` - "COMBELL_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "COMBELL_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "COMBELL_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "COMBELL_TTL": The TTL of the TXT record used for the DNS challenge`)

ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/combell`)

case "conoha":
// generated from: providers/dns/conoha/conoha.toml
ew.writeln(`Configuration for ConoHa.`)
Expand Down
69 changes: 69 additions & 0 deletions docs/content/dns/zz_gen_combell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: "Combell"
date: 2019-03-03T16:39:46+01:00
draft: false
slug: combell
dnsprovider:
since: "v4.14.0"
code: "combell"
url: "https://www.combell.com/"
---

<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/combell/combell.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->


Configuration for [Combell](https://www.combell.com/).


<!--more-->

- Code: `combell`
- Since: v4.14.0


Here is an example bash command using the Combell provider:

```bash
COMBELL_API_KEY=xxxxxxxxxxxxxxxxxxxxx \
COMBELL_API_SECRET=yyyyyyyyyyyyyyyyyyyy \
lego --email [email protected] --dns combell --domains my.example.org run
```




## Credentials

| Environment Variable Name | Description |
|-----------------------|-------------|
| `COMBELL_API_KEY` | The API key |
| `COMBELL_API_SECRET` | The API secret |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).


## Additional Configuration

| Environment Variable Name | Description |
|--------------------------------|-------------|
| `COMBELL_HTTP_TIMEOUT` | API request timeout |
| `COMBELL_POLLING_INTERVAL` | Time between DNS propagation check |
| `COMBELL_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `COMBELL_TTL` | The TTL of the TXT record used for the DNS challenge |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).




## More information

- [API documentation](https://api.combell.com/v2/documentation)

<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/combell/combell.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
2 changes: 1 addition & 1 deletion docs/data/zz_cli_help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ To display the documentation for a specific DNS provider, run:
$ lego dnshelp -c code

Supported DNS providers:
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, derak, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpreq, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, metaname, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rcodezero, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, servercow, simply, sonic, stackpath, tencentcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, vscale, vultr, websupport, wedos, yandex, yandexcloud, zoneee, zonomi
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, combell, conoha, constellix, derak, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpreq, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, metaname, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rcodezero, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, servercow, simply, sonic, stackpath, tencentcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, vscale, vultr, websupport, wedos, yandex, yandexcloud, zoneee, zonomi

More information: https://go-acme.github.io/lego/dns
"""
161 changes: 161 additions & 0 deletions providers/dns/combell/combell.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Package combell implements a DNS provider for solving the DNS-01 challenge using Combell DNS.
package combell

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/platform/config/env"
"github.com/go-acme/lego/v4/providers/dns/combell/internal"
)

const (
minTTL = 60
maxTTL = 8640
)

// Environment variables names.
const (
envNamespace = "COMBELL_"

EnvAPIKey = envNamespace + "API_KEY"
EnvAPISecret = envNamespace + "API_SECRET"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
)

// Config is used to configure the creation of the DNSProvider.
type Config struct {
APIKey string
APISecret string
TTL int
PropagationTimeout time.Duration
PollingInterval time.Duration
HTTPClient *http.Client
}

// NewDefaultConfig returns a default configuration for the DNSProvider.
func NewDefaultConfig() *Config {
return &Config{
TTL: env.GetOrDefaultInt(EnvTTL, 3600),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
},
}
}

// DNSProvider implements the challenge.Provider interface.
type DNSProvider struct {
config *Config
client *internal.Client
}

// NewDNSProvider returns a DNSProvider instance configured for Combell DNS.
// Credentials must be passed in the environment variables:
// COMBELL_API_KEY, COMBELL_API_SECRET.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIKey, EnvAPISecret)
if err != nil {
return nil, fmt.Errorf("combell: %w", err)
}

config := NewDefaultConfig()
config.APIKey = values[EnvAPIKey]
config.APISecret = values[EnvAPISecret]

return NewDNSProviderConfig(config)
}

// NewDNSProviderConfig return a DNSProvider instance configured for Combell DNS.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("combell: the configuration of the DNS provider is nil")
}

if config.APIKey == "" || config.APISecret == "" {
return nil, errors.New("combell: some credentials information are missing")
}

if config.TTL < minTTL {
return nil, fmt.Errorf("combell: invalid TTL, TTL (%d) must be greater than %d", config.TTL, minTTL)
}

if config.TTL > maxTTL {
return nil, fmt.Errorf("combell: invalid TTL, TTL (%d) must be lower than %d", config.TTL, maxTTL)
}

client := internal.NewClient(config.APIKey, config.APISecret, config.HTTPClient)

return &DNSProvider{config: config, client: client}, nil
}

// Timeout returns the timeout and interval to use when checking for DNS propagation.
// Adjusting here to cope with spikes in propagation times.
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}

// Present creates a TXT record to fulfill the dns-01 challenge.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("combell: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
}

record := internal.Record{
Type: "TXT",
RecordName: dns01.UnFqdn(strings.TrimSuffix(info.EffectiveFQDN, authZone)),
Content: info.Value,
TTL: d.config.TTL,
}

err = d.client.CreateRecord(context.Background(), authZone, record)
if err != nil {
return fmt.Errorf("combell: create record: %w", err)
}

return nil
}

// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()
info := dns01.GetChallengeInfo(domain, keyAuth)

authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("combell: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
}

request := &internal.GetRecordsRequest{
Type: "TXT",
RecordName: dns01.UnFqdn(strings.TrimSuffix(info.EffectiveFQDN, authZone)),
}
records, err := d.client.GetRecords(ctx, authZone, request)
if err != nil {
return fmt.Errorf("combell: get records: %w", err)
}

for _, record := range records {
if record.Content == info.Value {
err = d.client.DeleteRecord(ctx, authZone, record.ID)
if err != nil {
return fmt.Errorf("combell: delete record: %w", err)
}
}
}

return nil
}
24 changes: 24 additions & 0 deletions providers/dns/combell/combell.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Name = "Combell"
Description = ''''''
URL = "https://www.combell.com/"
Code = "combell"
Since = "v4.14.0"

Example = '''
COMBELL_API_KEY=xxxxxxxxxxxxxxxxxxxxx \
COMBELL_API_SECRET=yyyyyyyyyyyyyyyyyyyy \
lego --email [email protected] --dns combell --domains my.example.org run
'''

[Configuration]
[Configuration.Credentials]
COMBELL_API_KEY = "The API key"
COMBELL_API_SECRET = "The API secret"
[Configuration.Additional]
COMBELL_POLLING_INTERVAL = "Time between DNS propagation check"
COMBELL_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
COMBELL_TTL = "The TTL of the TXT record used for the DNS challenge"
COMBELL_HTTP_TIMEOUT = "API request timeout"

[Links]
API = "https://api.combell.com/v2/documentation"
Loading