Add DNS provider for Syse.no (#2742)

This commit is contained in:
Ludovic Fernandez 2025-12-08 20:25:08 +01:00 committed by GitHub
commit 02dd7152f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 789 additions and 9 deletions

View file

@ -237,42 +237,42 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
<td><a href="https://go-acme.github.io/lego/dns/sonic/">Sonic</a></td>
<td><a href="https://go-acme.github.io/lego/dns/spaceship/">Spaceship</a></td>
<td><a href="https://go-acme.github.io/lego/dns/stackpath/">Stackpath</a></td>
<td><a href="https://go-acme.github.io/lego/dns/technitium/">Technitium</a></td>
<td><a href="https://go-acme.github.io/lego/dns/syse/">Syse</a></td>
</tr><tr>
<td><a href="https://go-acme.github.io/lego/dns/technitium/">Technitium</a></td>
<td><a href="https://go-acme.github.io/lego/dns/tencentcloud/">Tencent Cloud DNS</a></td>
<td><a href="https://go-acme.github.io/lego/dns/edgeone/">Tencent EdgeOne</a></td>
<td><a href="https://go-acme.github.io/lego/dns/timewebcloud/">Timeweb Cloud</a></td>
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
</tr><tr>
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
<td><a href="https://go-acme.github.io/lego/dns/safedns/">UKFast SafeDNS</a></td>
<td><a href="https://go-acme.github.io/lego/dns/ultradns/">Ultradns</a></td>
<td><a href="https://go-acme.github.io/lego/dns/uniteddomains/">United-Domains</a></td>
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
</tr><tr>
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vegadns/">VegaDNS</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vercel/">Vercel</a></td>
<td><a href="https://go-acme.github.io/lego/dns/versio/">Versio.[nl|eu|uk]</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
</tr><tr>
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vkcloud/">VK Cloud</a></td>
<td><a href="https://go-acme.github.io/lego/dns/volcengine/">Volcano Engine/火山引擎</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vscale/">Vscale</a></td>
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
</tr><tr>
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
<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/webnames/">webnames.ru</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>
</tr><tr>
<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>
<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>
</tr><tr>
<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>
<td><a href="https://go-acme.github.io/lego/dns/zonomi/">Zonomi</a></td>
<td></td>
</tr></table>
<!-- END DNS PROVIDERS LIST -->

View file

@ -157,6 +157,7 @@ func allDNSCodes() string {
"sonic",
"spaceship",
"stackpath",
"syse",
"technitium",
"tencentcloud",
"timewebcloud",
@ -3312,6 +3313,26 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/stackpath`)
case "syse":
// generated from: providers/dns/syse/syse.toml
ew.writeln(`Configuration for Syse.`)
ew.writeln(`Code: 'syse'`)
ew.writeln(`Since: 'v4.30.0'`)
ew.writeln()
ew.writeln(`Credentials:`)
ew.writeln(` - "SYSE_CREDENTIALS": Comma-separated list of 'zone:password' credential pairs`)
ew.writeln()
ew.writeln(`Additional Configuration:`)
ew.writeln(` - "SYSE_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`)
ew.writeln(` - "SYSE_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 10)`)
ew.writeln(` - "SYSE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 1200)`)
ew.writeln(` - "SYSE_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/syse`)
case "technitium":
// generated from: providers/dns/technitium/technitium.toml
ew.writeln(`Configuration for Technitium.`)

70
docs/content/dns/zz_gen_syse.md generated Normal file
View file

@ -0,0 +1,70 @@
---
title: "Syse"
date: 2019-03-03T16:39:46+01:00
draft: false
slug: syse
dnsprovider:
since: "v4.30.0"
code: "syse"
url: "https://www.syse.no/"
---
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/syse/syse.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
Configuration for [Syse](https://www.syse.no/).
<!--more-->
- Code: `syse`
- Since: v4.30.0
Here is an example bash command using the Syse provider:
```bash
SYSE_CREDENTIALS=example.com:password \
lego --email you@example.com --dns syse -d '*.example.com' -d example.com run
SYSE_CREDENTIALS=example.org:password1,example.com:password2 \
lego --email you@example.com --dns syse -d '*.example.org' -d example.org -d '*.example.com' -d example.com
```
## Credentials
| Environment Variable Name | Description |
|-----------------------|-------------|
| `SYSE_CREDENTIALS` | Comma-separated list of `zone:password` credential pairs |
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 |
|--------------------------------|-------------|
| `SYSE_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) |
| `SYSE_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 10) |
| `SYSE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 1200) |
| `SYSE_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.syse.no/api/dns)
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/syse/syse.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

View file

@ -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, 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, uniteddomains, variomedia, vegadns, vercel, versio, vinyldns, 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, 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, syse, technitium, tencentcloud, timewebcloud, transip, ultradns, uniteddomains, 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
"""

View file

@ -0,0 +1,131 @@
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.syse.no/api"
// Client the Syse API client.
type Client struct {
credentials map[string]string
BaseURL *url.URL
HTTPClient *http.Client
}
// NewClient creates a new Client.
func NewClient(credentials map[string]string) (*Client, error) {
if len(credentials) == 0 {
return nil, errors.New("credentials missing")
}
baseURL, _ := url.Parse(defaultBaseURL)
return &Client{
credentials: credentials,
BaseURL: baseURL,
HTTPClient: &http.Client{Timeout: 10 * time.Second},
}, nil
}
func (c *Client) CreateRecord(ctx context.Context, zone string, record Record) (*Record, error) {
endpoint := c.BaseURL.JoinPath("dns", zone)
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, record)
if err != nil {
return nil, err
}
req.SetBasicAuth(zone, c.credentials[zone])
result := new(Record)
err = c.do(req, result)
if err != nil {
return nil, err
}
return result, nil
}
func (c *Client) DeleteRecord(ctx context.Context, zone, recordID string) error {
endpoint := c.BaseURL.JoinPath("dns", zone, recordID)
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {
return err
}
req.SetBasicAuth(zone, c.credentials[zone])
return c.do(req, nil)
}
func (c *Client) do(req *http.Request, result any) error {
useragent.SetHeader(req.Header)
resp, err := c.HTTPClient.Do(req)
if err != nil {
return errutils.NewHTTPDoError(req, err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode/100 != 2 {
raw, _ := io.ReadAll(resp.Body)
return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
}
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
}

View file

@ -0,0 +1,102 @@
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(map[string]string{
"example.com": "secret",
})
if err != nil {
return nil, err
}
client.BaseURL, _ = url.Parse(server.URL)
client.HTTPClient = server.Client()
return client, nil
},
servermock.CheckHeader().
WithJSONHeaders(),
)
}
func TestClient_CreateRecord(t *testing.T) {
client := mockBuilder().
Route("POST /dns/example.com",
servermock.ResponseFromFixture("create_record.json"),
servermock.CheckRequestJSONBodyFromFixture("create_record-request.json")).
Build(t)
record := Record{
Type: "TXT",
Prefix: "_acme-challenge",
Content: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
Active: true,
TTL: 120,
}
result, err := client.CreateRecord(t.Context(), "example.com", record)
require.NoError(t, err)
expected := &Record{
ID: "1234",
Type: "TXT",
Prefix: "_acme-challenge",
Content: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
Active: true,
TTL: 120,
}
assert.Equal(t, expected, result)
}
func TestClient_CreateRecord_error(t *testing.T) {
client := mockBuilder().
Route("POST /dns/example.com",
servermock.RawStringResponse(http.StatusText(http.StatusUnauthorized)).
WithStatusCode(http.StatusUnauthorized)).
Build(t)
record := Record{
Type: "TXT",
Prefix: "_acme-challenge",
Content: "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
Active: true,
TTL: 120,
}
_, err := client.CreateRecord(t.Context(), "example.com", record)
require.EqualError(t, err, "unexpected status code: [status code: 401] body: Unauthorized")
}
func TestClient_DeleteRecord(t *testing.T) {
client := mockBuilder().
Route("DELETE /dns/example.com/1234",
servermock.Noop()).
Build(t)
err := client.DeleteRecord(t.Context(), "example.com", "1234")
require.NoError(t, err)
}
func TestClient_DeleteRecord_error(t *testing.T) {
client := mockBuilder().
Route("DELETE /dns/example.com/1234",
servermock.RawStringResponse(http.StatusText(http.StatusUnauthorized)).
WithStatusCode(http.StatusUnauthorized)).
Build(t)
err := client.DeleteRecord(t.Context(), "example.com", "1234")
require.EqualError(t, err, "unexpected status code: [status code: 401] body: Unauthorized")
}

View file

@ -0,0 +1,7 @@
{
"content": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
"active": true,
"ttl": 120,
"prefix": "_acme-challenge",
"type": "TXT"
}

View file

@ -0,0 +1,8 @@
{
"id": "1234",
"content": "ADw2sEd82DUgXcQ9hNBZThJs7zVJkR5v9JeSbAb9mZY",
"active": true,
"ttl": 120,
"prefix": "_acme-challenge",
"type": "TXT"
}

View file

@ -0,0 +1,11 @@
package internal
type Record struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Prefix string `json:"prefix,omitempty"`
Content string `json:"content,omitempty"`
Priority int `json:"prio,omitempty"`
TTL int `json:"ttl,omitempty"`
Active bool `json:"active,omitempty"`
}

182
providers/dns/syse/syse.go Normal file
View file

@ -0,0 +1,182 @@
// Package syse implements a DNS provider for solving the DNS-01 challenge using Syse.
package syse
import (
"context"
"errors"
"fmt"
"net/http"
"sync"
"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/syse/internal"
)
// Environment variables names.
const (
envNamespace = "SYSE_"
EnvCredentials = envNamespace + "CREDENTIALS"
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 {
Credentials map[string]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, 1200*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
recordIDs map[string]string
recordIDsMu sync.Mutex
}
// NewDNSProvider returns a DNSProvider instance configured for Syse.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvCredentials)
if err != nil {
return nil, fmt.Errorf("syse: %w", err)
}
config := NewDefaultConfig()
credentials, err := env.ParsePairs(values[EnvCredentials])
if err != nil {
return nil, fmt.Errorf("syse: credentials: %w", err)
}
config.Credentials = credentials
return NewDNSProviderConfig(config)
}
// NewDNSProviderConfig return a DNSProvider instance configured for Syse.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("syse: the configuration of the DNS provider is nil")
}
if len(config.Credentials) == 0 {
return nil, errors.New("syse: missing credentials")
}
for domain, password := range config.Credentials {
if domain == "" {
return nil, fmt.Errorf(`syse: missing domain: "%s:%s"`, domain, password)
}
if password == "" {
return nil, fmt.Errorf(`syse: missing password: "%s:%s"`, domain, password)
}
}
client, err := internal.NewClient(config.Credentials)
if err != nil {
return nil, fmt.Errorf("syse: %w", err)
}
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("syse: could not find zone for domain %q: %w", domain, err)
}
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
if err != nil {
return fmt.Errorf("syse: %w", err)
}
record := internal.Record{
Type: "TXT",
Prefix: subDomain,
Content: info.Value,
TTL: d.config.TTL,
Active: true,
}
newRecord, err := d.client.CreateRecord(context.Background(), dns01.UnFqdn(authZone), record)
if err != nil {
return fmt.Errorf("syse: create record: %w", err)
}
d.recordIDsMu.Lock()
d.recordIDs[token] = newRecord.ID
d.recordIDsMu.Unlock()
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("syse: could not find zone for domain %q: %w", domain, err)
}
// gets the record's unique ID from when we created it
d.recordIDsMu.Lock()
recordID, ok := d.recordIDs[token]
d.recordIDsMu.Unlock()
if !ok {
return fmt.Errorf("syse: 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("syse: delete 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
}

View file

@ -0,0 +1,25 @@
Name = "Syse"
Description = ''''''
URL = "https://www.syse.no/"
Code = "syse"
Since = "v4.30.0"
Example = '''
SYSE_CREDENTIALS=example.com:password \
lego --email you@example.com --dns syse -d '*.example.com' -d example.com run
SYSE_CREDENTIALS=example.org:password1,example.com:password2 \
lego --email you@example.com --dns syse -d '*.example.org' -d example.org -d '*.example.com' -d example.com
'''
[Configuration]
[Configuration.Credentials]
SYSE_CREDENTIALS = "Comma-separated list of `zone:password` credential pairs"
[Configuration.Additional]
SYSE_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 10)"
SYSE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 1200)"
SYSE_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
SYSE_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
[Links]
API = "https://www.syse.no/api/dns"

View file

@ -0,0 +1,220 @@
package syse
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(EnvCredentials).WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "success",
envVars: map[string]string{
EnvCredentials: "example.org:123",
},
},
{
desc: "success multiple domains",
envVars: map[string]string{
EnvCredentials: "example.org:123,example.com:456,example.net:789",
},
},
{
desc: "invalid credentials",
envVars: map[string]string{
EnvCredentials: ",",
},
expected: `syse: credentials: incorrect pair: `,
},
{
desc: "missing password",
envVars: map[string]string{
EnvCredentials: "example.org:",
},
expected: `syse: missing password: "example.org:"`,
},
{
desc: "missing domain",
envVars: map[string]string{
EnvCredentials: ":123",
},
expected: `syse: missing domain: ":123"`,
},
{
desc: "invalid credentials, partial",
envVars: map[string]string{
EnvCredentials: "example.org:123,example.net",
},
expected: "syse: credentials: incorrect pair: example.net",
},
{
desc: "missing credentials",
envVars: map[string]string{
EnvCredentials: "",
},
expected: "syse: some credentials information are missing: SYSE_CREDENTIALS",
},
}
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
creds map[string]string
expected string
}{
{
desc: "success",
creds: map[string]string{"example.org": "123"},
},
{
desc: "success multiple domains",
creds: map[string]string{
"example.org": "123",
"example.com": "456",
"example.net": "789",
},
},
{
desc: "missing credentials",
expected: "syse: missing credentials",
},
{
desc: "missing domain",
creds: map[string]string{"": "123"},
expected: `syse: missing domain: ":123"`,
},
{
desc: "missing password",
creds: map[string]string{"example.org": ""},
expected: `syse: missing password: "example.org:"`,
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.Credentials = test.creds
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.Credentials = map[string]string{
"example.org": "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(),
)
}
func TestDNSProvider_Present(t *testing.T) {
provider := mockBuilder().
Route("/", servermock.DumpRequest()).
Route("POST /dns/example.com",
servermock.ResponseFromInternal("create_record.json"),
servermock.CheckRequestJSONBodyFromInternal("create_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 /dns/example.com/1234",
servermock.Noop()).
Build(t)
provider.recordIDs["abc"] = "1234"
err := provider.CleanUp("example.com", "abc", "123d==")
require.NoError(t, err)
}

View file

@ -151,6 +151,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/sonic"
"github.com/go-acme/lego/v4/providers/dns/spaceship"
"github.com/go-acme/lego/v4/providers/dns/stackpath"
"github.com/go-acme/lego/v4/providers/dns/syse"
"github.com/go-acme/lego/v4/providers/dns/technitium"
"github.com/go-acme/lego/v4/providers/dns/tencentcloud"
"github.com/go-acme/lego/v4/providers/dns/timewebcloud"
@ -472,6 +473,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return spaceship.NewDNSProvider()
case "stackpath":
return stackpath.NewDNSProvider()
case "syse":
return syse.NewDNSProvider()
case "technitium":
return technitium.NewDNSProvider()
case "tencentcloud":