1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-25 11:02:56 +02:00

Add DNS provider for RcodeZero (#1947)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Michael Braunöder 2023-07-01 00:51:17 +02:00 committed by GitHub
parent 9d193056f7
commit 2d4dc8fb38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 633 additions and 9 deletions

View File

@ -75,14 +75,14 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
| [Netcup](https://go-acme.github.io/lego/dns/netcup/) | [Netlify](https://go-acme.github.io/lego/dns/netlify/) | [Nicmanager](https://go-acme.github.io/lego/dns/nicmanager/) | [NIFCloud](https://go-acme.github.io/lego/dns/nifcloud/) |
| [Njalla](https://go-acme.github.io/lego/dns/njalla/) | [Nodion](https://go-acme.github.io/lego/dns/nodion/) | [NS1](https://go-acme.github.io/lego/dns/ns1/) | [Open Telekom Cloud](https://go-acme.github.io/lego/dns/otc/) |
| [Oracle Cloud](https://go-acme.github.io/lego/dns/oraclecloud/) | [OVH](https://go-acme.github.io/lego/dns/ovh/) | [plesk.com](https://go-acme.github.io/lego/dns/plesk/) | [Porkbun](https://go-acme.github.io/lego/dns/porkbun/) |
| [PowerDNS](https://go-acme.github.io/lego/dns/pdns/) | [Rackspace](https://go-acme.github.io/lego/dns/rackspace/) | [reg.ru](https://go-acme.github.io/lego/dns/regru/) | [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) |
| [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) | [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) | [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) | [Selectel](https://go-acme.github.io/lego/dns/selectel/) |
| [Servercow](https://go-acme.github.io/lego/dns/servercow/) | [Simply.com](https://go-acme.github.io/lego/dns/simply/) | [Sonic](https://go-acme.github.io/lego/dns/sonic/) | [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) |
| [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) | [TransIP](https://go-acme.github.io/lego/dns/transip/) | [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [Ultradns](https://go-acme.github.io/lego/dns/ultradns/) |
| [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) | [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) | [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) |
| [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | [VK Cloud](https://go-acme.github.io/lego/dns/vkcloud/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) |
| [Websupport](https://go-acme.github.io/lego/dns/websupport/) | [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex Cloud](https://go-acme.github.io/lego/dns/yandexcloud/) | [Yandex PDD](https://go-acme.github.io/lego/dns/yandex/) |
| [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | | |
| [PowerDNS](https://go-acme.github.io/lego/dns/pdns/) | [Rackspace](https://go-acme.github.io/lego/dns/rackspace/) | [RcodeZero](https://go-acme.github.io/lego/dns/rcodezero/) | [reg.ru](https://go-acme.github.io/lego/dns/regru/) |
| [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) | [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) | [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) | [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) |
| [Selectel](https://go-acme.github.io/lego/dns/selectel/) | [Servercow](https://go-acme.github.io/lego/dns/servercow/) | [Simply.com](https://go-acme.github.io/lego/dns/simply/) | [Sonic](https://go-acme.github.io/lego/dns/sonic/) |
| [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) | [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) | [TransIP](https://go-acme.github.io/lego/dns/transip/) | [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) |
| [Ultradns](https://go-acme.github.io/lego/dns/ultradns/) | [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) | [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) |
| [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) | [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | [VK Cloud](https://go-acme.github.io/lego/dns/vkcloud/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) |
| [Vultr](https://go-acme.github.io/lego/dns/vultr/) | [Websupport](https://go-acme.github.io/lego/dns/websupport/) | [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex Cloud](https://go-acme.github.io/lego/dns/yandexcloud/) |
| [Yandex PDD](https://go-acme.github.io/lego/dns/yandex/) | [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | |
<!-- END DNS PROVIDERS LIST -->

View File

@ -102,6 +102,7 @@ func allDNSCodes() string {
"plesk",
"porkbun",
"rackspace",
"rcodezero",
"regru",
"rfc2136",
"rimuhosting",
@ -2001,6 +2002,26 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/rackspace`)
case "rcodezero":
// generated from: providers/dns/rcodezero/rcodezero.toml
ew.writeln(`Configuration for RcodeZero.`)
ew.writeln(`Code: 'rcodezero'`)
ew.writeln(`Since: 'v4.13'`)
ew.writeln()
ew.writeln(`Credentials:`)
ew.writeln(` - "RCODEZERO_API_TOKEN": API token`)
ew.writeln()
ew.writeln(`Additional Configuration:`)
ew.writeln(` - "RCODEZERO_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "RCODEZERO_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "RCODEZERO_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "RCODEZERO_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/rcodezero`)
case "regru":
// generated from: providers/dns/regru/regru.toml
ew.writeln(`Configuration for reg.ru.`)

View File

@ -0,0 +1,74 @@
---
title: "RcodeZero"
date: 2019-03-03T16:39:46+01:00
draft: false
slug: rcodezero
dnsprovider:
since: "v4.13"
code: "rcodezero"
url: "https://www.rcodezero.at/"
---
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/rcodezero/rcodezero.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
Configuration for [RcodeZero](https://www.rcodezero.at/).
<!--more-->
- Code: `rcodezero`
- Since: v4.13
Here is an example bash command using the RcodeZero provider:
```bash
RCODEZERO_API_TOKEN=<mytoken> \
lego --email you@example.com --dns rcodezero --domains my.example.org run
```
## Credentials
| Environment Variable Name | Description |
|-----------------------|-------------|
| `RCODEZERO_API_TOKEN` | API token |
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 |
|--------------------------------|-------------|
| `RCODEZERO_HTTP_TIMEOUT` | API request timeout |
| `RCODEZERO_POLLING_INTERVAL` | Time between DNS propagation check |
| `RCODEZERO_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `RCODEZERO_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" >}}).
## Description
Generate your API Token via https://my.rcodezero.at with the `ACME` permissions.
This are special tokens with limited access for ACME requests only.
RcodeZero is an Anycast Network so the distribution of the DNS01-Challenge can take up to 2 minutes.
## More information
- [API documentation](https://my.rcodezero.at/openapi)
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/rcodezero/rcodezero.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

View File

@ -136,7 +136,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, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudxns, conoha, constellix, derak, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, 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, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, 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, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudxns, conoha, constellix, derak, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, 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, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, 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
"""

View File

@ -93,6 +93,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/plesk"
"github.com/go-acme/lego/v4/providers/dns/porkbun"
"github.com/go-acme/lego/v4/providers/dns/rackspace"
"github.com/go-acme/lego/v4/providers/dns/rcodezero"
"github.com/go-acme/lego/v4/providers/dns/regru"
"github.com/go-acme/lego/v4/providers/dns/rfc2136"
"github.com/go-acme/lego/v4/providers/dns/rimuhosting"
@ -305,6 +306,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return porkbun.NewDNSProvider()
case "rackspace":
return rackspace.NewDNSProvider()
case "rcodezero":
return rcodezero.NewDNSProvider()
case "regru":
return regru.NewDNSProvider()
case "rfc2136":

View File

@ -0,0 +1,114 @@
package internal
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
"github.com/miekg/dns"
)
const defaultBaseURL = "https://my.rcodezero.at/api"
const authorizationHeader = "Authorization"
// Client for the RcodeZero API.
type Client struct {
apiToken string
baseURL *url.URL
HTTPClient *http.Client
}
// NewClient creates a new Client.
func NewClient(apiToken string) *Client {
baseURL, _ := url.Parse(defaultBaseURL)
return &Client{
apiToken: apiToken,
baseURL: baseURL,
HTTPClient: &http.Client{Timeout: 5 * time.Second},
}
}
func (c *Client) UpdateRecords(ctx context.Context, authZone string, sets []UpdateRRSet) (*APIResponse, error) {
endpoint := c.baseURL.JoinPath("v1", "acme", "zones", strings.TrimSuffix(dns.Fqdn(authZone), "."), "rrsets")
req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, sets)
if err != nil {
return nil, err
}
return c.do(req)
}
func (c *Client) do(req *http.Request) (*APIResponse, error) {
req.Header.Set(authorizationHeader, "Bearer "+c.apiToken)
resp, err := c.HTTPClient.Do(req)
if err != nil {
return nil, errutils.NewHTTPDoError(req, err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode/100 != 2 {
return nil, parseError(req, resp)
}
result := &APIResponse{}
raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, errutils.NewReadResponseError(req, resp.StatusCode, err)
}
err = json.Unmarshal(raw, result)
if err != nil {
return nil, errutils.NewUnmarshalError(req, resp.StatusCode, raw, err)
}
return result, nil
}
func newJSONRequest(ctx context.Context, method string, endpoint *url.URL, payload any) (*http.Request, error) {
buf := new(bytes.Buffer)
if payload != nil {
err := json.NewEncoder(buf).Encode(payload)
if err != nil {
return nil, fmt.Errorf("failed to create request JSON body: %w", err)
}
}
req, err := http.NewRequestWithContext(ctx, method, endpoint.String(), buf)
if err != nil {
return nil, fmt.Errorf("unable to create request: %w", err)
}
req.Header.Set("Accept", "application/json")
if payload != nil {
req.Header.Set("Content-Type", "application/json")
}
return req, nil
}
func parseError(req *http.Request, resp *http.Response) error {
raw, _ := io.ReadAll(resp.Body)
errAPI := &APIResponse{}
err := json.Unmarshal(raw, errAPI)
if err != nil {
return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
}
return fmt.Errorf("[status code: %d] %w", resp.StatusCode, errAPI)
}

View File

@ -0,0 +1,96 @@
package internal
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupTest(t *testing.T, method, pattern string, status int, file string) *Client {
t.Helper()
mux := http.NewServeMux()
server := httptest.NewServer(mux)
t.Cleanup(server.Close)
mux.HandleFunc(pattern, func(rw http.ResponseWriter, req *http.Request) {
if req.Method != method {
http.Error(rw, fmt.Sprintf("unsupported method: %s", req.Method), http.StatusBadRequest)
return
}
apiToken := req.Header.Get(authorizationHeader)
if apiToken != "Bearer secret" {
http.Error(rw, fmt.Sprintf("invalid credentials: %s", apiToken), http.StatusBadRequest)
return
}
if file == "" {
rw.WriteHeader(status)
return
}
open, err := os.Open(filepath.Join("fixtures", file))
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
defer func() { _ = open.Close() }()
rw.WriteHeader(status)
_, err = io.Copy(rw, open)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
})
client := NewClient("secret")
client.HTTPClient = server.Client()
client.baseURL, _ = url.Parse(server.URL)
return client
}
func TestClient_UpdateRecords_error(t *testing.T) {
client := setupTest(t, http.MethodPatch, "/v1/acme/zones/example.org/rrsets", http.StatusUnprocessableEntity, "error.json")
rrSet := []UpdateRRSet{{
Name: "acme.example.org.",
ChangeType: "add",
Type: "TXT",
Records: []Record{{Content: `"my-acme-challenge"`}},
}}
resp, err := client.UpdateRecords(context.Background(), "example.org", rrSet)
require.ErrorAs(t, err, new(*APIResponse))
assert.Nil(t, resp)
}
func TestClient_UpdateRecords(t *testing.T) {
client := setupTest(t, http.MethodPatch, "/v1/acme/zones/example.org/rrsets", http.StatusOK, "rrsets-response.json")
rrSet := []UpdateRRSet{{
Name: "acme.example.org.",
ChangeType: "add",
Type: "TXT",
Records: []Record{{Content: `"my-acme-challenge"`}},
}}
resp, err := client.UpdateRecords(context.Background(), "example.org", rrSet)
require.NoError(t, err)
expected := &APIResponse{Status: "ok", Message: "RRsets updated"}
assert.Equal(t, expected, resp)
}

View File

@ -0,0 +1,4 @@
{
"status": "failed",
"message": "A human readable error message"
}

View File

@ -0,0 +1,4 @@
{
"status": "ok",
"message": "RRsets updated"
}

View File

@ -0,0 +1,25 @@
package internal
import "fmt"
type UpdateRRSet struct {
Name string `json:"name"`
Type string `json:"type"`
ChangeType string `json:"changetype"`
Records []Record `json:"records"`
TTL int `json:"ttl"`
}
type Record struct {
Content string `json:"content"`
Disabled bool `json:"disabled"`
}
type APIResponse struct {
Status string `json:"status"`
Message string `json:"message"`
}
func (a APIResponse) Error() string {
return fmt.Sprintf("%s: %s", a.Status, a.Message)
}

View File

@ -0,0 +1,145 @@
// Package rcodezero implements a DNS provider for solving the DNS-01 challenge using RcodeZero Anycast network.
package rcodezero
import (
"context"
"errors"
"fmt"
"net/http"
"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/rcodezero/internal"
)
// Environment variables names.
const (
envNamespace = "RCODEZERO_"
EnvAPIToken = envNamespace + "API_TOKEN"
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 {
APIToken string
PropagationTimeout time.Duration
PollingInterval time.Duration
TTL int
HTTPClient *http.Client
}
// NewDefaultConfig returns a default configuration for the DNSProvider.
func NewDefaultConfig() *Config {
return &Config{
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 240*time.Second),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 10*time.Second),
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 RcodeZero.
// Credentials must be passed in the environment variable:
// RCODEZERO_API_URL and RCODEZERO_API_TOKEN.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIToken)
if err != nil {
return nil, fmt.Errorf("rcodezero: %w", err)
}
config := NewDefaultConfig()
config.APIToken = values[EnvAPIToken]
return NewDNSProviderConfig(config)
}
// NewDNSProviderConfig return a DNSProvider instance configured for RcodeZero.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("rcodezero: the configuration of the DNS provider is nil")
}
if config.APIToken == "" {
return nil, errors.New("rcodezero: API token missing")
}
client := internal.NewClient(config.APIToken)
if config.HTTPClient != nil {
client.HTTPClient = 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)
ctx := context.Background()
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("rcodezero: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
}
rrSet := []internal.UpdateRRSet{{
Name: info.EffectiveFQDN,
ChangeType: "update",
Type: "TXT",
TTL: d.config.TTL,
Records: []internal.Record{{Content: `"` + info.Value + `"`}},
}}
_, err = d.client.UpdateRecords(ctx, authZone, rrSet)
if err != nil {
return fmt.Errorf("rcodezero: %w", err)
}
return nil
}
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
info := dns01.GetChallengeInfo(domain, keyAuth)
ctx := context.Background()
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("rcodezero: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
}
rrSet := []internal.UpdateRRSet{{
Name: info.EffectiveFQDN,
Type: "TXT",
ChangeType: "delete",
}}
_, err = d.client.UpdateRecords(ctx, authZone, rrSet)
if err != nil {
return fmt.Errorf("rcodezero: %w", err)
}
return nil
}

View File

@ -0,0 +1,33 @@
Name = "RcodeZero"
Description = ''''''
URL = "https://www.rcodezero.at/"
Code = "rcodezero"
Since = "v4.13"
Example = '''
RCODEZERO_API_TOKEN=<mytoken> \
lego --email you@example.com --dns rcodezero --domains my.example.org run
'''
Additional = '''
## Description
Generate your API Token via https://my.rcodezero.at with the `ACME` permissions.
This are special tokens with limited access for ACME requests only.
RcodeZero is an Anycast Network so the distribution of the DNS01-Challenge can take up to 2 minutes.
'''
[Configuration]
[Configuration.Credentials]
RCODEZERO_API_TOKEN = "API token"
[Configuration.Additional]
RCODEZERO_POLLING_INTERVAL = "Time between DNS propagation check"
RCODEZERO_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
RCODEZERO_TTL = "The TTL of the TXT record used for the DNS challenge"
RCODEZERO_HTTP_TIMEOUT = "API request timeout"
[Links]
# Note: the API endpoint used inside the client is not documented.
API = "https://my.rcodezero.at/openapi"

View File

@ -0,0 +1,105 @@
package rcodezero
import (
"testing"
"github.com/go-acme/lego/v4/platform/tester"
"github.com/stretchr/testify/require"
)
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest(
EnvAPIToken).
WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "success",
envVars: map[string]string{
EnvAPIToken: "123",
},
},
{
desc: "missing credentials",
envVars: map[string]string{
EnvAPIToken: "",
},
expected: "rcodezero: some credentials information are missing: RCODEZERO_API_TOKEN",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
defer envTest.RestoreEnv()
envTest.ClearEnv()
envTest.Apply(test.envVars)
p, err := NewDNSProvider()
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
apiToken string
expected string
}{
{
desc: "success",
apiToken: "123",
},
{
desc: "missing credentials",
expected: "rcodezero: API token missing",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.APIToken = test.apiToken
p, err := NewDNSProviderConfig(config)
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestLivePresentAndCleanup(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}