diff --git a/README.md b/README.md index 05c5a9b72..844a0fa66 100644 --- a/README.md +++ b/README.md @@ -158,85 +158,90 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns). Manual Metaname + Metaregistrar mijn.host Mittwald myaddr.{tools,dev,io} - MyDNS.jp + MyDNS.jp MythicBeasts Name.com Namecheap - Namesilo + Namesilo NearlyFreeSpeech.NET Netcup Netlify - Nicmanager + Nicmanager NIFCloud Njalla Nodion - NS1 + NS1 Open Telekom Cloud Oracle Cloud OVH - plesk.com + plesk.com Porkbun PowerDNS Rackspace - Rain Yun/雨云 + Rain Yun/雨云 RcodeZero reg.ru Regfish - RFC2136 + RFC2136 RimuHosting Sakura Cloud Scaleway - Selectel + Selectel Selectel v2 SelfHost.(de|eu) Servercow - Shellrent + Shellrent Simply.com Sonic Spaceship - Stackpath + Stackpath Technitium Tencent Cloud DNS Timeweb Cloud - TransIP + TransIP UKFast SafeDNS Ultradns Variomedia - VegaDNS + VegaDNS Vercel Versio.[nl|eu|uk] VinylDNS - VK Cloud + VK Cloud Volcano Engine/火山引擎 Vscale Vultr - Webnames + Webnames Websupport WEDOS West.cn/西部数码 - Yandex 360 + Yandex 360 Yandex Cloud Yandex PDD Zone.ee + Zonomi + + + diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 4f02a7879..cb4c53646 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -95,6 +95,7 @@ func allDNSCodes() string { "mailinabox", "manageengine", "metaname", + "metaregistrar", "mijnhost", "mittwald", "myaddr", @@ -1924,6 +1925,26 @@ func displayDNSHelp(w io.Writer, name string) error { ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/metaname`) + case "metaregistrar": + // generated from: providers/dns/metaregistrar/metaregistrar.toml + ew.writeln(`Configuration for Metaregistrar.`) + ew.writeln(`Code: 'metaregistrar'`) + ew.writeln(`Since: 'v4.23.0'`) + ew.writeln() + + ew.writeln(`Credentials:`) + ew.writeln(` - "METAREGISTRAR_API_TOKEN": The API token`) + ew.writeln() + + ew.writeln(`Additional Configuration:`) + ew.writeln(` - "METAREGISTRAR_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`) + ew.writeln(` - "METAREGISTRAR_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`) + ew.writeln(` - "METAREGISTRAR_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`) + ew.writeln(` - "METAREGISTRAR_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/metaregistrar`) + case "mijnhost": // generated from: providers/dns/mijnhost/mijnhost.toml ew.writeln(`Configuration for mijn.host.`) diff --git a/docs/content/dns/zz_gen_metaregistrar.md b/docs/content/dns/zz_gen_metaregistrar.md new file mode 100644 index 000000000..63cc2bebc --- /dev/null +++ b/docs/content/dns/zz_gen_metaregistrar.md @@ -0,0 +1,67 @@ +--- +title: "Metaregistrar" +date: 2019-03-03T16:39:46+01:00 +draft: false +slug: metaregistrar +dnsprovider: + since: "v4.23.0" + code: "metaregistrar" + url: "https://metaregistrar.com/" +--- + + + + + + +Configuration for [Metaregistrar](https://metaregistrar.com/). + + + + +- Code: `metaregistrar` +- Since: v4.23.0 + + +Here is an example bash command using the Metaregistrar provider: + +```bash +METAREGISTRAR_API_TOKEN="xxxxxxxxxxxxxxxxxxxxx" \ +lego --email you@example.com --dns metaregistrar -d '*.example.com' -d example.com run +``` + + + + +## Credentials + +| Environment Variable Name | Description | +|-----------------------|-------------| +| `METAREGISTRAR_API_TOKEN` | The API token | + +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 | +|--------------------------------|-------------| +| `METAREGISTRAR_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) | +| `METAREGISTRAR_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) | +| `METAREGISTRAR_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) | +| `METAREGISTRAR_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://metaregistrar.dev/docu/metaapi/) + + + + diff --git a/docs/data/zz_cli_help.toml b/docs/data/zz_cli_help.toml index 2f02d4da7..aff8766a2 100644 --- a/docs/data/zz_cli_help.toml +++ b/docs/data/zz_cli_help.toml @@ -149,7 +149,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, bookmyname, 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 + acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, bookmyname, 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, metaregistrar, 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 """ diff --git a/providers/dns/metaregistrar/internal/client.go b/providers/dns/metaregistrar/internal/client.go new file mode 100644 index 000000000..f2838c532 --- /dev/null +++ b/providers/dns/metaregistrar/internal/client.go @@ -0,0 +1,128 @@ +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://api.metaregistrar.com" + +// Client is a client to interact with the Metaregistrar API. +type Client struct { + token string + + baseURL *url.URL + HTTPClient *http.Client +} + +// NewClient creates a new Client. +func NewClient(token string) (*Client, error) { + if token == "" { + return nil, errors.New("token missing") + } + + baseURL, _ := url.Parse(defaultBaseURL) + + return &Client{ + token: token, + baseURL: baseURL, + HTTPClient: &http.Client{Timeout: 10 * time.Second}, + }, nil +} + +// UpdateDNSZone updates the DNS zone for a domain. +// To add or remove a TXT record we make a PATCH request. +// https://metaregistrar.dev/docu/metaapi/requests/patch_Update_dns_zone.html +func (c Client) UpdateDNSZone(ctx context.Context, domain string, updateRequest DNSZoneUpdateRequest) (*DNSZoneUpdateResponse, error) { + endpoint := c.baseURL.JoinPath("dnszone", domain) + + req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, updateRequest) + if err != nil { + return nil, err + } + + result := &DNSZoneUpdateResponse{} + + err = c.do(req, result) + if err != nil { + return nil, err + } + + return result, nil +} + +func (c Client) do(req *http.Request, result any) error { + req.Header.Add("token", c.token) + + 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 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 +} diff --git a/providers/dns/metaregistrar/internal/client_test.go b/providers/dns/metaregistrar/internal/client_test.go new file mode 100644 index 000000000..1015ba8c8 --- /dev/null +++ b/providers/dns/metaregistrar/internal/client_test.go @@ -0,0 +1,114 @@ +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("token") + require.NoError(t, err) + + client.HTTPClient = server.Client() + client.baseURL, _ = url.Parse(server.URL) + + return client +} + +func TestClient_UpdateDNSZone(t *testing.T) { + client := setupTest(t, "PATCH /dnszone/example.com", http.StatusOK, "update-dns-zone.json") + + updateRequest := DNSZoneUpdateRequest{ + Add: []Record{{ + Name: "@", + Type: "TXT", + TTL: 60, + Content: "value", + }}, + } + + response, err := client.UpdateDNSZone(context.Background(), "example.com", updateRequest) + require.NoError(t, err) + + expected := &DNSZoneUpdateResponse{ + ResponseID: "mapi1_cb46ad8790b62b76535bd3102bd282aec83b894c", + Status: "ok", + Message: "Command completed successfully", + } + + assert.Equal(t, expected, response) +} + +func TestClient_UpdateDNSZone_error(t *testing.T) { + testCases := []struct { + desc string + filename string + expected string + }{ + { + desc: "authentication error", + filename: "error.json", + expected: "invalid_token: the supplied token is invalid", + }, + { + desc: "API error", + filename: "error-response.json", + expected: "error: does_not_exist: This server does not exist", + }, + } + + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + client := setupTest(t, "PATCH /dnszone/example.com", http.StatusUnprocessableEntity, test.filename) + + updateRequest := DNSZoneUpdateRequest{ + Add: []Record{{ + Name: "@", + Type: "TXT", + TTL: 60, + Content: "value", + }}, + } + + _, err := client.UpdateDNSZone(context.Background(), "example.com", updateRequest) + require.EqualError(t, err, test.expected) + }) + } +} diff --git a/providers/dns/metaregistrar/internal/fixtures/error-response.json b/providers/dns/metaregistrar/internal/fixtures/error-response.json new file mode 100644 index 000000000..8fa5a5ff3 --- /dev/null +++ b/providers/dns/metaregistrar/internal/fixtures/error-response.json @@ -0,0 +1,6 @@ +{ + "responseId": "1_0a407cb0634a56374ba80f863fda53ae37fd0042", + "status": "error", + "errorCode": "does_not_exist", + "errorMessage": "This server does not exist" +} diff --git a/providers/dns/metaregistrar/internal/fixtures/error.json b/providers/dns/metaregistrar/internal/fixtures/error.json new file mode 100644 index 000000000..c76a32fc8 --- /dev/null +++ b/providers/dns/metaregistrar/internal/fixtures/error.json @@ -0,0 +1,4 @@ +{ + "error": "invalid_token", + "message": "the supplied token is invalid" +} \ No newline at end of file diff --git a/providers/dns/metaregistrar/internal/fixtures/update-dns-zone.json b/providers/dns/metaregistrar/internal/fixtures/update-dns-zone.json new file mode 100644 index 000000000..b4977272a --- /dev/null +++ b/providers/dns/metaregistrar/internal/fixtures/update-dns-zone.json @@ -0,0 +1,5 @@ +{ + "responseId": "mapi1_cb46ad8790b62b76535bd3102bd282aec83b894c", + "status": "ok", + "message": "Command completed successfully" +} diff --git a/providers/dns/metaregistrar/internal/types.go b/providers/dns/metaregistrar/internal/types.go new file mode 100644 index 000000000..d8b6b3f87 --- /dev/null +++ b/providers/dns/metaregistrar/internal/types.go @@ -0,0 +1,67 @@ +package internal + +import ( + "strings" +) + +// APIError It's a mix of documented and undocumented fields. +// Note: the documentation is inconsistent: the names of property are not the same as the JSON sample. +// https://metaregistrar.dev/docu/metaapi/requests/response_ErrorResponse.html +type APIError struct { + ResponseID string `json:"responseId,omitempty"` + Status string `json:"status,omitempty"` + Message string `json:"message,omitempty"` + Err string `json:"error,omitempty"` + ErrorCode string `json:"errorCode,omitempty"` + ErrorMessage string `json:"errorMessage,omitempty"` +} + +func (e *APIError) Error() string { + var msg []string + + if e.Status != "" { + msg = append(msg, e.Status) + } + + if e.Err != "" { + msg = append(msg, e.Err) + } + + if e.ErrorCode != "" { + msg = append(msg, e.ErrorCode) + } + + if e.Message != "" { + msg = append(msg, e.Message) + } + + if e.ErrorMessage != "" { + msg = append(msg, e.ErrorMessage) + } + + return strings.Join(msg, ": ") +} + +type Record struct { + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + TTL int `json:"ttl,omitempty"` + Content string `json:"content,omitempty"` + Priority int `json:"priority,omitempty"` + Disabled bool `json:"disabled,omitempty"` +} + +// DNSZoneUpdateRequest is the representation of DnszoneUpdateRequest object. +// https://metaregistrar.dev/docu/metaapi/requests/request_DnszoneUpdateRequest.html +type DNSZoneUpdateRequest struct { + Add []Record `json:"add,omitempty"` + Remove []Record `json:"rem,omitempty"` +} + +// DNSZoneUpdateResponse is the representation of DnszoneUpdateResponse object. +// https://metaregistrar.dev/docu/metaapi/requests/response_DnszoneUpdateResponse.html +type DNSZoneUpdateResponse struct { + ResponseID string `json:"responseId,omitempty"` + Status string `json:"status,omitempty"` + Message string `json:"message,omitempty"` +} diff --git a/providers/dns/metaregistrar/metaregistrar.go b/providers/dns/metaregistrar/metaregistrar.go new file mode 100644 index 000000000..28526fcb4 --- /dev/null +++ b/providers/dns/metaregistrar/metaregistrar.go @@ -0,0 +1,147 @@ +// Package metaregistrar implements a DNS provider for solving the DNS-01 challenge using Metaregistrar. +package metaregistrar + +import ( + "context" + "errors" + "fmt" + "net/http" + "strconv" + "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/metaregistrar/internal" +) + +// Environment variables names. +const ( + envNamespace = "METAREGISTRAR_" + + EnvToken = envNamespace + "API_TOKEN" + + 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 { + APIToken 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 Metaregistrar. +func NewDNSProvider() (*DNSProvider, error) { + values, err := env.Get(EnvToken) + if err != nil { + return nil, fmt.Errorf("metaregistrar: %w", err) + } + + config := NewDefaultConfig() + config.APIToken = values[EnvToken] + + return NewDNSProviderConfig(config) +} + +// NewDNSProviderConfig return a DNSProvider instance configured for Metaregistrar. +func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { + if config == nil { + return nil, errors.New("metaregistrar: the configuration of the DNS provider is nil") + } + + client, err := internal.NewClient(config.APIToken) + if err != nil { + return nil, fmt.Errorf("metaregistrar: %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("metaregistrar: could not find zone for domain %q: %w", domain, err) + } + + updateRequest := internal.DNSZoneUpdateRequest{ + Add: []internal.Record{{ + Name: dns01.UnFqdn(info.EffectiveFQDN), + Type: "TXT", + TTL: d.config.TTL, + Content: info.Value, + }}, + } + + _, err = d.client.UpdateDNSZone(context.Background(), dns01.UnFqdn(authZone), updateRequest) + if err != nil { + return fmt.Errorf("metaregistrar: %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("metaregistrar: could not find zone for domain %q: %w", domain, err) + } + + updateRequest := internal.DNSZoneUpdateRequest{ + Remove: []internal.Record{{ + Name: dns01.UnFqdn(info.EffectiveFQDN), + Type: "TXT", + TTL: d.config.TTL, + Content: strconv.Quote(info.Value), + }}, + } + + _, err = d.client.UpdateDNSZone(context.Background(), dns01.UnFqdn(authZone), updateRequest) + if err != nil { + return fmt.Errorf("metaregistrar: %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 +} diff --git a/providers/dns/metaregistrar/metaregistrar.toml b/providers/dns/metaregistrar/metaregistrar.toml new file mode 100644 index 000000000..952c7ea61 --- /dev/null +++ b/providers/dns/metaregistrar/metaregistrar.toml @@ -0,0 +1,22 @@ +Name = "Metaregistrar" +Description = '''''' +URL = "https://metaregistrar.com/" +Code = "metaregistrar" +Since = "v4.23.0" + +Example = ''' +METAREGISTRAR_API_TOKEN="xxxxxxxxxxxxxxxxxxxxx" \ +lego --email you@example.com --dns metaregistrar -d '*.example.com' -d example.com run +''' + +[Configuration] + [Configuration.Credentials] + METAREGISTRAR_API_TOKEN = "The API token" + [Configuration.Additional] + METAREGISTRAR_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)" + METAREGISTRAR_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)" + METAREGISTRAR_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)" + METAREGISTRAR_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)" + +[Links] + API = "https://metaregistrar.dev/docu/metaapi/" diff --git a/providers/dns/metaregistrar/metaregistrar_test.go b/providers/dns/metaregistrar/metaregistrar_test.go new file mode 100644 index 000000000..ffd7965d9 --- /dev/null +++ b/providers/dns/metaregistrar/metaregistrar_test.go @@ -0,0 +1,113 @@ +package metaregistrar + +import ( + "testing" + + "github.com/go-acme/lego/v4/platform/tester" + "github.com/stretchr/testify/require" +) + +const envDomain = envNamespace + "DOMAIN" + +var envTest = tester.NewEnvTest(EnvToken).WithDomain(envDomain) + +func TestNewDNSProvider(t *testing.T) { + testCases := []struct { + desc string + envVars map[string]string + expected string + }{ + { + desc: "success", + envVars: map[string]string{ + EnvToken: "token", + }, + }, + { + desc: "missing credentials", + envVars: map[string]string{}, + expected: "metaregistrar: some credentials information are missing: METAREGISTRAR_API_TOKEN", + }, + } + + 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 + apiToken string + expected string + }{ + { + desc: "success", + apiToken: "token", + }, + { + desc: "missing credentials", + expected: "metaregistrar: token missing", + }, + } + + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + config := NewDefaultConfig() + config.APIToken = test.apiToken + + 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) +} diff --git a/providers/dns/zz_gen_dns_providers.go b/providers/dns/zz_gen_dns_providers.go index 7988aca11..f3afca153 100644 --- a/providers/dns/zz_gen_dns_providers.go +++ b/providers/dns/zz_gen_dns_providers.go @@ -89,6 +89,7 @@ import ( "github.com/go-acme/lego/v4/providers/dns/mailinabox" "github.com/go-acme/lego/v4/providers/dns/manageengine" "github.com/go-acme/lego/v4/providers/dns/metaname" + "github.com/go-acme/lego/v4/providers/dns/metaregistrar" "github.com/go-acme/lego/v4/providers/dns/mijnhost" "github.com/go-acme/lego/v4/providers/dns/mittwald" "github.com/go-acme/lego/v4/providers/dns/myaddr" @@ -325,6 +326,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) { return manageengine.NewDNSProvider() case "metaname": return metaname.NewDNSProvider() + case "metaregistrar": + return metaregistrar.NewDNSProvider() case "mijnhost": return mijnhost.NewDNSProvider() case "mittwald":