diff --git a/README.md b/README.md
index 570a340e5..3b395aad9 100644
--- a/README.md
+++ b/README.md
@@ -146,138 +146,138 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
| Hetzner |
Hosting.de |
+ Hosting.nl |
Hostinger |
- Hosttech |
+ | Hosttech |
HTTP request |
http.net |
Huawei Cloud |
- Hurricane Electric DNS |
+ | Hurricane Electric DNS |
HyperOne |
IBM Cloud (SoftLayer) |
IIJ DNS Platform Service |
- Infoblox |
+ | Infoblox |
Infomaniak |
Internet Initiative Japan |
Internet.bs |
- INWX |
+ | INWX |
Ionos |
IPv64 |
iwantmyname (Deprecated) |
- Joker |
+ | Joker |
Joohoi's ACME-DNS |
KeyHelp |
Liara |
- Lima-City |
+ | Lima-City |
Linode (v4) |
Liquid Web |
Loopia |
- LuaDNS |
+ | LuaDNS |
Mail-in-a-Box |
ManageEngine CloudDNS |
Manual |
- Metaname |
+ | Metaname |
Metaregistrar |
mijn.host |
Mittwald |
- myaddr.{tools,dev,io} |
+ | myaddr.{tools,dev,io} |
MyDNS.jp |
MythicBeasts |
Name.com |
- Namecheap |
+ | Namecheap |
Namesilo |
NearlyFreeSpeech.NET |
Neodigit |
- Netcup |
+ | Netcup |
Netlify |
Nicmanager |
NIFCloud |
- Njalla |
+ | Njalla |
Nodion |
NS1 |
Octenium |
- Open Telekom Cloud |
+ | Open Telekom Cloud |
Oracle Cloud |
OVH |
plesk.com |
- Porkbun |
+ | Porkbun |
PowerDNS |
Rackspace |
Rain Yun/雨云 |
- RcodeZero |
+ | RcodeZero |
reg.ru |
Regfish |
RFC2136 |
- RimuHosting |
+ | RimuHosting |
RU CENTER |
Sakura Cloud |
Scaleway |
- Selectel |
+ | Selectel |
Selectel v2 |
SelfHost.(de|eu) |
Servercow |
- Shellrent |
+ | Shellrent |
Simply.com |
Sonic |
Spaceship |
- Stackpath |
+ | Stackpath |
Syse |
Technitium |
Tencent Cloud DNS |
- Tencent EdgeOne |
+ | Tencent EdgeOne |
Timeweb Cloud |
TransIP |
UKFast SafeDNS |
- Ultradns |
+ | Ultradns |
United-Domains |
Variomedia |
VegaDNS |
- Vercel |
+ | Vercel |
Versio.[nl|eu|uk] |
VinylDNS |
Virtualname |
- VK Cloud |
+ | VK Cloud |
Volcano Engine/火山引擎 |
Vscale |
Vultr |
- webnames.ca |
+ | webnames.ca |
webnames.ru |
Websupport |
WEDOS |
- West.cn/西部数码 |
+ | West.cn/西部数码 |
Yandex 360 |
Yandex Cloud |
Yandex PDD |
- Zone.ee |
+ | Zone.ee |
ZoneEdit |
Zonomi |
|
- |
diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go
index ebd4cc72b..89b3ce7e1 100644
--- a/cmd/zz_gen_cmd_dnshelp.go
+++ b/cmd/zz_gen_cmd_dnshelp.go
@@ -83,6 +83,7 @@ func allDNSCodes() string {
"hetzner",
"hostingde",
"hostinger",
+ "hostingnl",
"hosttech",
"httpnet",
"httpreq",
@@ -1723,6 +1724,26 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/hostinger`)
+ case "hostingnl":
+ // generated from: providers/dns/hostingnl/hostingnl.toml
+ ew.writeln(`Configuration for Hosting.nl.`)
+ ew.writeln(`Code: 'hostingnl'`)
+ ew.writeln(`Since: 'v4.30.0'`)
+ ew.writeln()
+
+ ew.writeln(`Credentials:`)
+ ew.writeln(` - "HOSTINGNL_API_KEY": The API key`)
+ ew.writeln()
+
+ ew.writeln(`Additional Configuration:`)
+ ew.writeln(` - "HOSTINGNL_HTTP_TIMEOUT": API request timeout in seconds (Default: 10)`)
+ ew.writeln(` - "HOSTINGNL_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`)
+ ew.writeln(` - "HOSTINGNL_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 120)`)
+ ew.writeln(` - "HOSTINGNL_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/hostingnl`)
+
case "hosttech":
// generated from: providers/dns/hosttech/hosttech.toml
ew.writeln(`Configuration for Hosttech.`)
diff --git a/docs/content/dns/zz_gen_hostingnl.md b/docs/content/dns/zz_gen_hostingnl.md
new file mode 100644
index 000000000..0577affd4
--- /dev/null
+++ b/docs/content/dns/zz_gen_hostingnl.md
@@ -0,0 +1,67 @@
+---
+title: "Hosting.nl"
+date: 2019-03-03T16:39:46+01:00
+draft: false
+slug: hostingnl
+dnsprovider:
+ since: "v4.30.0"
+ code: "hostingnl"
+ url: "https://hosting.nl"
+---
+
+
+
+
+
+
+Configuration for [Hosting.nl](https://hosting.nl).
+
+
+
+
+- Code: `hostingnl`
+- Since: v4.30.0
+
+
+Here is an example bash command using the Hosting.nl provider:
+
+```bash
+HOSTINGNL_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
+lego --email you@example.com --dns hostingnl -d '*.example.com' -d example.com run
+```
+
+
+
+
+## Credentials
+
+| Environment Variable Name | Description |
+|-----------------------|-------------|
+| `HOSTINGNL_API_KEY` | The API key |
+
+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 |
+|--------------------------------|-------------|
+| `HOSTINGNL_HTTP_TIMEOUT` | API request timeout in seconds (Default: 10) |
+| `HOSTINGNL_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) |
+| `HOSTINGNL_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 120) |
+| `HOSTINGNL_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://api.hosting.nl/api/documentation)
+
+
+
+
diff --git a/docs/data/zz_cli_help.toml b/docs/data/zz_cli_help.toml
index 506c7e47d..7962f0d73 100644
--- a/docs/data/zz_cli_help.toml
+++ b/docs/data/zz_cli_help.toml
@@ -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, aliesa, 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, edgecenter, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, gigahostno, glesys, godaddy, googledomains, gravity, 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, neodigit, 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, syse, technitium, tencentcloud, timewebcloud, transip, ultradns, uniteddomains, variomedia, vegadns, vercel, versio, vinyldns, virtualname, vkcloud, volcengine, vscale, vultr, webnames, webnamesca, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
+ acme-dns, active24, alidns, aliesa, 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, edgecenter, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, gigahostno, glesys, godaddy, googledomains, gravity, hetzner, hostingde, hostinger, hostingnl, 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, neodigit, 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, syse, technitium, tencentcloud, timewebcloud, transip, ultradns, uniteddomains, variomedia, vegadns, vercel, versio, vinyldns, virtualname, vkcloud, volcengine, vscale, vultr, webnames, webnamesca, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
More information: https://go-acme.github.io/lego/dns
"""
diff --git a/providers/dns/hostingnl/hostingnl.go b/providers/dns/hostingnl/hostingnl.go
new file mode 100644
index 000000000..a49941817
--- /dev/null
+++ b/providers/dns/hostingnl/hostingnl.go
@@ -0,0 +1,168 @@
+// Package hostingnl implements a DNS provider for solving the DNS-01 challenge using hosting.nl.
+package hostingnl
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "net/http"
+ "strconv"
+ "sync"
+ "time"
+
+ "github.com/go-acme/lego/v4/challenge"
+ "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/hostingnl/internal"
+ "github.com/go-acme/lego/v4/providers/dns/internal/clientdebug"
+)
+
+// Environment variables names.
+const (
+ envNamespace = "HOSTINGNL_"
+
+ EnvAPIKey = envNamespace + "API_KEY"
+
+ EnvTTL = envNamespace + "TTL"
+ EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
+ EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
+ EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
+)
+
+var _ challenge.ProviderTimeout = (*DNSProvider)(nil)
+
+// Config is used to configure the creation of the DNSProvider.
+type Config struct {
+ APIKey string
+ HTTPClient *http.Client
+ PropagationTimeout time.Duration
+ PollingInterval time.Duration
+ TTL int
+}
+
+// NewDefaultConfig returns a default configuration for the DNSProvider.
+func NewDefaultConfig() *Config {
+ return &Config{
+ TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
+ PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
+ PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
+ HTTPClient: &http.Client{
+ Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 10*time.Second),
+ },
+ }
+}
+
+// DNSProvider implements the challenge.Provider interface.
+type DNSProvider struct {
+ config *Config
+ client *internal.Client
+
+ recordIDs map[string]string
+ recordIDsMu sync.Mutex
+}
+
+// NewDNSProvider returns a DNSProvider instance configured for hosting.nl.
+// Credentials must be passed in the environment variables:
+// HOSTINGNL_APIKEY.
+func NewDNSProvider() (*DNSProvider, error) {
+ values, err := env.Get(EnvAPIKey)
+ if err != nil {
+ return nil, fmt.Errorf("hostingnl: %w", err)
+ }
+
+ config := NewDefaultConfig()
+ config.APIKey = values[EnvAPIKey]
+
+ return NewDNSProviderConfig(config)
+}
+
+// NewDNSProviderConfig return a DNSProvider instance configured for hosting.nl.
+func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
+ if config == nil {
+ return nil, errors.New("hostingnl: the configuration of the DNS provider is nil")
+ }
+
+ if config.APIKey == "" {
+ return nil, errors.New("hostingnl: APIKey is missing")
+ }
+
+ client := internal.NewClient(config.APIKey)
+
+ if config.HTTPClient != nil {
+ client.HTTPClient = config.HTTPClient
+ }
+
+ client.HTTPClient = clientdebug.Wrap(client.HTTPClient)
+
+ return &DNSProvider{
+ config: config,
+ client: client,
+ recordIDs: make(map[string]string),
+ }, 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("hostingnl: could not find zone for domain %q: %w", domain, err)
+ }
+
+ record := internal.Record{
+ Name: dns01.UnFqdn(info.EffectiveFQDN),
+ Type: "TXT",
+ Content: strconv.Quote(info.Value),
+ TTL: d.config.TTL,
+ Priority: 0,
+ }
+
+ newRecord, err := d.client.AddRecord(context.Background(), dns01.UnFqdn(authZone), record)
+ if err != nil {
+ return fmt.Errorf("hostingnl: failed to create TXT record, fqdn=%s: %w", info.EffectiveFQDN, err)
+ }
+
+ d.recordIDsMu.Lock()
+ d.recordIDs[token] = newRecord.ID
+ d.recordIDsMu.Unlock()
+
+ return nil
+}
+
+// CleanUp removes the TXT records 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("hostingnl: could not find zone for domain %q: %w", domain, err)
+ }
+
+ // gets the record's unique ID
+ d.recordIDsMu.Lock()
+ recordID, ok := d.recordIDs[token]
+ d.recordIDsMu.Unlock()
+
+ if !ok {
+ return fmt.Errorf("hostingnl: unknown record ID for '%s' '%s'", info.EffectiveFQDN, token)
+ }
+
+ err = d.client.DeleteRecord(context.Background(), dns01.UnFqdn(authZone), recordID)
+ if err != nil {
+ return fmt.Errorf("hostingnl: failed to delete TXT record, id=%s: %w", recordID, err)
+ }
+
+ // deletes record ID from map
+ d.recordIDsMu.Lock()
+ delete(d.recordIDs, token)
+ d.recordIDsMu.Unlock()
+
+ 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
+}
diff --git a/providers/dns/hostingnl/hostingnl.toml b/providers/dns/hostingnl/hostingnl.toml
new file mode 100644
index 000000000..a26c07ab2
--- /dev/null
+++ b/providers/dns/hostingnl/hostingnl.toml
@@ -0,0 +1,22 @@
+Name = "Hosting.nl"
+Description = ''''''
+URL = "https://hosting.nl"
+Code = "hostingnl"
+Since = "v4.30.0"
+
+Example = '''
+HOSTINGNL_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
+lego --email you@example.com --dns hostingnl -d '*.example.com' -d example.com run
+'''
+
+[Configuration]
+ [Configuration.Credentials]
+ HOSTINGNL_API_KEY = "The API key"
+ [Configuration.Additional]
+ HOSTINGNL_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
+ HOSTINGNL_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 120)"
+ HOSTINGNL_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
+ HOSTINGNL_HTTP_TIMEOUT = "API request timeout in seconds (Default: 10)"
+
+[Links]
+ API = "https://api.hosting.nl/api/documentation"
diff --git a/providers/dns/hostingnl/hostingnl_test.go b/providers/dns/hostingnl/hostingnl_test.go
new file mode 100644
index 000000000..cef754c7c
--- /dev/null
+++ b/providers/dns/hostingnl/hostingnl_test.go
@@ -0,0 +1,167 @@
+package hostingnl
+
+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(EnvAPIKey).WithDomain(envDomain)
+
+func TestNewDNSProvider(t *testing.T) {
+ testCases := []struct {
+ desc string
+ envVars map[string]string
+ expected string
+ }{
+ {
+ desc: "success",
+ envVars: map[string]string{
+ EnvAPIKey: "key",
+ },
+ },
+ {
+ desc: "missing API key",
+ envVars: map[string]string{},
+ expected: "hostingnl: some credentials information are missing: HOSTINGNL_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
+ apiKey string
+ expected string
+ }{
+ {
+ desc: "success",
+ apiKey: "key",
+ },
+ {
+ desc: "missing API key",
+ expected: "hostingnl: APIKey is missing",
+ },
+ }
+
+ for _, test := range testCases {
+ t.Run(test.desc, func(t *testing.T) {
+ config := NewDefaultConfig()
+ 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.APIKey = "secret"
+ config.HTTPClient = server.Client()
+
+ provider, err := NewDNSProviderConfig(config)
+ if err != nil {
+ return nil, err
+ }
+
+ provider.client.BaseURL, _ = url.Parse(server.URL)
+
+ return provider, nil
+ },
+ servermock.CheckHeader().
+ WithJSONHeaders().
+ With("API-TOKEN", "secret"),
+ )
+}
+
+func TestDNSProvider_Present(t *testing.T) {
+ provider := mockBuilder().
+ Route("POST /domains/example.com/dns",
+ servermock.ResponseFromInternal("add_record.json"),
+ servermock.CheckQueryParameter().Strict(),
+ servermock.CheckRequestJSONBodyFromInternal("add_record-request.json")).
+ 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/dns",
+ servermock.ResponseFromInternal("delete_record.json"),
+ servermock.CheckQueryParameter().Strict(),
+ servermock.CheckRequestJSONBodyFromInternal("delete_record-request.json")).
+ Build(t)
+
+ provider.recordIDs["abc"] = "12345"
+
+ err := provider.CleanUp("example.com", "abc", "123d==")
+ require.NoError(t, err)
+}
diff --git a/providers/dns/hostingnl/internal/client.go b/providers/dns/hostingnl/internal/client.go
new file mode 100644
index 000000000..f2d7b5346
--- /dev/null
+++ b/providers/dns/hostingnl/internal/client.go
@@ -0,0 +1,144 @@
+package internal
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "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://api.hosting.nl"
+
+type Client struct {
+ apiKey string
+
+ BaseURL *url.URL
+ HTTPClient *http.Client
+}
+
+func NewClient(apiKey string) *Client {
+ baseURL, _ := url.Parse(defaultBaseURL)
+
+ return &Client{
+ apiKey: apiKey,
+ BaseURL: baseURL,
+ HTTPClient: &http.Client{Timeout: 5 * time.Second},
+ }
+}
+
+func (c Client) AddRecord(ctx context.Context, domain string, record Record) (*Record, error) {
+ endpoint := c.BaseURL.JoinPath("domains", domain, "dns")
+
+ req, err := newJSONRequest(ctx, http.MethodPost, endpoint, []Record{record})
+ if err != nil {
+ return nil, err
+ }
+
+ var result APIResponse[Record]
+
+ err = c.do(req, &result)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(result.Data) != 1 {
+ return nil, fmt.Errorf("unexpected response data: %v", result.Data)
+ }
+
+ return &result.Data[0], nil
+}
+
+func (c Client) DeleteRecord(ctx context.Context, domain, recordID string) error {
+ endpoint := c.BaseURL.JoinPath("domains", domain, "dns")
+
+ req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, []Record{{ID: recordID}})
+ if err != nil {
+ return err
+ }
+
+ var result APIResponse[Record]
+
+ err = c.do(req, &result)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (c Client) do(req *http.Request, result any) error {
+ useragent.SetHeader(req.Header)
+
+ req.Header.Set("API-TOKEN", c.apiKey)
+
+ resp, err := c.HTTPClient.Do(req)
+ if err != nil {
+ return errutils.NewHTTPDoError(req, err)
+ }
+
+ defer func() { _ = resp.Body.Close() }()
+
+ if resp.StatusCode != http.StatusOK {
+ 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 parseError(req *http.Request, resp *http.Response) error {
+ raw, _ := io.ReadAll(resp.Body)
+
+ var apiErr APIError
+
+ err := json.Unmarshal(raw, &apiErr)
+ if err != nil {
+ return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
+ }
+
+ return fmt.Errorf("[status code: %d] %w", resp.StatusCode, apiErr)
+}
+
+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
+}
diff --git a/providers/dns/hostingnl/internal/client_test.go b/providers/dns/hostingnl/internal/client_test.go
new file mode 100644
index 000000000..efdb98980
--- /dev/null
+++ b/providers/dns/hostingnl/internal/client_test.go
@@ -0,0 +1,92 @@
+package internal
+
+import (
+ "context"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "strconv"
+ "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(
+ func(server *httptest.Server) (*Client, error) {
+ client := NewClient("secret")
+ client.HTTPClient = server.Client()
+ client.BaseURL, _ = url.Parse(server.URL)
+
+ return client, nil
+ },
+ servermock.CheckHeader().
+ WithJSONHeaders().
+ With("API-TOKEN", "secret"),
+ )
+}
+
+func TestClient_AddRecord(t *testing.T) {
+ client := mockBuilder().
+ Route("POST /domains/example.com/dns",
+ servermock.ResponseFromFixture("add_record.json"),
+ servermock.CheckQueryParameter().Strict(),
+ servermock.CheckRequestJSONBodyFromFixture("add_record-request.json")).
+ Build(t)
+
+ record := Record{
+ Name: "_acme-challenge.example.com",
+ Type: "TXT",
+ Content: strconv.Quote("ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY"),
+ TTL: 120,
+ }
+
+ newRecord, err := client.AddRecord(context.Background(), "example.com", record)
+ require.NoError(t, err)
+
+ expected := &Record{
+ ID: "12345",
+ Name: "_acme-challenge.example.com",
+ Type: "TXT",
+ Content: strconv.Quote("ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY"),
+ TTL: 120,
+ }
+
+ assert.Equal(t, expected, newRecord)
+}
+
+func TestClient_DeleteRecord(t *testing.T) {
+ client := mockBuilder().
+ Route("DELETE /domains/example.com/dns",
+ servermock.ResponseFromFixture("delete_record.json"),
+ servermock.CheckQueryParameter().Strict(),
+ servermock.CheckRequestJSONBodyFromFixture("delete_record-request.json")).
+ Build(t)
+
+ err := client.DeleteRecord(context.Background(), "example.com", "12345")
+ require.NoError(t, err)
+}
+
+func TestClient_DeleteRecord_error(t *testing.T) {
+ client := mockBuilder().
+ Route("DELETE /domains/example.com/dns",
+ servermock.ResponseFromFixture("error.json").
+ WithStatusCode(http.StatusUnauthorized)).
+ Build(t)
+
+ err := client.DeleteRecord(context.Background(), "example.com", "12345")
+ require.EqualError(t, err, "[status code: 401] Something went wrong")
+}
+
+func TestClient_DeleteRecord_error_other(t *testing.T) {
+ client := mockBuilder().
+ Route("DELETE /domains/example.com/dns",
+ servermock.ResponseFromFixture("error_other.json").
+ WithStatusCode(http.StatusNotFound)).
+ Build(t)
+
+ err := client.DeleteRecord(context.Background(), "example.com", "12345")
+ require.EqualError(t, err, "[status code: 404] Resource not found")
+}
diff --git a/providers/dns/hostingnl/internal/fixtures/add_record-request.json b/providers/dns/hostingnl/internal/fixtures/add_record-request.json
new file mode 100644
index 000000000..6b68ec3c6
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/add_record-request.json
@@ -0,0 +1,8 @@
+[
+ {
+ "name": "_acme-challenge.example.com",
+ "type": "TXT",
+ "content": "\"ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY\"",
+ "ttl": 120
+ }
+]
diff --git a/providers/dns/hostingnl/internal/fixtures/add_record.json b/providers/dns/hostingnl/internal/fixtures/add_record.json
new file mode 100644
index 000000000..a822a4f8d
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/add_record.json
@@ -0,0 +1,13 @@
+{
+ "success": true,
+ "data": [
+ {
+ "id": "12345",
+ "type": "TXT",
+ "content": "\"ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY\"",
+ "name": "_acme-challenge.example.com",
+ "prio": 0,
+ "ttl": 120
+ }
+ ]
+}
diff --git a/providers/dns/hostingnl/internal/fixtures/delete_record-request.json b/providers/dns/hostingnl/internal/fixtures/delete_record-request.json
new file mode 100644
index 000000000..cfc26d2b9
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/delete_record-request.json
@@ -0,0 +1,5 @@
+[
+ {
+ "id": "12345"
+ }
+]
diff --git a/providers/dns/hostingnl/internal/fixtures/delete_record.json b/providers/dns/hostingnl/internal/fixtures/delete_record.json
new file mode 100644
index 000000000..c041c1f6d
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/delete_record.json
@@ -0,0 +1,8 @@
+{
+ "success": true,
+ "data": [
+ {
+ "id": "12345"
+ }
+ ]
+}
diff --git a/providers/dns/hostingnl/internal/fixtures/error.json b/providers/dns/hostingnl/internal/fixtures/error.json
new file mode 100644
index 000000000..170587246
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/error.json
@@ -0,0 +1,5 @@
+{
+ "errors": {
+ "message": "Something went wrong"
+ }
+}
diff --git a/providers/dns/hostingnl/internal/fixtures/error_other.json b/providers/dns/hostingnl/internal/fixtures/error_other.json
new file mode 100644
index 000000000..ca7ecab28
--- /dev/null
+++ b/providers/dns/hostingnl/internal/fixtures/error_other.json
@@ -0,0 +1,3 @@
+{
+ "error": "Resource not found"
+}
diff --git a/providers/dns/hostingnl/internal/types.go b/providers/dns/hostingnl/internal/types.go
new file mode 100644
index 000000000..f324665fe
--- /dev/null
+++ b/providers/dns/hostingnl/internal/types.go
@@ -0,0 +1,36 @@
+package internal
+
+type Record struct {
+ ID string `json:"id,omitempty"`
+ Name string `json:"name,omitempty"`
+ Type string `json:"type,omitempty"`
+ Content string `json:"content,omitempty"`
+ TTL int `json:"ttl,omitempty"`
+ Priority int `json:"prio,omitempty"`
+}
+
+type APIResponse[T any] struct {
+ Success bool `json:"success"`
+ Data []T `json:"data"`
+}
+
+type APIError struct {
+ ErrorMsg string `json:"error"`
+ Errors Error `json:"errors"`
+}
+
+func (e APIError) Error() string {
+ if e.ErrorMsg != "" {
+ return e.ErrorMsg
+ }
+
+ return e.Errors.Error()
+}
+
+type Error struct {
+ Message string `json:"message"`
+}
+
+func (e Error) Error() string {
+ return e.Message
+}
diff --git a/providers/dns/zz_gen_dns_providers.go b/providers/dns/zz_gen_dns_providers.go
index 2b1b14b24..3b7b8c5fc 100644
--- a/providers/dns/zz_gen_dns_providers.go
+++ b/providers/dns/zz_gen_dns_providers.go
@@ -77,6 +77,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/hetzner"
"github.com/go-acme/lego/v4/providers/dns/hostingde"
"github.com/go-acme/lego/v4/providers/dns/hostinger"
+ "github.com/go-acme/lego/v4/providers/dns/hostingnl"
"github.com/go-acme/lego/v4/providers/dns/hosttech"
"github.com/go-acme/lego/v4/providers/dns/httpnet"
"github.com/go-acme/lego/v4/providers/dns/httpreq"
@@ -327,6 +328,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return hostingde.NewDNSProvider()
case "hostinger":
return hostinger.NewDNSProvider()
+ case "hostingnl":
+ return hostingnl.NewDNSProvider()
case "hosttech":
return hosttech.NewDNSProvider()
case "httpnet":