mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
Add DNS provider for webnames.ca (#2698)
This commit is contained in:
parent
31772ec503
commit
7d099f2ad7
14 changed files with 822 additions and 4 deletions
|
|
@ -254,20 +254,20 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
|
|||
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnames/">Webnames</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnamesca/">webnames.ca</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/websupport/">Websupport</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/wedos/">WEDOS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/westcn/">West.cn/西部数码</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/yandex360/">Yandex 360</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/yandex360/">Yandex 360</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/yandexcloud/">Yandex Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/yandex/">Yandex PDD</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneee/">Zone.ee</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneedit/">ZoneEdit</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneedit/">ZoneEdit</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zonomi/">Zonomi</a></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr></table>
|
||||
|
||||
<!-- END DNS PROVIDERS LIST -->
|
||||
|
|
|
|||
22
cmd/zz_gen_cmd_dnshelp.go
generated
22
cmd/zz_gen_cmd_dnshelp.go
generated
|
|
@ -168,6 +168,7 @@ func allDNSCodes() string {
|
|||
"vscale",
|
||||
"vultr",
|
||||
"webnames",
|
||||
"webnamesca",
|
||||
"websupport",
|
||||
"wedos",
|
||||
"westcn",
|
||||
|
|
@ -3530,6 +3531,27 @@ func displayDNSHelp(w io.Writer, name string) error {
|
|||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/webnames`)
|
||||
|
||||
case "webnamesca":
|
||||
// generated from: providers/dns/webnamesca/webnamesca.toml
|
||||
ew.writeln(`Configuration for webnames.ca.`)
|
||||
ew.writeln(`Code: 'webnamesca'`)
|
||||
ew.writeln(`Since: 'v4.28.0'`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Credentials:`)
|
||||
ew.writeln(` - "WEBNAMESCA_API_KEY": API key`)
|
||||
ew.writeln(` - "WEBNAMESCA_API_USER": API username`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Additional Configuration:`)
|
||||
ew.writeln(` - "WEBNAMESCA_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`)
|
||||
ew.writeln(` - "WEBNAMESCA_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`)
|
||||
ew.writeln(` - "WEBNAMESCA_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`)
|
||||
ew.writeln(` - "WEBNAMESCA_TTL": The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)`)
|
||||
|
||||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/webnamesca`)
|
||||
|
||||
case "websupport":
|
||||
// generated from: providers/dns/websupport/websupport.toml
|
||||
ew.writeln(`Configuration for Websupport.`)
|
||||
|
|
|
|||
69
docs/content/dns/zz_gen_webnamesca.md
generated
Normal file
69
docs/content/dns/zz_gen_webnamesca.md
generated
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
---
|
||||
title: "webnames.ca"
|
||||
date: 2019-03-03T16:39:46+01:00
|
||||
draft: false
|
||||
slug: webnamesca
|
||||
dnsprovider:
|
||||
since: "v4.28.0"
|
||||
code: "webnamesca"
|
||||
url: "https://www.webnames.ca/"
|
||||
---
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/webnamesca/webnamesca.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
|
||||
|
||||
Configuration for [webnames.ca](https://www.webnames.ca/).
|
||||
|
||||
|
||||
<!--more-->
|
||||
|
||||
- Code: `webnamesca`
|
||||
- Since: v4.28.0
|
||||
|
||||
|
||||
Here is an example bash command using the webnames.ca provider:
|
||||
|
||||
```bash
|
||||
WEBNAMESCA_API_USER="xxx" \
|
||||
WEBNAMESCA_API_KEY="yyy" \
|
||||
lego --email you@example.com --dns webnamesca -d '*.example.com' -d example.com run
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## Credentials
|
||||
|
||||
| Environment Variable Name | Description |
|
||||
|-----------------------|-------------|
|
||||
| `WEBNAMESCA_API_KEY` | API key |
|
||||
| `WEBNAMESCA_API_USER` | API username |
|
||||
|
||||
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 |
|
||||
|--------------------------------|-------------|
|
||||
| `WEBNAMESCA_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) |
|
||||
| `WEBNAMESCA_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) |
|
||||
| `WEBNAMESCA_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) |
|
||||
| `WEBNAMESCA_TTL` | The TTL of the TXT record used for the DNS challenge in seconds (Default: 120) |
|
||||
|
||||
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://www.webnames.ca/_/swagger/index.html)
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/webnamesca/webnamesca.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
2
docs/data/zz_cli_help.toml
generated
2
docs/data/zz_cli_help.toml
generated
|
|
@ -152,7 +152,7 @@ To display the documentation for a specific DNS provider, run:
|
|||
$ lego dnshelp -c code
|
||||
|
||||
Supported DNS providers:
|
||||
acme-dns, active24, alidns, allinkl, anexia, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, beget, binarylane, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hostinger, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, keyhelp, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, octenium, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
|
||||
acme-dns, active24, alidns, allinkl, anexia, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, beget, binarylane, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hostinger, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, keyhelp, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, octenium, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, webnamesca, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
|
||||
|
||||
More information: https://go-acme.github.io/lego/dns
|
||||
"""
|
||||
|
|
|
|||
162
providers/dns/webnamesca/internal/client.go
Normal file
162
providers/dns/webnamesca/internal/client.go
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
|
||||
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
|
||||
)
|
||||
|
||||
const defaultBaseURL = "https://www.webnames.ca/_/APICore"
|
||||
|
||||
// Client the webnames.ca API client.
|
||||
type Client struct {
|
||||
user string
|
||||
key string
|
||||
|
||||
BaseURL *url.URL
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new Client.
|
||||
func NewClient(user, key string) (*Client, error) {
|
||||
if user == "" || key == "" {
|
||||
return nil, errors.New("credentials missing")
|
||||
}
|
||||
|
||||
baseURL, _ := url.Parse(defaultBaseURL)
|
||||
|
||||
return &Client{
|
||||
user: user,
|
||||
key: key,
|
||||
BaseURL: baseURL,
|
||||
HTTPClient: &http.Client{Timeout: 10 * time.Second},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddTXTRecord(ctx context.Context, domainName, hostName, value string) ([]DNSRecordSet, error) {
|
||||
endpoint := c.BaseURL.JoinPath("domains", domainName, "add-txt-record")
|
||||
|
||||
query := endpoint.Query()
|
||||
query.Set("hostName", hostName)
|
||||
query.Set("txt", value)
|
||||
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result APIResponse[*DNSInfo]
|
||||
|
||||
err = c.do(req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Result.DNSRecordSets, nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteTXTRecord(ctx context.Context, domainName, hostName, value string) ([]DNSRecordSet, error) {
|
||||
endpoint := c.BaseURL.JoinPath("domains", domainName, "delete-txt-record")
|
||||
|
||||
query := endpoint.Query()
|
||||
query.Set("hostName", hostName)
|
||||
query.Set("txt", value)
|
||||
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result APIResponse[*DNSInfo]
|
||||
|
||||
err = c.do(req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Result.DNSRecordSets, nil
|
||||
}
|
||||
|
||||
func (c *Client) do(req *http.Request, result any) error {
|
||||
useragent.SetHeader(req.Header)
|
||||
|
||||
req.Header.Set("API-User", c.user)
|
||||
req.Header.Set("API-Key", c.key)
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return errutils.NewHTTPDoError(req, err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
return parseError(req, resp)
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
raw, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errutils.NewReadResponseError(req, resp.StatusCode, err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(raw, result)
|
||||
if err != nil {
|
||||
return errutils.NewUnmarshalError(req, resp.StatusCode, raw, err)
|
||||
}
|
||||
|
||||
return 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)
|
||||
|
||||
var errAPI APIError
|
||||
|
||||
err := json.Unmarshal(raw, &errAPI)
|
||||
if err != nil {
|
||||
return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
|
||||
}
|
||||
|
||||
return &errAPI
|
||||
}
|
||||
96
providers/dns/webnamesca/internal/client_test.go
Normal file
96
providers/dns/webnamesca/internal/client_test.go
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/platform/tester/servermock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func mockBuilder() *servermock.Builder[*Client] {
|
||||
return servermock.NewBuilder[*Client](
|
||||
func(server *httptest.Server) (*Client, error) {
|
||||
client, err := NewClient("user", "secret")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client.BaseURL, _ = url.Parse(server.URL)
|
||||
client.HTTPClient = server.Client()
|
||||
|
||||
return client, nil
|
||||
},
|
||||
servermock.CheckHeader().
|
||||
With("API-User", "user").
|
||||
With("API-Key", "secret").
|
||||
WithJSONHeaders(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestClient_AddTXTRecord(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("POST /domains/example.com/add-txt-record",
|
||||
servermock.ResponseFromFixture("add_txt_record.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("hostName", "foo.example.com").
|
||||
With("txt", "value")).
|
||||
Build(t)
|
||||
|
||||
result, err := client.AddTXTRecord(t.Context(), "example.com", "foo.example.com", "value")
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []DNSRecordSet{{
|
||||
Hostname: "_acme-challenge.example.com",
|
||||
Type: "TXT",
|
||||
Records: []string{"value"},
|
||||
}}
|
||||
|
||||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func TestClient_AddTXTRecord_error(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("POST /domains/example.com/add-txt-record",
|
||||
servermock.ResponseFromFixture("error.json").
|
||||
WithStatusCode(http.StatusBadRequest)).
|
||||
Build(t)
|
||||
|
||||
_, err := client.AddTXTRecord(t.Context(), "example.com", "foo.example.com", "value")
|
||||
require.EqualError(t, err, "message: User does not exist., details: string, logiD: 35579, result: {}")
|
||||
}
|
||||
|
||||
func TestClient_DeleteTXTRecord(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("DELETE /domains/example.com/delete-txt-record",
|
||||
servermock.ResponseFromFixture("delete_txt_record.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("hostName", "foo.example.com").
|
||||
With("txt", "value")).
|
||||
Build(t)
|
||||
|
||||
result, err := client.DeleteTXTRecord(t.Context(), "example.com", "foo.example.com", "value")
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []DNSRecordSet{{
|
||||
Hostname: "_acme-challenge.example.com",
|
||||
Type: "TXT",
|
||||
Records: []string{"value"},
|
||||
}}
|
||||
|
||||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func TestClient_DeleteTXTRecord_error(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("DELETE /domains/example.com/delete-txt-record",
|
||||
servermock.ResponseFromFixture("error.json").
|
||||
WithStatusCode(http.StatusBadRequest)).
|
||||
Build(t)
|
||||
|
||||
_, err := client.DeleteTXTRecord(t.Context(), "example.com", "foo.example.com", "value")
|
||||
require.EqualError(t, err, "message: User does not exist., details: string, logiD: 35579, result: {}")
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"result": {
|
||||
"domainAdvancedDNSConfigID": 3258480,
|
||||
"domainID": 1333334,
|
||||
"dtCreated": "2025-10-30T11:55:23.243",
|
||||
"dtModified": "2025-10-30T11:55:23.177",
|
||||
"timeToLive": 21600,
|
||||
"soAorigin": "hosting.webnames.ca",
|
||||
"soArefresh": 21600,
|
||||
"soAretry": 180,
|
||||
"soAexpire": 1209600,
|
||||
"soAnegcache": 3600,
|
||||
"forwardingURL": null,
|
||||
"gripping": false,
|
||||
"name": null,
|
||||
"dtSubmitted": "2025-10-30T11:55:24.927",
|
||||
"dtRequestedDNSChange": null,
|
||||
"type": "REAL_DOMAIN",
|
||||
"userManaged": false,
|
||||
"effectiveMgmtOption": "AD",
|
||||
"urlForwardRootOnly": false,
|
||||
"enableDNSSEC": false,
|
||||
"dnsRecordSets": [
|
||||
{
|
||||
"hostname": "_acme-challenge.example.com",
|
||||
"type": "TXT",
|
||||
"records": [
|
||||
"value"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"logID": 36014
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"errorMessage": "string",
|
||||
"errorDetails": "string",
|
||||
"logID": 0,
|
||||
"result": {
|
||||
"domainAdvancedDNSConfigID": 0,
|
||||
"domainID": 0,
|
||||
"dtCreated": "2025-10-29T21:22:31.478",
|
||||
"dtModified": "2025-10-29T21:22:31.478",
|
||||
"timeToLive": 0,
|
||||
"soAorigin": "string",
|
||||
"soArefresh": 0,
|
||||
"soAretry": 0,
|
||||
"soAexpire": 0,
|
||||
"soAnegcache": 0,
|
||||
"forwardingURL": "string",
|
||||
"gripping": true,
|
||||
"name": "string",
|
||||
"dtSubmitted": "2025-10-29T21:22:31.478",
|
||||
"dtRequestedDNSChange": "2025-10-29T21:22:31.478",
|
||||
"type": "string",
|
||||
"userManaged": true,
|
||||
"effectiveMgmtOption": "string",
|
||||
"urlForwardRootOnly": true,
|
||||
"enableDNSSEC": true,
|
||||
"dnsRecordSets": [
|
||||
{
|
||||
"hostname": "_acme-challenge.example.com",
|
||||
"type": "TXT",
|
||||
"records": [
|
||||
"value"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
6
providers/dns/webnamesca/internal/fixtures/error.json
Normal file
6
providers/dns/webnamesca/internal/fixtures/error.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"errorMessage": "User does not exist.",
|
||||
"errorDetails": "string",
|
||||
"logID": 35579,
|
||||
"result": {}
|
||||
}
|
||||
33
providers/dns/webnamesca/internal/types.go
Normal file
33
providers/dns/webnamesca/internal/types.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
ErrorDetails string `json:"errorDetails,omitempty"`
|
||||
LogID int `json:"logID,omitempty"`
|
||||
Result json.RawMessage `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
func (a *APIError) Error() string {
|
||||
return fmt.Sprintf("message: %s, details: %s, logiD: %d, result: %s", a.ErrorMessage, a.ErrorDetails, a.LogID, a.Result)
|
||||
}
|
||||
|
||||
type APIResponse[T any] struct {
|
||||
Result T `json:"result,omitempty"`
|
||||
LogID int `json:"logID,omitempty"`
|
||||
}
|
||||
|
||||
type DNSInfo struct {
|
||||
DomainID int `json:"domainID,omitempty"`
|
||||
DNSRecordSets []DNSRecordSet `json:"dnsRecordSets,omitempty"`
|
||||
}
|
||||
|
||||
type DNSRecordSet struct {
|
||||
Hostname string `json:"hostname"`
|
||||
Type string `json:"type"`
|
||||
Records []string `json:"records"`
|
||||
}
|
||||
134
providers/dns/webnamesca/webnamesca.go
Normal file
134
providers/dns/webnamesca/webnamesca.go
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
// Package webnamesca implements a DNS provider for solving the DNS-01 challenge using webnames.ca.
|
||||
package webnamesca
|
||||
|
||||
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/internal/clientdebug"
|
||||
"github.com/go-acme/lego/v4/providers/dns/webnamesca/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "WEBNAMESCA_"
|
||||
|
||||
EnvAPIUser = envNamespace + "API_USER"
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
|
||||
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 {
|
||||
APIUser string
|
||||
APIKey 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, 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 webnames.ca.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(EnvAPIUser, EnvAPIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("webnamesca: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIUser = values[EnvAPIUser]
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
||||
// NewDNSProviderConfig return a DNSProvider instance configured for webnames.ca.
|
||||
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("webnamesca: the configuration of the DNS provider is nil")
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(config.APIUser, config.APIKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("webnamesca: %w", err)
|
||||
}
|
||||
|
||||
if config.HTTPClient != nil {
|
||||
client.HTTPClient = config.HTTPClient
|
||||
}
|
||||
|
||||
client.HTTPClient = clientdebug.Wrap(client.HTTPClient)
|
||||
|
||||
return &DNSProvider{
|
||||
config: config,
|
||||
client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Present creates a TXT record using the specified parameters.
|
||||
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("webnamesca: could not find zone for domain %q: %w", domain, err)
|
||||
}
|
||||
|
||||
_, err = d.client.AddTXTRecord(context.Background(), dns01.UnFqdn(authZone), dns01.UnFqdn(info.EffectiveFQDN), info.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("webnamesca: add TXT record: %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)
|
||||
|
||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||
if err != nil {
|
||||
return fmt.Errorf("webnamesca: could not find zone for domain %q: %w", domain, err)
|
||||
}
|
||||
|
||||
_, err = d.client.DeleteTXTRecord(context.Background(), dns01.UnFqdn(authZone), dns01.UnFqdn(info.EffectiveFQDN), info.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("webnamesca: delete TXT record: %w", err)
|
||||
}
|
||||
|
||||
return 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
|
||||
}
|
||||
24
providers/dns/webnamesca/webnamesca.toml
Normal file
24
providers/dns/webnamesca/webnamesca.toml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Name = "webnames.ca"
|
||||
Description = ''''''
|
||||
URL = "https://www.webnames.ca/"
|
||||
Code = "webnamesca"
|
||||
Since = "v4.28.0"
|
||||
|
||||
Example = '''
|
||||
WEBNAMESCA_API_USER="xxx" \
|
||||
WEBNAMESCA_API_KEY="yyy" \
|
||||
lego --email you@example.com --dns webnamesca -d '*.example.com' -d example.com run
|
||||
'''
|
||||
|
||||
[Configuration]
|
||||
[Configuration.Credentials]
|
||||
WEBNAMESCA_API_USER = "API username"
|
||||
WEBNAMESCA_API_KEY = "API key"
|
||||
[Configuration.Additional]
|
||||
WEBNAMESCA_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
|
||||
WEBNAMESCA_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
|
||||
WEBNAMESCA_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
|
||||
WEBNAMESCA_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
|
||||
|
||||
[Links]
|
||||
API = "https://www.webnames.ca/_/swagger/index.html"
|
||||
199
providers/dns/webnamesca/webnamesca_test.go
Normal file
199
providers/dns/webnamesca/webnamesca_test.go
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
package webnamesca
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/platform/tester"
|
||||
"github.com/go-acme/lego/v4/platform/tester/servermock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIUser, EnvAPIKey).WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
envVars map[string]string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
EnvAPIUser: "user",
|
||||
EnvAPIKey: "secret",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing EnvAPIUser",
|
||||
envVars: map[string]string{
|
||||
EnvAPIUser: "",
|
||||
EnvAPIKey: "secret",
|
||||
},
|
||||
expected: "webnamesca: some credentials information are missing: WEBNAMESCA_API_USER",
|
||||
},
|
||||
{
|
||||
desc: "missing EnvAPIKey",
|
||||
envVars: map[string]string{
|
||||
EnvAPIUser: "user",
|
||||
EnvAPIKey: "",
|
||||
},
|
||||
expected: "webnamesca: some credentials information are missing: WEBNAMESCA_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{},
|
||||
expected: "webnamesca: some credentials information are missing: WEBNAMESCA_API_USER,WEBNAMESCA_API_KEY",
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
require.NotNil(t, p.client)
|
||||
} else {
|
||||
require.EqualError(t, err, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDNSProviderConfig(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
apiUser string
|
||||
apiKey string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "success",
|
||||
apiUser: "user",
|
||||
apiKey: "secret",
|
||||
},
|
||||
{
|
||||
desc: "missing apiUser",
|
||||
apiKey: "secret",
|
||||
expected: "webnamesca: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing apiKey",
|
||||
apiUser: "user",
|
||||
expected: "webnamesca: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
expected: "webnamesca: credentials missing",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := NewDefaultConfig()
|
||||
config.APIUser = test.apiUser
|
||||
config.APIKey = test.apiKey
|
||||
|
||||
p, err := NewDNSProviderConfig(config)
|
||||
|
||||
if test.expected == "" {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
require.NotNil(t, p.config)
|
||||
require.NotNil(t, p.client)
|
||||
} else {
|
||||
require.EqualError(t, err, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLivePresent(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)
|
||||
}
|
||||
|
||||
func TestLiveCleanUp(t *testing.T) {
|
||||
if !envTest.IsLiveTest() {
|
||||
t.Skip("skipping live test")
|
||||
}
|
||||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func mockBuilder() *servermock.Builder[*DNSProvider] {
|
||||
return servermock.NewBuilder(
|
||||
func(server *httptest.Server) (*DNSProvider, error) {
|
||||
config := NewDefaultConfig()
|
||||
config.APIUser = "user"
|
||||
config.APIKey = "secret"
|
||||
config.HTTPClient = server.Client()
|
||||
|
||||
p, err := NewDNSProviderConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.client.BaseURL, _ = url.Parse(server.URL)
|
||||
|
||||
return p, nil
|
||||
},
|
||||
servermock.CheckHeader().
|
||||
WithJSONHeaders().
|
||||
With("API-User", "user").
|
||||
With("API-Key", "secret"),
|
||||
)
|
||||
}
|
||||
|
||||
func TestDNSProvider_Present(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("POST /domains/example.com/add-txt-record",
|
||||
servermock.ResponseFromInternal("add_txt_record.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("hostName", "_acme-challenge.example.com").
|
||||
With("txt", "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY")).
|
||||
Build(t)
|
||||
|
||||
err := provider.Present("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("DELETE /domains/example.com/delete-txt-record",
|
||||
servermock.ResponseFromInternal("delete_txt_record.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("hostName", "_acme-challenge.example.com").
|
||||
With("txt", "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY")).
|
||||
Build(t)
|
||||
|
||||
err := provider.CleanUp("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
3
providers/dns/zz_gen_dns_providers.go
generated
3
providers/dns/zz_gen_dns_providers.go
generated
|
|
@ -162,6 +162,7 @@ import (
|
|||
"github.com/go-acme/lego/v4/providers/dns/vscale"
|
||||
"github.com/go-acme/lego/v4/providers/dns/vultr"
|
||||
"github.com/go-acme/lego/v4/providers/dns/webnames"
|
||||
"github.com/go-acme/lego/v4/providers/dns/webnamesca"
|
||||
"github.com/go-acme/lego/v4/providers/dns/websupport"
|
||||
"github.com/go-acme/lego/v4/providers/dns/wedos"
|
||||
"github.com/go-acme/lego/v4/providers/dns/westcn"
|
||||
|
|
@ -488,6 +489,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||
return vultr.NewDNSProvider()
|
||||
case "webnames":
|
||||
return webnames.NewDNSProvider()
|
||||
case "webnamesca":
|
||||
return webnamesca.NewDNSProvider()
|
||||
case "websupport":
|
||||
return websupport.NewDNSProvider()
|
||||
case "wedos":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue