mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
Add DNS provider for Spaceship (#2406)
This commit is contained in:
parent
c0260c1d8a
commit
a25218dbb8
13 changed files with 776 additions and 8 deletions
14
README.md
14
README.md
|
|
@ -204,39 +204,39 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
|
|||
<td><a href="https://go-acme.github.io/lego/dns/simply/">Simply.com</a></td>
|
||||
</tr><tr>
|
||||
<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/tencentcloud/">Tencent Cloud DNS</a></td>
|
||||
</tr><tr>
|
||||
<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/timewebcloud/">Timeweb Cloud</a></td>
|
||||
<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>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ultradns/">Ultradns</a></td>
|
||||
<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>
|
||||
</tr><tr>
|
||||
<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>
|
||||
<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>
|
||||
</tr><tr>
|
||||
<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>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnames/">Webnames</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/zonomi/">Zonomi</a></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
|
|
@ -134,6 +134,7 @@ func allDNSCodes() string {
|
|||
"shellrent",
|
||||
"simply",
|
||||
"sonic",
|
||||
"spaceship",
|
||||
"stackpath",
|
||||
"technitium",
|
||||
"tencentcloud",
|
||||
|
|
@ -2770,6 +2771,27 @@ func displayDNSHelp(w io.Writer, name string) error {
|
|||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/sonic`)
|
||||
|
||||
case "spaceship":
|
||||
// generated from: providers/dns/spaceship/spaceship.toml
|
||||
ew.writeln(`Configuration for Spaceship.`)
|
||||
ew.writeln(`Code: 'spaceship'`)
|
||||
ew.writeln(`Since: 'v4.22.0'`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Credentials:`)
|
||||
ew.writeln(` - "SPACESHIP_API_KEY": API key`)
|
||||
ew.writeln(` - "SPACESHIP_API_SECRET": API secret`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Additional Configuration:`)
|
||||
ew.writeln(` - "SPACESHIP_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`)
|
||||
ew.writeln(` - "SPACESHIP_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`)
|
||||
ew.writeln(` - "SPACESHIP_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`)
|
||||
ew.writeln(` - "SPACESHIP_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/spaceship`)
|
||||
|
||||
case "stackpath":
|
||||
// generated from: providers/dns/stackpath/stackpath.toml
|
||||
ew.writeln(`Configuration for Stackpath.`)
|
||||
|
|
|
|||
69
docs/content/dns/zz_gen_spaceship.md
generated
Normal file
69
docs/content/dns/zz_gen_spaceship.md
generated
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
---
|
||||
title: "Spaceship"
|
||||
date: 2019-03-03T16:39:46+01:00
|
||||
draft: false
|
||||
slug: spaceship
|
||||
dnsprovider:
|
||||
since: "v4.22.0"
|
||||
code: "spaceship"
|
||||
url: "https://www.spaceship.com/"
|
||||
---
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/spaceship/spaceship.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
|
||||
|
||||
Configuration for [Spaceship](https://www.spaceship.com/).
|
||||
|
||||
|
||||
<!--more-->
|
||||
|
||||
- Code: `spaceship`
|
||||
- Since: v4.22.0
|
||||
|
||||
|
||||
Here is an example bash command using the Spaceship provider:
|
||||
|
||||
```bash
|
||||
SPACESHIP_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
SPACESHIP_API_SECRET="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
lego --email you@example.com --dns spaceship -d '*.example.com' -d example.com run
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## Credentials
|
||||
|
||||
| Environment Variable Name | Description |
|
||||
|-----------------------|-------------|
|
||||
| `SPACESHIP_API_KEY` | API key |
|
||||
| `SPACESHIP_API_SECRET` | API secret |
|
||||
|
||||
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 |
|
||||
|--------------------------------|-------------|
|
||||
| `SPACESHIP_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) |
|
||||
| `SPACESHIP_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) |
|
||||
| `SPACESHIP_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) |
|
||||
| `SPACESHIP_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://docs.spaceship.dev/#tag/DNS-records)
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/spaceship/spaceship.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
|
|
@ -148,7 +148,7 @@ To display the documentation for a specific DNS provider, run:
|
|||
$ lego dnshelp -c code
|
||||
|
||||
Supported DNS providers:
|
||||
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi
|
||||
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, 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, zoneee, zonomi
|
||||
|
||||
More information: https://go-acme.github.io/lego/dns
|
||||
"""
|
||||
|
|
|
|||
159
providers/dns/spaceship/internal/client.go
Normal file
159
providers/dns/spaceship/internal/client.go
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
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"
|
||||
)
|
||||
|
||||
const defaultBaseURL = "https://spaceship.dev/api/v1/"
|
||||
|
||||
// Client the Spaceship API client.
|
||||
type Client struct {
|
||||
apiKey string
|
||||
apiSecret string
|
||||
|
||||
baseURL *url.URL
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new Client.
|
||||
func NewClient(apiKey, apiSecret string) (*Client, error) {
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
return nil, errors.New("credentials missing")
|
||||
}
|
||||
|
||||
baseURL, _ := url.Parse(defaultBaseURL)
|
||||
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
apiSecret: apiSecret,
|
||||
baseURL: baseURL,
|
||||
HTTPClient: &http.Client{Timeout: 10 * time.Second},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) do(req *http.Request, result any) error {
|
||||
req.Header.Add("X-Api-Secret", c.apiSecret)
|
||||
req.Header.Add("X-Api-Key", c.apiKey)
|
||||
|
||||
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 (c *Client) AddRecord(ctx context.Context, domain string, record Record) error {
|
||||
endpoint := c.baseURL.JoinPath("dns", "records", domain)
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodPut, endpoint, Foo{Items: []Record{record}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.do(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteRecord(ctx context.Context, domain string, record Record) error {
|
||||
endpoint := c.baseURL.JoinPath("dns", "records", domain)
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, []Record{record})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.do(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) GetRecords(ctx context.Context, domain string) ([]Record, error) {
|
||||
endpoint := c.baseURL.JoinPath("dns", "records", domain)
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result GetRecordsResponse
|
||||
err = c.do(req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Items, 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
|
||||
}
|
||||
125
providers/dns/spaceship/internal/client_test.go
Normal file
125
providers/dns/spaceship/internal/client_test.go
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupTest(t *testing.T, pattern string, status int, filename string) *Client {
|
||||
t.Helper()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
server := httptest.NewServer(mux)
|
||||
t.Cleanup(server.Close)
|
||||
|
||||
mux.HandleFunc(pattern, func(rw http.ResponseWriter, req *http.Request) {
|
||||
if filename == "" {
|
||||
rw.WriteHeader(status)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Open(filepath.Join("fixtures", filename))
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { _ = file.Close() }()
|
||||
|
||||
rw.WriteHeader(status)
|
||||
_, err = io.Copy(rw, file)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
client, err := NewClient("key", "secret")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.HTTPClient = server.Client()
|
||||
client.baseURL, _ = url.Parse(server.URL)
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func TestClient_AddRecord(t *testing.T) {
|
||||
client := setupTest(t, "PUT /dns/records/example.com", http.StatusOK, "")
|
||||
|
||||
record := Record{
|
||||
Type: "TXT",
|
||||
Name: "@",
|
||||
TTL: 60,
|
||||
}
|
||||
|
||||
err := client.AddRecord(context.Background(), "example.com", record)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestClient_AddRecord_error(t *testing.T) {
|
||||
client := setupTest(t, "PUT /dns/records/example.com", http.StatusUnprocessableEntity, "error.json")
|
||||
|
||||
record := Record{
|
||||
Type: "TXT",
|
||||
Name: "@",
|
||||
TTL: 60,
|
||||
}
|
||||
|
||||
err := client.AddRecord(context.Background(), "example.com", record)
|
||||
require.EqualError(t, err, "^$, name: The domain name contains invalid characters")
|
||||
}
|
||||
|
||||
func TestClient_DeleteRecord(t *testing.T) {
|
||||
client := setupTest(t, "DELETE /dns/records/example.com", http.StatusOK, "")
|
||||
|
||||
record := Record{
|
||||
Type: "TXT",
|
||||
Name: "@",
|
||||
TTL: 60,
|
||||
}
|
||||
|
||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||
client := setupTest(t, "DELETE /dns/records/example.com", http.StatusUnprocessableEntity, "error.json")
|
||||
|
||||
record := Record{
|
||||
Type: "TXT",
|
||||
Name: "@",
|
||||
TTL: 60,
|
||||
}
|
||||
|
||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
||||
require.EqualError(t, err, "^$, name: The domain name contains invalid characters")
|
||||
}
|
||||
|
||||
func TestClient_GetRecords(t *testing.T) {
|
||||
client := setupTest(t, "GET /dns/records/example.com", http.StatusOK, "get-records.json")
|
||||
|
||||
records, err := client.GetRecords(context.Background(), "example.com")
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []Record{
|
||||
{Type: "A", Name: "@", TTL: 3600},
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, records)
|
||||
}
|
||||
|
||||
func TestClient_GetRecords_error(t *testing.T) {
|
||||
client := setupTest(t, "GET /dns/records/example.com", http.StatusUnprocessableEntity, "error.json")
|
||||
|
||||
_, err := client.GetRecords(context.Background(), "example.com")
|
||||
require.EqualError(t, err, "^$, name: The domain name contains invalid characters")
|
||||
}
|
||||
9
providers/dns/spaceship/internal/fixtures/error.json
Normal file
9
providers/dns/spaceship/internal/fixtures/error.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"detail": "^$",
|
||||
"data": [
|
||||
{
|
||||
"field": "name",
|
||||
"details": "The domain name contains invalid characters"
|
||||
}
|
||||
]
|
||||
}
|
||||
13
providers/dns/spaceship/internal/fixtures/get-records.json
Normal file
13
providers/dns/spaceship/internal/fixtures/get-records.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "A",
|
||||
"name": "@",
|
||||
"ttl": 3600,
|
||||
"group": {
|
||||
"type": "custom"
|
||||
}
|
||||
}
|
||||
],
|
||||
"total": 100
|
||||
}
|
||||
47
providers/dns/spaceship/internal/types.go
Normal file
47
providers/dns/spaceship/internal/types.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
Detail string `json:"detail"`
|
||||
Data []struct {
|
||||
Field string `json:"field"`
|
||||
Details string `json:"details"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func (a *APIError) Error() string {
|
||||
msg := []string{a.Detail}
|
||||
|
||||
for _, datum := range a.Data {
|
||||
msg = append(msg, fmt.Sprintf("%s: %s", datum.Field, datum.Details))
|
||||
}
|
||||
|
||||
return strings.Join(msg, ", ")
|
||||
}
|
||||
|
||||
type Foo struct {
|
||||
Force bool `json:"force,omitempty"`
|
||||
Items []Record `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Nameserver string `json:"nameserver,omitempty"`
|
||||
AliasName string `json:"aliasName,omitempty"`
|
||||
Pointer string `json:"pointer,omitempty"`
|
||||
CName string `json:"cname,omitempty"`
|
||||
Exchange string `json:"exchange,omitempty"`
|
||||
TTL int `json:"ttl,omitempty"`
|
||||
}
|
||||
|
||||
type GetRecordsResponse struct {
|
||||
Items []Record `json:"items"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
154
providers/dns/spaceship/spaceship.go
Normal file
154
providers/dns/spaceship/spaceship.go
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
// Package spaceship implements a DNS provider for solving the DNS-01 challenge using Spaceship.
|
||||
package spaceship
|
||||
|
||||
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/spaceship/internal"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "SPACESHIP_"
|
||||
|
||||
EnvAPIKey = envNamespace + "API_KEY"
|
||||
EnvAPISecret = envNamespace + "API_SECRET"
|
||||
|
||||
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 {
|
||||
APIKey string
|
||||
APISecret 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 Spaceship.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(EnvAPIKey, EnvAPISecret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("spaceship: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = values[EnvAPIKey]
|
||||
config.APISecret = values[EnvAPISecret]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
||||
// NewDNSProviderConfig return a DNSProvider instance configured for Spaceship.
|
||||
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("spaceship: the configuration of the DNS provider is nil")
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(config.APIKey, config.APISecret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("spaceship: %w", err)
|
||||
}
|
||||
|
||||
if config.HTTPClient != nil {
|
||||
client.HTTPClient = config.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("spaceship: could not find zone for domain %q: %w", domain, err)
|
||||
}
|
||||
|
||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("spaceship: %w", err)
|
||||
}
|
||||
|
||||
record := internal.Record{
|
||||
Type: "TXT",
|
||||
Name: subDomain,
|
||||
Value: info.Value,
|
||||
TTL: d.config.TTL,
|
||||
}
|
||||
|
||||
err = d.client.AddRecord(context.Background(), dns01.UnFqdn(authZone), record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("spaceship: %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("spaceship: could not find zone for domain %q: %w", domain, err)
|
||||
}
|
||||
|
||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("spaceship: %w", err)
|
||||
}
|
||||
|
||||
record := internal.Record{
|
||||
Type: "TXT",
|
||||
Name: subDomain,
|
||||
Value: info.Value,
|
||||
}
|
||||
|
||||
err = d.client.DeleteRecord(context.Background(), dns01.UnFqdn(authZone), record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("spaceship: %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/spaceship/spaceship.toml
Normal file
24
providers/dns/spaceship/spaceship.toml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Name = "Spaceship"
|
||||
Description = ''''''
|
||||
URL = "https://www.spaceship.com/"
|
||||
Code = "spaceship"
|
||||
Since = "v4.22.0"
|
||||
|
||||
Example = '''
|
||||
SPACESHIP_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
SPACESHIP_API_SECRET="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
lego --email you@example.com --dns spaceship -d '*.example.com' -d example.com run
|
||||
'''
|
||||
|
||||
[Configuration]
|
||||
[Configuration.Credentials]
|
||||
SPACESHIP_API_KEY = "API key"
|
||||
SPACESHIP_API_SECRET = "API secret"
|
||||
[Configuration.Additional]
|
||||
SPACESHIP_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
|
||||
SPACESHIP_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
|
||||
SPACESHIP_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)"
|
||||
SPACESHIP_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
|
||||
|
||||
[Links]
|
||||
API = "https://docs.spaceship.dev/#tag/DNS-records"
|
||||
143
providers/dns/spaceship/spaceship_test.go
Normal file
143
providers/dns/spaceship/spaceship_test.go
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package spaceship
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/platform/tester"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(EnvAPIKey, EnvAPISecret).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",
|
||||
EnvAPISecret: "secret",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing API key",
|
||||
envVars: map[string]string{
|
||||
EnvAPIKey: "",
|
||||
EnvAPISecret: "secret",
|
||||
},
|
||||
expected: "spaceship: some credentials information are missing: SPACESHIP_API_KEY",
|
||||
},
|
||||
{
|
||||
desc: "missing API secret",
|
||||
envVars: map[string]string{
|
||||
EnvAPIKey: "key",
|
||||
EnvAPISecret: "",
|
||||
},
|
||||
expected: "spaceship: some credentials information are missing: SPACESHIP_API_SECRET",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{},
|
||||
expected: "spaceship: some credentials information are missing: SPACESHIP_API_KEY,SPACESHIP_API_SECRET",
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
apiSecret string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "success",
|
||||
apiKey: "key",
|
||||
apiSecret: "secret",
|
||||
},
|
||||
{
|
||||
desc: "missing API key",
|
||||
apiSecret: "secret",
|
||||
expected: "spaceship: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing API secret",
|
||||
apiKey: "key",
|
||||
expected: "spaceship: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
expected: "spaceship: credentials missing",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := NewDefaultConfig()
|
||||
config.APIKey = test.apiKey
|
||||
config.APISecret = test.apiSecret
|
||||
|
||||
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)
|
||||
}
|
||||
3
providers/dns/zz_gen_dns_providers.go
generated
3
providers/dns/zz_gen_dns_providers.go
generated
|
|
@ -128,6 +128,7 @@ import (
|
|||
"github.com/go-acme/lego/v4/providers/dns/shellrent"
|
||||
"github.com/go-acme/lego/v4/providers/dns/simply"
|
||||
"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/technitium"
|
||||
"github.com/go-acme/lego/v4/providers/dns/tencentcloud"
|
||||
|
|
@ -401,6 +402,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||
return simply.NewDNSProvider()
|
||||
case "sonic":
|
||||
return sonic.NewDNSProvider()
|
||||
case "spaceship":
|
||||
return spaceship.NewDNSProvider()
|
||||
case "stackpath":
|
||||
return stackpath.NewDNSProvider()
|
||||
case "technitium":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue