Skip to content

Commit 02dd715

Browse files
authored
Add DNS provider for Syse.no (#2742)
1 parent 36552da commit 02dd715

File tree

13 files changed

+789
-9
lines changed

13 files changed

+789
-9
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,42 +237,42 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
237237
<td><a href="https://go-acme.github.io/lego/dns/sonic/">Sonic</a></td>
238238
<td><a href="https://go-acme.github.io/lego/dns/spaceship/">Spaceship</a></td>
239239
<td><a href="https://go-acme.github.io/lego/dns/stackpath/">Stackpath</a></td>
240-
<td><a href="https://go-acme.github.io/lego/dns/technitium/">Technitium</a></td>
240+
<td><a href="https://go-acme.github.io/lego/dns/syse/">Syse</a></td>
241241
</tr><tr>
242+
<td><a href="https://go-acme.github.io/lego/dns/technitium/">Technitium</a></td>
242243
<td><a href="https://go-acme.github.io/lego/dns/tencentcloud/">Tencent Cloud DNS</a></td>
243244
<td><a href="https://go-acme.github.io/lego/dns/edgeone/">Tencent EdgeOne</a></td>
244245
<td><a href="https://go-acme.github.io/lego/dns/timewebcloud/">Timeweb Cloud</a></td>
245-
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
246246
</tr><tr>
247+
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
247248
<td><a href="https://go-acme.github.io/lego/dns/safedns/">UKFast SafeDNS</a></td>
248249
<td><a href="https://go-acme.github.io/lego/dns/ultradns/">Ultradns</a></td>
249250
<td><a href="https://go-acme.github.io/lego/dns/uniteddomains/">United-Domains</a></td>
250-
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
251251
</tr><tr>
252+
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
252253
<td><a href="https://go-acme.github.io/lego/dns/vegadns/">VegaDNS</a></td>
253254
<td><a href="https://go-acme.github.io/lego/dns/vercel/">Vercel</a></td>
254255
<td><a href="https://go-acme.github.io/lego/dns/versio/">Versio.[nl|eu|uk]</a></td>
255-
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
256256
</tr><tr>
257+
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
257258
<td><a href="https://go-acme.github.io/lego/dns/vkcloud/">VK Cloud</a></td>
258259
<td><a href="https://go-acme.github.io/lego/dns/volcengine/">Volcano Engine/火山引擎</a></td>
259260
<td><a href="https://go-acme.github.io/lego/dns/vscale/">Vscale</a></td>
260-
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
261261
</tr><tr>
262+
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
262263
<td><a href="https://go-acme.github.io/lego/dns/webnamesca/">webnames.ca</a></td>
263264
<td><a href="https://go-acme.github.io/lego/dns/webnames/">webnames.ru</a></td>
264265
<td><a href="https://go-acme.github.io/lego/dns/websupport/">Websupport</a></td>
265-
<td><a href="https://go-acme.github.io/lego/dns/wedos/">WEDOS</a></td>
266266
</tr><tr>
267+
<td><a href="https://go-acme.github.io/lego/dns/wedos/">WEDOS</a></td>
267268
<td><a href="https://go-acme.github.io/lego/dns/westcn/">West.cn/西部数码</a></td>
268269
<td><a href="https://go-acme.github.io/lego/dns/yandex360/">Yandex 360</a></td>
269270
<td><a href="https://go-acme.github.io/lego/dns/yandexcloud/">Yandex Cloud</a></td>
270-
<td><a href="https://go-acme.github.io/lego/dns/yandex/">Yandex PDD</a></td>
271271
</tr><tr>
272+
<td><a href="https://go-acme.github.io/lego/dns/yandex/">Yandex PDD</a></td>
272273
<td><a href="https://go-acme.github.io/lego/dns/zoneee/">Zone.ee</a></td>
273274
<td><a href="https://go-acme.github.io/lego/dns/zoneedit/">ZoneEdit</a></td>
274275
<td><a href="https://go-acme.github.io/lego/dns/zonomi/">Zonomi</a></td>
275-
<td></td>
276276
</tr></table>
277277

278278
<!-- END DNS PROVIDERS LIST -->

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/dns/zz_gen_syse.md

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data/zz_cli_help.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package internal
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"errors"
8+
"fmt"
9+
"io"
10+
"net/http"
11+
"net/url"
12+
"time"
13+
14+
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
15+
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
16+
)
17+
18+
const defaultBaseURL = "https://www.syse.no/api"
19+
20+
// Client the Syse API client.
21+
type Client struct {
22+
credentials map[string]string
23+
24+
BaseURL *url.URL
25+
HTTPClient *http.Client
26+
}
27+
28+
// NewClient creates a new Client.
29+
func NewClient(credentials map[string]string) (*Client, error) {
30+
if len(credentials) == 0 {
31+
return nil, errors.New("credentials missing")
32+
}
33+
34+
baseURL, _ := url.Parse(defaultBaseURL)
35+
36+
return &Client{
37+
credentials: credentials,
38+
BaseURL: baseURL,
39+
HTTPClient: &http.Client{Timeout: 10 * time.Second},
40+
}, nil
41+
}
42+
43+
func (c *Client) CreateRecord(ctx context.Context, zone string, record Record) (*Record, error) {
44+
endpoint := c.BaseURL.JoinPath("dns", zone)
45+
46+
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, record)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
req.SetBasicAuth(zone, c.credentials[zone])
52+
53+
result := new(Record)
54+
55+
err = c.do(req, result)
56+
if err != nil {
57+
return nil, err
58+
}
59+
60+
return result, nil
61+
}
62+
63+
func (c *Client) DeleteRecord(ctx context.Context, zone, recordID string) error {
64+
endpoint := c.BaseURL.JoinPath("dns", zone, recordID)
65+
66+
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
67+
if err != nil {
68+
return err
69+
}
70+
71+
req.SetBasicAuth(zone, c.credentials[zone])
72+
73+
return c.do(req, nil)
74+
}
75+
76+
func (c *Client) do(req *http.Request, result any) error {
77+
useragent.SetHeader(req.Header)
78+
79+
resp, err := c.HTTPClient.Do(req)
80+
if err != nil {
81+
return errutils.NewHTTPDoError(req, err)
82+
}
83+
84+
defer func() { _ = resp.Body.Close() }()
85+
86+
if resp.StatusCode/100 != 2 {
87+
raw, _ := io.ReadAll(resp.Body)
88+
89+
return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
90+
}
91+
92+
if result == nil {
93+
return nil
94+
}
95+
96+
raw, err := io.ReadAll(resp.Body)
97+
if err != nil {
98+
return errutils.NewReadResponseError(req, resp.StatusCode, err)
99+
}
100+
101+
err = json.Unmarshal(raw, result)
102+
if err != nil {
103+
return errutils.NewUnmarshalError(req, resp.StatusCode, raw, err)
104+
}
105+
106+
return nil
107+
}
108+
109+
func newJSONRequest(ctx context.Context, method string, endpoint *url.URL, payload any) (*http.Request, error) {
110+
buf := new(bytes.Buffer)
111+
112+
if payload != nil {
113+
err := json.NewEncoder(buf).Encode(payload)
114+
if err != nil {
115+
return nil, fmt.Errorf("failed to create request JSON body: %w", err)
116+
}
117+
}
118+
119+
req, err := http.NewRequestWithContext(ctx, method, endpoint.String(), buf)
120+
if err != nil {
121+
return nil, fmt.Errorf("unable to create request: %w", err)
122+
}
123+
124+
req.Header.Set("Accept", "application/json")
125+
126+
if payload != nil {
127+
req.Header.Set("Content-Type", "application/json")
128+
}
129+
130+
return req, nil
131+
}

0 commit comments

Comments
 (0)