Add DNS provider for Derak Cloud (#1909)

This commit is contained in:
Ludovic Fernandez 2023-05-05 12:37:54 +02:00 committed by GitHub
parent 67d80a1445
commit 3d44184074
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 1471 additions and 26 deletions

View file

@ -54,31 +54,31 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
| [Azure](https://go-acme.github.io/lego/dns/azure/) | [Bindman](https://go-acme.github.io/lego/dns/bindman/) | [Bluecat](https://go-acme.github.io/lego/dns/bluecat/) | [Brandit](https://go-acme.github.io/lego/dns/brandit/) |
| [Bunny](https://go-acme.github.io/lego/dns/bunny/) | [Checkdomain](https://go-acme.github.io/lego/dns/checkdomain/) | [Civo](https://go-acme.github.io/lego/dns/civo/) | [CloudDNS](https://go-acme.github.io/lego/dns/clouddns/) |
| [Cloudflare](https://go-acme.github.io/lego/dns/cloudflare/) | [ClouDNS](https://go-acme.github.io/lego/dns/cloudns/) | [CloudXNS](https://go-acme.github.io/lego/dns/cloudxns/) | [ConoHa](https://go-acme.github.io/lego/dns/conoha/) |
| [Constellix](https://go-acme.github.io/lego/dns/constellix/) | [deSEC.io](https://go-acme.github.io/lego/dns/desec/) | [Designate DNSaaS for Openstack](https://go-acme.github.io/lego/dns/designate/) | [Digital Ocean](https://go-acme.github.io/lego/dns/digitalocean/) |
| [DNS Made Easy](https://go-acme.github.io/lego/dns/dnsmadeeasy/) | [dnsHome.de](https://go-acme.github.io/lego/dns/dnshomede/) | [DNSimple](https://go-acme.github.io/lego/dns/dnsimple/) | [DNSPod (deprecated)](https://go-acme.github.io/lego/dns/dnspod/) |
| [Domain Offensive (do.de)](https://go-acme.github.io/lego/dns/dode/) | [Domeneshop](https://go-acme.github.io/lego/dns/domeneshop/) | [DreamHost](https://go-acme.github.io/lego/dns/dreamhost/) | [Duck DNS](https://go-acme.github.io/lego/dns/duckdns/) |
| [Dyn](https://go-acme.github.io/lego/dns/dyn/) | [Dynu](https://go-acme.github.io/lego/dns/dynu/) | [EasyDNS](https://go-acme.github.io/lego/dns/easydns/) | [Epik](https://go-acme.github.io/lego/dns/epik/) |
| [Exoscale](https://go-acme.github.io/lego/dns/exoscale/) | [External program](https://go-acme.github.io/lego/dns/exec/) | [freemyip.com](https://go-acme.github.io/lego/dns/freemyip/) | [G-Core Labs](https://go-acme.github.io/lego/dns/gcore/) |
| [Gandi Live DNS (v5)](https://go-acme.github.io/lego/dns/gandiv5/) | [Gandi](https://go-acme.github.io/lego/dns/gandi/) | [Glesys](https://go-acme.github.io/lego/dns/glesys/) | [Go Daddy](https://go-acme.github.io/lego/dns/godaddy/) |
| [Google Cloud](https://go-acme.github.io/lego/dns/gcloud/) | [Google Domains](https://go-acme.github.io/lego/dns/googledomains/) | [Hetzner](https://go-acme.github.io/lego/dns/hetzner/) | [Hosting.de](https://go-acme.github.io/lego/dns/hostingde/) |
| [Hosttech](https://go-acme.github.io/lego/dns/hosttech/) | [HTTP request](https://go-acme.github.io/lego/dns/httpreq/) | [Hurricane Electric DNS](https://go-acme.github.io/lego/dns/hurricane/) | [HyperOne](https://go-acme.github.io/lego/dns/hyperone/) |
| [IBM Cloud (SoftLayer)](https://go-acme.github.io/lego/dns/ibmcloud/) | [IIJ DNS Platform Service](https://go-acme.github.io/lego/dns/iijdpf/) | [Infoblox](https://go-acme.github.io/lego/dns/infoblox/) | [Infomaniak](https://go-acme.github.io/lego/dns/infomaniak/) |
| [Internet Initiative Japan](https://go-acme.github.io/lego/dns/iij/) | [Internet.bs](https://go-acme.github.io/lego/dns/internetbs/) | [INWX](https://go-acme.github.io/lego/dns/inwx/) | [Ionos](https://go-acme.github.io/lego/dns/ionos/) |
| [iwantmyname](https://go-acme.github.io/lego/dns/iwantmyname/) | [Joker](https://go-acme.github.io/lego/dns/joker/) | [Joohoi's ACME-DNS](https://go-acme.github.io/lego/dns/acme-dns/) | [Liara](https://go-acme.github.io/lego/dns/liara/) |
| [Linode (v4)](https://go-acme.github.io/lego/dns/linode/) | [Liquid Web](https://go-acme.github.io/lego/dns/liquidweb/) | [Loopia](https://go-acme.github.io/lego/dns/loopia/) | [LuaDNS](https://go-acme.github.io/lego/dns/luadns/) |
| [Manual](https://go-acme.github.io/lego/dns/manual/) | [MyDNS.jp](https://go-acme.github.io/lego/dns/mydnsjp/) | [MythicBeasts](https://go-acme.github.io/lego/dns/mythicbeasts/) | [Name.com](https://go-acme.github.io/lego/dns/namedotcom/) |
| [Namecheap](https://go-acme.github.io/lego/dns/namecheap/) | [Namesilo](https://go-acme.github.io/lego/dns/namesilo/) | [NearlyFreeSpeech.NET](https://go-acme.github.io/lego/dns/nearlyfreespeech/) | [Netcup](https://go-acme.github.io/lego/dns/netcup/) |
| [Netlify](https://go-acme.github.io/lego/dns/netlify/) | [Nicmanager](https://go-acme.github.io/lego/dns/nicmanager/) | [NIFCloud](https://go-acme.github.io/lego/dns/nifcloud/) | [Njalla](https://go-acme.github.io/lego/dns/njalla/) |
| [Nodion](https://go-acme.github.io/lego/dns/nodion/) | [NS1](https://go-acme.github.io/lego/dns/ns1/) | [Open Telekom Cloud](https://go-acme.github.io/lego/dns/otc/) | [Oracle Cloud](https://go-acme.github.io/lego/dns/oraclecloud/) |
| [OVH](https://go-acme.github.io/lego/dns/ovh/) | [plesk.com](https://go-acme.github.io/lego/dns/plesk/) | [Porkbun](https://go-acme.github.io/lego/dns/porkbun/) | [PowerDNS](https://go-acme.github.io/lego/dns/pdns/) |
| [Rackspace](https://go-acme.github.io/lego/dns/rackspace/) | [reg.ru](https://go-acme.github.io/lego/dns/regru/) | [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) | [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) |
| [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) | [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) | [Selectel](https://go-acme.github.io/lego/dns/selectel/) | [Servercow](https://go-acme.github.io/lego/dns/servercow/) |
| [Simply.com](https://go-acme.github.io/lego/dns/simply/) | [Sonic](https://go-acme.github.io/lego/dns/sonic/) | [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) | [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) |
| [TransIP](https://go-acme.github.io/lego/dns/transip/) | [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [Ultradns](https://go-acme.github.io/lego/dns/ultradns/) | [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) |
| [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) | [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) | [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) |
| [VK Cloud](https://go-acme.github.io/lego/dns/vkcloud/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) | [Websupport](https://go-acme.github.io/lego/dns/websupport/) |
| [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex Cloud](https://go-acme.github.io/lego/dns/yandexcloud/) | [Yandex PDD](https://go-acme.github.io/lego/dns/yandex/) | [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) |
| [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | | | |
| [Constellix](https://go-acme.github.io/lego/dns/constellix/) | [Derak Cloud](https://go-acme.github.io/lego/dns/derak/) | [deSEC.io](https://go-acme.github.io/lego/dns/desec/) | [Designate DNSaaS for Openstack](https://go-acme.github.io/lego/dns/designate/) |
| [Digital Ocean](https://go-acme.github.io/lego/dns/digitalocean/) | [DNS Made Easy](https://go-acme.github.io/lego/dns/dnsmadeeasy/) | [dnsHome.de](https://go-acme.github.io/lego/dns/dnshomede/) | [DNSimple](https://go-acme.github.io/lego/dns/dnsimple/) |
| [DNSPod (deprecated)](https://go-acme.github.io/lego/dns/dnspod/) | [Domain Offensive (do.de)](https://go-acme.github.io/lego/dns/dode/) | [Domeneshop](https://go-acme.github.io/lego/dns/domeneshop/) | [DreamHost](https://go-acme.github.io/lego/dns/dreamhost/) |
| [Duck DNS](https://go-acme.github.io/lego/dns/duckdns/) | [Dyn](https://go-acme.github.io/lego/dns/dyn/) | [Dynu](https://go-acme.github.io/lego/dns/dynu/) | [EasyDNS](https://go-acme.github.io/lego/dns/easydns/) |
| [Epik](https://go-acme.github.io/lego/dns/epik/) | [Exoscale](https://go-acme.github.io/lego/dns/exoscale/) | [External program](https://go-acme.github.io/lego/dns/exec/) | [freemyip.com](https://go-acme.github.io/lego/dns/freemyip/) |
| [G-Core Labs](https://go-acme.github.io/lego/dns/gcore/) | [Gandi Live DNS (v5)](https://go-acme.github.io/lego/dns/gandiv5/) | [Gandi](https://go-acme.github.io/lego/dns/gandi/) | [Glesys](https://go-acme.github.io/lego/dns/glesys/) |
| [Go Daddy](https://go-acme.github.io/lego/dns/godaddy/) | [Google Cloud](https://go-acme.github.io/lego/dns/gcloud/) | [Google Domains](https://go-acme.github.io/lego/dns/googledomains/) | [Hetzner](https://go-acme.github.io/lego/dns/hetzner/) |
| [Hosting.de](https://go-acme.github.io/lego/dns/hostingde/) | [Hosttech](https://go-acme.github.io/lego/dns/hosttech/) | [HTTP request](https://go-acme.github.io/lego/dns/httpreq/) | [Hurricane Electric DNS](https://go-acme.github.io/lego/dns/hurricane/) |
| [HyperOne](https://go-acme.github.io/lego/dns/hyperone/) | [IBM Cloud (SoftLayer)](https://go-acme.github.io/lego/dns/ibmcloud/) | [IIJ DNS Platform Service](https://go-acme.github.io/lego/dns/iijdpf/) | [Infoblox](https://go-acme.github.io/lego/dns/infoblox/) |
| [Infomaniak](https://go-acme.github.io/lego/dns/infomaniak/) | [Internet Initiative Japan](https://go-acme.github.io/lego/dns/iij/) | [Internet.bs](https://go-acme.github.io/lego/dns/internetbs/) | [INWX](https://go-acme.github.io/lego/dns/inwx/) |
| [Ionos](https://go-acme.github.io/lego/dns/ionos/) | [iwantmyname](https://go-acme.github.io/lego/dns/iwantmyname/) | [Joker](https://go-acme.github.io/lego/dns/joker/) | [Joohoi's ACME-DNS](https://go-acme.github.io/lego/dns/acme-dns/) |
| [Liara](https://go-acme.github.io/lego/dns/liara/) | [Linode (v4)](https://go-acme.github.io/lego/dns/linode/) | [Liquid Web](https://go-acme.github.io/lego/dns/liquidweb/) | [Loopia](https://go-acme.github.io/lego/dns/loopia/) |
| [LuaDNS](https://go-acme.github.io/lego/dns/luadns/) | [Manual](https://go-acme.github.io/lego/dns/manual/) | [MyDNS.jp](https://go-acme.github.io/lego/dns/mydnsjp/) | [MythicBeasts](https://go-acme.github.io/lego/dns/mythicbeasts/) |
| [Name.com](https://go-acme.github.io/lego/dns/namedotcom/) | [Namecheap](https://go-acme.github.io/lego/dns/namecheap/) | [Namesilo](https://go-acme.github.io/lego/dns/namesilo/) | [NearlyFreeSpeech.NET](https://go-acme.github.io/lego/dns/nearlyfreespeech/) |
| [Netcup](https://go-acme.github.io/lego/dns/netcup/) | [Netlify](https://go-acme.github.io/lego/dns/netlify/) | [Nicmanager](https://go-acme.github.io/lego/dns/nicmanager/) | [NIFCloud](https://go-acme.github.io/lego/dns/nifcloud/) |
| [Njalla](https://go-acme.github.io/lego/dns/njalla/) | [Nodion](https://go-acme.github.io/lego/dns/nodion/) | [NS1](https://go-acme.github.io/lego/dns/ns1/) | [Open Telekom Cloud](https://go-acme.github.io/lego/dns/otc/) |
| [Oracle Cloud](https://go-acme.github.io/lego/dns/oraclecloud/) | [OVH](https://go-acme.github.io/lego/dns/ovh/) | [plesk.com](https://go-acme.github.io/lego/dns/plesk/) | [Porkbun](https://go-acme.github.io/lego/dns/porkbun/) |
| [PowerDNS](https://go-acme.github.io/lego/dns/pdns/) | [Rackspace](https://go-acme.github.io/lego/dns/rackspace/) | [reg.ru](https://go-acme.github.io/lego/dns/regru/) | [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) |
| [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) | [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) | [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) | [Selectel](https://go-acme.github.io/lego/dns/selectel/) |
| [Servercow](https://go-acme.github.io/lego/dns/servercow/) | [Simply.com](https://go-acme.github.io/lego/dns/simply/) | [Sonic](https://go-acme.github.io/lego/dns/sonic/) | [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) |
| [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) | [TransIP](https://go-acme.github.io/lego/dns/transip/) | [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [Ultradns](https://go-acme.github.io/lego/dns/ultradns/) |
| [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) | [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) | [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) |
| [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | [VK Cloud](https://go-acme.github.io/lego/dns/vkcloud/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) |
| [Websupport](https://go-acme.github.io/lego/dns/websupport/) | [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex Cloud](https://go-acme.github.io/lego/dns/yandexcloud/) | [Yandex PDD](https://go-acme.github.io/lego/dns/yandex/) |
| [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | | |
<!-- END DNS PROVIDERS LIST -->

View file

@ -33,6 +33,7 @@ func allDNSCodes() string {
"cloudxns",
"conoha",
"constellix",
"derak",
"desec",
"designate",
"digitalocean",
@ -549,6 +550,27 @@ func displayDNSHelp(w io.Writer, name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/constellix`)
case "derak":
// generated from: providers/dns/derak/derak.toml
ew.writeln(`Configuration for Derak Cloud.`)
ew.writeln(`Code: 'derak'`)
ew.writeln(`Since: 'v4.12.0'`)
ew.writeln()
ew.writeln(`Credentials:`)
ew.writeln(` - "DERAK_API_KEY": The API key`)
ew.writeln()
ew.writeln(`Additional Configuration:`)
ew.writeln(` - "DERAK_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "DERAK_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "DERAK_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "DERAK_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "DERAK_WEBSITE_ID": Force the zone/website ID`)
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/derak`)
case "desec":
// generated from: providers/dns/desec/desec.toml
ew.writeln(`Configuration for deSEC.io.`)

View file

@ -0,0 +1,65 @@
---
title: "Derak Cloud"
date: 2019-03-03T16:39:46+01:00
draft: false
slug: derak
dnsprovider:
since: "v4.12.0"
code: "derak"
url: "https://derak.cloud/"
---
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/derak/derak.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
Configuration for [Derak Cloud](https://derak.cloud/).
<!--more-->
- Code: `derak`
- Since: v4.12.0
Here is an example bash command using the Derak Cloud provider:
```bash
DERAK_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
lego --email myemail@example.com --dns derak --domains my.example.org run
```
## Credentials
| Environment Variable Name | Description |
|-----------------------|-------------|
| `DERAK_API_KEY` | The API key |
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
## Additional Configuration
| Environment Variable Name | Description |
|--------------------------------|-------------|
| `DERAK_HTTP_TIMEOUT` | API request timeout |
| `DERAK_POLLING_INTERVAL` | Time between DNS propagation check |
| `DERAK_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `DERAK_TTL` | The TTL of the TXT record used for the DNS challenge |
| `DERAK_WEBSITE_ID` | Force the zone/website ID |
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" >}}).
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/derak/derak.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

View file

@ -125,7 +125,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, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudxns, conoha, constellix, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpreq, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, servercow, simply, sonic, stackpath, tencentcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, vscale, vultr, websupport, wedos, yandex, yandexcloud, zoneee, zonomi
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudxns, conoha, constellix, derak, desec, designate, digitalocean, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpreq, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, iwantmyname, joker, liara, lightsail, linode, liquidweb, loopia, luadns, manual, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, servercow, simply, sonic, stackpath, tencentcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, vscale, vultr, websupport, wedos, yandex, yandexcloud, zoneee, zonomi
More information: https://go-acme.github.io/lego/dns
"""

View file

@ -0,0 +1,195 @@
// Package derak implements a DNS provider for solving the DNS-01 challenge using Derak Cloud.
package derak
import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"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/derak/internal"
"github.com/miekg/dns"
)
// Environment variables names.
const (
envNamespace = "DERAK_"
EnvAPIKey = envNamespace + "API_KEY"
EnvWebsiteID = envNamespace + "WEBSITE_ID"
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
WebsiteID 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, 2*time.Minute),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 5*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 Derak Cloud.
// Credentials must be passed in the environment variable: DERAK_API_KEY.
func NewDNSProvider() (*DNSProvider, error) {
values, err := env.Get(EnvAPIKey)
if err != nil {
return nil, fmt.Errorf("derak: %w", err)
}
config := NewDefaultConfig()
config.APIKey = values[EnvAPIKey]
config.WebsiteID = env.GetOrDefaultString(EnvWebsiteID, "")
return NewDNSProviderConfig(config)
}
// NewDNSProviderConfig return a DNSProvider instance configured for Derak Cloud.
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
if config == nil {
return nil, errors.New("derak: the configuration of the DNS provider is nil")
}
if config.APIKey == "" {
return nil, errors.New("derak: missing credentials")
}
client := internal.NewClient(config.APIKey)
if config.HTTPClient != nil {
client.HTTPClient = config.HTTPClient
}
return &DNSProvider{
config: config,
client: client,
recordIDs: make(map[string]string),
}, 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
}
// Present creates a TXT record using the specified parameters.
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
ctx := context.Background()
info := dns01.GetChallengeInfo(domain, keyAuth)
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
if err != nil {
return fmt.Errorf("derak: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
}
recordName, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
if err != nil {
return fmt.Errorf("derak: %w", err)
}
zoneID, err := d.getZoneID(ctx, info)
if err != nil {
return fmt.Errorf("derak: get zone ID: %w", err)
}
r := internal.Record{
Type: "TXT",
Host: recordName,
Content: info.Value,
TTL: d.config.TTL,
}
record, err := d.client.CreateRecord(ctx, zoneID, r)
if err != nil {
return fmt.Errorf("derak: create record: %w", err)
}
d.recordIDsMu.Lock()
d.recordIDs[token] = record.ID
d.recordIDsMu.Unlock()
return nil
}
// CleanUp removes the TXT record matching the specified parameters.
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()
info := dns01.GetChallengeInfo(domain, keyAuth)
zoneID, err := d.getZoneID(ctx, info)
if err != nil {
return fmt.Errorf("derak: get zone ID: %w", err)
}
// gets the record's unique ID
d.recordIDsMu.Lock()
recordID, ok := d.recordIDs[token]
d.recordIDsMu.Unlock()
if !ok {
return fmt.Errorf("derak: unknown record ID for '%s' '%s'", info.EffectiveFQDN, token)
}
err = d.client.DeleteRecord(ctx, zoneID, recordID)
if err != nil {
return fmt.Errorf("derak: delete record: %w", err)
}
// deletes record ID from map
d.recordIDsMu.Lock()
delete(d.recordIDs, token)
d.recordIDsMu.Unlock()
return nil
}
func (d *DNSProvider) getZoneID(ctx context.Context, info dns01.ChallengeInfo) (string, error) {
zoneID := d.config.WebsiteID
if zoneID != "" {
return zoneID, nil
}
zones, err := d.client.GetZones(ctx)
if err != nil {
return "", fmt.Errorf("get zones: %w", err)
}
for _, zone := range zones {
if strings.HasSuffix(info.EffectiveFQDN, dns.Fqdn(zone.HumanReadable)) {
return zone.ID, nil
}
}
return "", fmt.Errorf("zone/website not found %s", info.EffectiveFQDN)
}

View file

@ -0,0 +1,20 @@
Name = "Derak Cloud"
Description = ''''''
URL = "https://derak.cloud/"
Code = "derak"
Since = "v4.12.0"
Example = '''
DERAK_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
lego --email myemail@example.com --dns derak --domains my.example.org run
'''
[Configuration]
[Configuration.Credentials]
DERAK_API_KEY = "The API key"
[Configuration.Additional]
DERAK_WEBSITE_ID = "Force the zone/website ID"
DERAK_POLLING_INTERVAL = "Time between DNS propagation check"
DERAK_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
DERAK_TTL = "The TTL of the TXT record used for the DNS challenge"
DERAK_HTTP_TIMEOUT = "API request timeout"

View file

@ -0,0 +1,113 @@
package derak
import (
"testing"
"github.com/go-acme/lego/v4/platform/tester"
"github.com/stretchr/testify/require"
)
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest(EnvAPIKey, EnvWebsiteID).WithDomain(envDomain)
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "success",
envVars: map[string]string{
EnvAPIKey: "key",
},
},
{
desc: "missing API key",
envVars: map[string]string{},
expected: "derak: some credentials information are missing: DERAK_API_KEY",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
defer envTest.RestoreEnv()
envTest.ClearEnv()
envTest.Apply(test.envVars)
p, err := NewDNSProvider()
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.client)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
apiKey string
expected string
}{
{
desc: "success",
apiKey: "key",
},
{
desc: "missing API key",
expected: "derak: missing credentials",
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.APIKey = test.apiKey
p, err := NewDNSProviderConfig(config)
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.client)
} else {
require.EqualError(t, err, test.expected)
}
})
}
}
func TestLivePresent(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}

View file

@ -0,0 +1,230 @@
package internal
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"time"
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
querystring "github.com/google/go-querystring/query"
)
const defaultBaseURL = "https://api.derak.cloud/v1.0"
type Client struct {
baseURL *url.URL
HTTPClient *http.Client
zoneEndpoint string
apiKey string
}
func NewClient(apiKey string) *Client {
baseURL, _ := url.Parse(defaultBaseURL)
return &Client{
HTTPClient: &http.Client{Timeout: 10 * time.Second},
baseURL: baseURL,
zoneEndpoint: "https://api.derak.cloud/api/v2/service/cdn/zones",
apiKey: apiKey,
}
}
// GetRecords gets all records.
// Note: the response is not influenced by the query parameters, so the documentation seems wrong.
func (c Client) GetRecords(ctx context.Context, zoneID string, params *GetRecordsParameters) (*GetRecordsResponse, error) {
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords")
v, err := querystring.Values(params)
if err != nil {
return nil, err
}
endpoint.RawQuery = v.Encode()
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
response := &GetRecordsResponse{}
err = c.do(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// GetRecord gets a record by ID.
func (c Client) GetRecord(ctx context.Context, zoneID string, recordID string) (*Record, error) {
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
response := &Record{}
err = c.do(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// CreateRecord creates a new record.
func (c Client) CreateRecord(ctx context.Context, zoneID string, record Record) (*Record, error) {
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords")
req, err := newJSONRequest(ctx, http.MethodPut, endpoint, record)
if err != nil {
return nil, err
}
response := &Record{}
err = c.do(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// EditRecord edits an existing record.
func (c Client) EditRecord(ctx context.Context, zoneID string, recordID string, record Record) (*Record, error) {
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, record)
if err != nil {
return nil, err
}
response := &Record{}
err = c.do(req, response)
if err != nil {
return nil, err
}
return response, nil
}
// DeleteRecord deletes an existing record.
func (c Client) DeleteRecord(ctx context.Context, zoneID string, recordID string) error {
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
if err != nil {
return err
}
response := &APIResponse[any]{}
err = c.do(req, response)
if err != nil {
return err
}
if !response.Success {
return fmt.Errorf("API error: %d %s", response.Error, codeText(response.Error))
}
return nil
}
// GetZones gets zones.
// Note: it's not a part of the official API, there is no documentation about this.
// The endpoint comes from UI calls analysis.
func (c Client) GetZones(ctx context.Context) ([]Zone, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.zoneEndpoint, http.NoBody)
if err != nil {
return nil, err
}
response := &APIResponse[[]Zone]{}
err = c.do(req, response)
if err != nil {
return nil, err
}
if !response.Success {
return nil, fmt.Errorf("API error: %d %s", response.Error, codeText(response.Error))
}
return response.Result, nil
}
func (c Client) do(req *http.Request, result any) error {
req.SetBasicAuth("api", c.apiKey)
resp, err := c.HTTPClient.Do(req)
if err != nil {
return errutils.NewHTTPDoError(req, err)
}
defer func() { _ = resp.Body.Close() }()
switch req.Method {
case http.MethodPut:
if resp.StatusCode != http.StatusCreated {
return parseError(req, resp)
}
default:
if resp.StatusCode != http.StatusOK {
return parseError(req, resp)
}
}
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 response APIResponse[any]
err := json.Unmarshal(raw, &response)
if err != nil {
return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw)
}
return fmt.Errorf("[status code %d] %d: %s", resp.StatusCode, response.Error, codeText(response.Error))
}

View file

@ -0,0 +1,312 @@
package internal
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupTest(t *testing.T) (*Client, *http.ServeMux) {
t.Helper()
mux := http.NewServeMux()
server := httptest.NewServer(mux)
t.Cleanup(server.Close)
client := NewClient("secret")
client.baseURL, _ = url.Parse(server.URL)
client.zoneEndpoint = server.URL
client.HTTPClient = server.Client()
return client, mux
}
func testHandler(method string, statusCode int, filename string) func(rw http.ResponseWriter, req *http.Request) {
return func(rw http.ResponseWriter, req *http.Request) {
if req.Method != method {
http.Error(rw, fmt.Sprintf("unsupported method %s", req.Method), http.StatusBadRequest)
return
}
username, password, ok := req.BasicAuth()
if !ok {
http.Error(rw, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
if username != "api" {
http.Error(rw, fmt.Sprintf("username: want %s got %s", username, "user"), http.StatusUnauthorized)
return
}
if password != "secret" {
http.Error(rw, fmt.Sprintf("password: want %s got %s", password, "secret"), http.StatusUnauthorized)
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(statusCode)
_, err = io.Copy(rw, file)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
}
}
func TestGetRecords(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
testHandler(http.MethodGet, http.StatusOK, "records-GET.json"))
records, err := client.GetRecords(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
require.NoError(t, err)
excepted := &GetRecordsResponse{Data: []Record{
{
Type: "A",
Host: "example.com",
Content: "188.114.97.3",
ID: "812bee17a0b440b0bd5ee099a78b839c",
},
{
Type: "A",
Host: "example.com",
Content: "188.114.96.3",
ID: "90e6029da45d4a36bf31056cf85d0cab",
},
{
Type: "AAAA",
Host: "example.com",
Content: "2a06:98c1:3121::7",
ID: "0ac0320da0d24b5ca4f1648986a17340",
},
{
Type: "AAAA",
Host: "example.com",
Content: "2a06:98c1:3120::7",
ID: "c91599694aea413498a0b3cd0a54a585",
},
{
Type: "A",
Host: "www",
Content: "188.114.96.7",
ID: "c21f974992d549499f92e768bc468374",
},
{
Type: "A",
Host: "www",
Content: "188.114.97.7",
ID: "90c3c1f05dca426893f10f122d18ad7a",
},
{
Type: "AAAA",
Host: "www",
Content: "2a06:98c1:3121::",
ID: "379ab0ac0e434bc9aee5287e497f88a5",
},
{
Type: "AAAA",
Host: "www",
Content: "2a06:98c1:3120::",
ID: "a1c4f9e50ba74791a4d70dc96999474c",
},
}, Count: 8}
assert.Equal(t, excepted, records)
}
func TestGetRecords_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
_, err := client.GetRecords(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
require.Error(t, err)
}
func TestGetRecord(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
testHandler(http.MethodGet, http.StatusOK, "record-GET.json"))
record, err := client.GetRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
require.NoError(t, err)
excepted := &Record{
Type: "A",
Host: "example.com",
Content: "188.114.97.3",
ID: "812bee17a0b440b0bd5ee099a78b839c",
}
assert.Equal(t, excepted, record)
}
func TestGetRecord_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
_, err := client.GetRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
require.Error(t, err)
}
func TestCreateRecord(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
testHandler(http.MethodPut, http.StatusCreated, "record-PUT.json"))
r := Record{
Type: "TXT",
Host: "test",
Content: "test",
TTL: 120,
}
record, err := client.CreateRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", r)
require.NoError(t, err)
excepted := &Record{
Type: "A",
Host: "example.com",
Content: "188.114.97.3",
ID: "812bee17a0b440b0bd5ee099a78b839c",
}
assert.Equal(t, excepted, record)
}
func TestCreateRecord_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
testHandler(http.MethodPut, http.StatusUnauthorized, "error.json"))
r := Record{
Type: "TXT",
Host: "test",
Content: "test",
TTL: 120,
}
_, err := client.CreateRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", r)
require.Error(t, err)
}
func TestEditRecord(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
testHandler(http.MethodPatch, http.StatusOK, "record-PATCH.json"))
record, err := client.EditRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
Content: "foo",
})
require.NoError(t, err)
excepted := &Record{
Type: "A",
Host: "example.com",
Content: "188.114.97.3",
ID: "812bee17a0b440b0bd5ee099a78b839c",
}
assert.Equal(t, excepted, record)
}
func TestEditRecord_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
testHandler(http.MethodPatch, http.StatusUnauthorized, "error.json"))
_, err := client.EditRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
Content: "foo",
})
require.Error(t, err)
}
func TestDeleteRecord(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
testHandler(http.MethodDelete, http.StatusOK, "record-DELETE.json"))
err := client.DeleteRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
require.NoError(t, err)
}
func TestDeleteRecord_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
err := client.DeleteRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
require.Error(t, err)
}
func TestGetZones(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusOK, "service-cdn-zones.json"))
zones, err := client.GetZones(context.Background())
require.NoError(t, err)
excepted := []Zone{{
ID: "47c0ecf6c91243308c649ad1d2d618dd",
Tags: []string{},
ContextID: "47c0ecf6c91243308c649ad1d2d618dd",
ContextType: "CDN",
HumanReadable: "example.com",
Serial: "2301449956",
CreationTime: 1679090659902,
CreationTimeDate: time.Date(2023, time.March, 17, 22, 4, 19, 902000000, time.UTC),
Status: "active",
IsMoved: true,
Paused: false,
ServiceType: "CDN",
Limbo: false,
TeamName: "test",
TeamID: "640ef58496738d38fa7246a4",
MyTeam: true,
RoleName: "owner",
IsBoard: true,
BoardRole: []string{"owner"},
}}
assert.Equal(t, excepted, zones)
}
func TestGetZones_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
_, err := client.GetZones(context.Background())
require.Error(t, err)
}

View file

@ -0,0 +1 @@
{"success":false,"error":1010}

View file

@ -0,0 +1,3 @@
{
"success": true
}

View file

@ -0,0 +1,10 @@
{
"recordId": "812bee17a0b440b0bd5ee099a78b839c",
"type": "A",
"host": "example.com",
"content": "188.114.97.3",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
}

View file

@ -0,0 +1,10 @@
{
"recordId": "812bee17a0b440b0bd5ee099a78b839c",
"type": "A",
"host": "example.com",
"content": "188.114.97.3",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
}

View file

@ -0,0 +1,10 @@
{
"recordId": "812bee17a0b440b0bd5ee099a78b839c",
"type": "A",
"host": "example.com",
"content": "188.114.97.3",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
}

View file

@ -0,0 +1,85 @@
{
"data": [
{
"recordId": "812bee17a0b440b0bd5ee099a78b839c",
"type": "A",
"host": "example.com",
"content": "188.114.97.3",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "90e6029da45d4a36bf31056cf85d0cab",
"type": "A",
"host": "example.com",
"content": "188.114.96.3",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "0ac0320da0d24b5ca4f1648986a17340",
"type": "AAAA",
"host": "example.com",
"content": "2a06:98c1:3121::7",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "c91599694aea413498a0b3cd0a54a585",
"type": "AAAA",
"host": "example.com",
"content": "2a06:98c1:3120::7",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "c21f974992d549499f92e768bc468374",
"type": "A",
"host": "www",
"content": "188.114.96.7",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "90c3c1f05dca426893f10f122d18ad7a",
"type": "A",
"host": "www",
"content": "188.114.97.7",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "379ab0ac0e434bc9aee5287e497f88a5",
"type": "AAAA",
"host": "www",
"content": "2a06:98c1:3121::",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
},
{
"recordId": "a1c4f9e50ba74791a4d70dc96999474c",
"type": "AAAA",
"host": "www",
"content": "2a06:98c1:3120::",
"ttl": 0,
"cloud": false,
"advanced": false,
"customSSLType": ""
}
],
"count": 8
}

View file

@ -0,0 +1,40 @@
{
"success": true,
"result": [
{
"zoneId": "47c0ecf6c91243308c649ad1d2d618dd",
"tags": [],
"contextId": "47c0ecf6c91243308c649ad1d2d618dd",
"contextType": "CDN",
"humanReadable": "example.com",
"serial": "2301449956",
"creationTime": 1679090659902,
"creationTimeDate": "2023-03-17T22:04:19.902Z",
"status": "active",
"is_moved": true,
"paused": false,
"cache": {
"developmentMode": false
},
"securityOptions": {
"level": "off"
},
"ssl": {
"active": true
},
"dns": {
"length": 8
},
"serviceType": "CDN",
"limbo": false,
"teamName": "test",
"teamId": "640ef58496738d38fa7246a4",
"myTeam": true,
"roleName": "owner",
"isBoard": true,
"boardRole": [
"owner"
]
}
]
}

View file

@ -0,0 +1,250 @@
# Notes
## Forum
- https://derak.cloud/faq/programming/%da%86%da%af%d9%88%d9%86%d9%87-%d9%85%db%8c%d8%aa%d9%88%d8%a7%d9%86-%d8%a8%d9%87-api%d9%87%d8%a7-%d8%af%d8%b3%d8%aa%d8%b1%d8%b3%db%8c-%d8%af%d8%a7%d8%b4%d8%aa%d8%9f/
- https://derak.cloud/faq/programming/%d8%af%d8%b1%db%8c%d8%a7%d9%81%d8%aa-%da%a9%d9%84%db%8c%d8%af-api-api-key/
---
## DNS records (API)
### GET: Get a list of all DNS records
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords`
#### Query
| The name of the parameter | Description |
|---------------------------|----------------------------------|
| dnsType | dnsType query |
| content | The Host value of the DNS record |
#### Errors
| type error | Error code |
|-------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
#### Example
```bash
curl -X GET --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords
```
```bash
curl -X GET --user "api:api-MbmnxdpIBvk14nk5LFFdG1CV9PdMDfqi3tZAixBZLXYzM3qc187d7ede2de" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords \
-F dnsType="TXT"
```
### PUT: Creating a new DNS record on the desired website
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords`
#### parameters
| The name of the parameter | Description |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| *type | DNS record type [of types Aand AAAAand CNAMEand MXand NSand CAAand TXTand SPFand PTRand SRV] |
| *host | The Host value of the DNS record |
| *content | The Host value of the DNS record |
| ttl | TTL of DNS record [default: 0] |
| cloud | This parameter specifies whether the traffic of this record passes through the cloud or not [Default: false] |
| priority | Priority of MX and SRV records [Default: 0] |
| service | SRV record service |
| protocol | SRV record protocol [default: _tcp] |
| weight | SRV Record Weight [Default: 0] |
| port | Priority of MX and SRV records [Default: 0] |
| advanced | This parameter specifies whether this record has advanced settings or not [default: false] |
| upstreamPort | Upstream Port of DNS record [Default: 80] |
| upstreamProtocol | Upstream protocol related to DNS records. Note that if you change these settings for another record of the same subdomain, the settings will be overwritten. [Default: http] |
| customSSLType | Custom SSL related DNS record. Note that if you change these settings for another record of the same subdomain, the settings will be overwritten. |
#### Errors
| type error | Error code |
|--------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
| DNSValidationError | 1008 |
#### Example
```bash
curl -X PUT --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords \
-F type="A" \
-F host="app" \
-F content="1.2.3.4"
```
### GET: Get the information of a single DNS record
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId`
#### Errors
| type error | Error code |
|---------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
| RecordNotFoundError | 1021 |
#### Example
```bash
curl -X GET --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId
```
### PATCH: Edit the parameters of a DNS record
`https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId`
#### parameters
| The name of the parameter | Description |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| type | DNS record type [of types Aand AAAAand CNAMEand MXand NSand CAAand TXTand SPFand PTRand SRV] |
| host | The Host value of the DNS record |
| content | The Host value of the DNS record |
| ttl | TTL of DNS record [default: 0] |
| cloud | This parameter specifies whether the traffic of this record passes through the cloud or not [Default: false] |
| priority | Priority of MX and SRV records [Default: 0] |
| service | SRV record service |
| protocol | SRV record protocol [default: _tcp] |
| weight | SRV Record Weight [Default: 0] |
| port | Priority of MX and SRV records [Default: 0] |
| advanced | This parameter specifies whether this record has advanced settings or not [default: false] |
| upstreamPort | Upstream Port of DNS record [Default: 80] |
| upstreamProtocol | Upstream protocol related to DNS records. Note that if you change these settings for another record of the same subdomain, the settings will be overwritten. [Default: http] |
| customSSLType | Custom SSL related DNS record. Note that if you change these settings for another record of the same subdomain, the settings will be overwritten. |
#### Errors
| type error | Error code |
|---------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
| RecordNotFoundError | 1021 |
| DNSValidationError | 1008 |
#### Example
```bash
curl -X PATCH --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId \
-F cloud="true"
```
### DELETE: Delete a DNS record
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId`
#### Errors
| type error | Error code |
|---------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
| RecordNotFoundError | 1021 |
#### Example
```bash
curl -X DELETE --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/:recordId
```
---
## Cache clearing (API)
### POST: Clearing (Purge Cache) specified parameters, if no parameter is specified, the entire cache is deleted.
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/cache/purge`
#### parameters
| The name of the parameter | Description |
|---------------------------|-------------------------------------|
| hostname | The hostname to be deleted |
| hostnames | An array of hostnames to be cleared |
| url | The URL to be deleted |
| urls | An array of URLs to be purged |
#### Errors
| type error | Error code |
|-------------------|------------|
| ForbiddenError | 1003 |
| RateLimitExceeded | 1013 |
#### Examples
Purge URLS:
```bash
curl -X POST --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/cache/purge \
-F urls[]="https://www.derak.cloud/post/1" \
-F urls[]="https://www.derak.cloud/post/2"
```
Purge HOSTNAMES:
```bash
curl -X POST --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/cache/purge \
-F hostnames[]="www.derak.cloud" \
-F hostnames[]="app.derak.cloud"
```
Purge EVERYTHING:
```bash
curl -X POST --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/cache/purge
```
---
## API for SSL certificates
### PUT: Enable SSL for a domain
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/ssl/`
#### Errors
| type error | Error code |
|----------------|------------|
| ForbiddenError | 1003 |
#### Example
```bash
curl -X PUT --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/ssl/
```
### DELETE: Disable SSL for a domain
ex: `https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/ssl/`
#### Errors
| type error | Error code |
|----------------|------------|
| ForbiddenError | 1003 |
#### Example
```bash
curl -X DELETE --user "api:YOUR_API_KEY" \
https://api.derak.cloud/v1.0/zones/47c0ecf6c91243308c649ad1d2d618dd/ssl/
```

View file

@ -0,0 +1,76 @@
package internal
import "time"
type GetRecordsParameters struct {
DNSType string `url:"dnsType,omitempty"`
Content string `url:"content,omitempty"`
}
type GetRecordsResponse struct {
Data []Record `json:"data"`
Count int `json:"count"`
}
type Record struct {
Type string `json:"type,omitempty"`
Host string `json:"host,omitempty"`
Content string `json:"content,omitempty"`
ID string `json:"recordId,omitempty"`
TTL int `json:"ttl,omitempty"`
Cloud bool `json:"cloud,omitempty"`
Priority int `json:"priority,omitempty"`
Service string `json:"service,omitempty"`
Protocol string `json:"protocol,omitempty"`
Weight int `json:"weight,omitempty"`
Port int `json:"port,omitempty"`
Advanced bool `json:"advanced,omitempty"`
UpstreamPort int `json:"upstreamPort,omitempty"`
UpstreamProtocol string `json:"upstreamProtocol,omitempty"`
CustomSSLType string `json:"customSSLType,omitempty"`
}
type APIResponse[T any] struct {
Success bool `json:"success"`
Result T `json:"result"`
Error int `json:"error"`
}
type Zone struct {
ID string `json:"zoneId,omitempty"`
Tags []string `json:"tags,omitempty"`
ContextID string `json:"contextId,omitempty"`
ContextType string `json:"contextType,omitempty"`
HumanReadable string `json:"humanReadable,omitempty"`
Serial string `json:"serial,omitempty"`
CreationTime int64 `json:"creationTime,omitempty"`
CreationTimeDate time.Time `json:"creationTimeDate,omitempty"`
Status string `json:"status,omitempty"`
IsMoved bool `json:"is_moved,omitempty"`
Paused bool `json:"paused,omitempty"`
ServiceType string `json:"serviceType,omitempty"`
Limbo bool `json:"limbo,omitempty"`
TeamName string `json:"teamName,omitempty"`
TeamID string `json:"teamId,omitempty"`
MyTeam bool `json:"myTeam,omitempty"`
RoleName string `json:"roleName,omitempty"`
IsBoard bool `json:"isBoard,omitempty"`
BoardRole []string `json:"boardRole,omitempty"`
}
func codeText(code int) string {
switch code {
case 1008:
return "DNSValidationError"
case 1003:
return "ForbiddenError"
case 1013:
return "RateLimitExceeded"
case 1021:
return "RecordNotFoundError"
default:
return ""
}
}

View file

@ -24,6 +24,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/cloudxns"
"github.com/go-acme/lego/v4/providers/dns/conoha"
"github.com/go-acme/lego/v4/providers/dns/constellix"
"github.com/go-acme/lego/v4/providers/dns/derak"
"github.com/go-acme/lego/v4/providers/dns/desec"
"github.com/go-acme/lego/v4/providers/dns/designate"
"github.com/go-acme/lego/v4/providers/dns/digitalocean"
@ -164,6 +165,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return conoha.NewDNSProvider()
case "constellix":
return constellix.NewDNSProvider()
case "derak":
return derak.NewDNSProvider()
case "desec":
return desec.NewDNSProvider()
case "designate":