mirror of
https://github.com/go-acme/lego.git
synced 2026-01-24 20:56:25 +00:00
Add DNS provider for Gravity (#2738)
This commit is contained in:
committed by
GitHub
parent
bc163db9ed
commit
dea97e4dfa
54
README.md
54
README.md
@@ -142,137 +142,137 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
|
||||
<td><a href="https://go-acme.github.io/lego/dns/godaddy/">Go Daddy</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/gcloud/">Google Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/googledomains/">Google Domains</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hetzner/">Hetzner</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/gravity/">Gravity</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hetzner/">Hetzner</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hostingde/">Hosting.de</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hostinger/">Hostinger</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hosttech/">Hosttech</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/httpreq/">HTTP request</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/httpreq/">HTTP request</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/httpnet/">http.net</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/huaweicloud/">Huawei Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hurricane/">Hurricane Electric DNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hyperone/">HyperOne</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/hyperone/">HyperOne</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ibmcloud/">IBM Cloud (SoftLayer)</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/iijdpf/">IIJ DNS Platform Service</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/infoblox/">Infoblox</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/infomaniak/">Infomaniak</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/infomaniak/">Infomaniak</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/iij/">Internet Initiative Japan</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/internetbs/">Internet.bs</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/inwx/">INWX</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ionos/">Ionos</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ionos/">Ionos</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ipv64/">IPv64</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/iwantmyname/">iwantmyname (Deprecated)</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/joker/">Joker</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/acme-dns/">Joohoi's ACME-DNS</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/acme-dns/">Joohoi's ACME-DNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/keyhelp/">KeyHelp</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/liara/">Liara</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/limacity/">Lima-City</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/linode/">Linode (v4)</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/linode/">Linode (v4)</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/liquidweb/">Liquid Web</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/loopia/">Loopia</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/luadns/">LuaDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mailinabox/">Mail-in-a-Box</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mailinabox/">Mail-in-a-Box</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/manageengine/">ManageEngine CloudDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/manual/">Manual</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/metaname/">Metaname</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/metaregistrar/">Metaregistrar</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/metaregistrar/">Metaregistrar</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mijnhost/">mijn.host</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mittwald/">Mittwald</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/myaddr/">myaddr.{tools,dev,io}</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mydnsjp/">MyDNS.jp</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mydnsjp/">MyDNS.jp</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/mythicbeasts/">MythicBeasts</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/namedotcom/">Name.com</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/namecheap/">Namecheap</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/namesilo/">Namesilo</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/namesilo/">Namesilo</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nearlyfreespeech/">NearlyFreeSpeech.NET</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/netcup/">Netcup</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/netlify/">Netlify</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nicmanager/">Nicmanager</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nicmanager/">Nicmanager</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nifcloud/">NIFCloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/njalla/">Njalla</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nodion/">Nodion</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ns1/">NS1</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ns1/">NS1</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/octenium/">Octenium</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/otc/">Open Telekom Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/oraclecloud/">Oracle Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ovh/">OVH</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ovh/">OVH</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/plesk/">plesk.com</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/porkbun/">Porkbun</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/pdns/">PowerDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rackspace/">Rackspace</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rackspace/">Rackspace</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rainyun/">Rain Yun/雨云</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rcodezero/">RcodeZero</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/regru/">reg.ru</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/regfish/">Regfish</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/regfish/">Regfish</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rfc2136/">RFC2136</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/rimuhosting/">RimuHosting</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/nicru/">RU CENTER</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/sakuracloud/">Sakura Cloud</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/sakuracloud/">Sakura Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/scaleway/">Scaleway</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/selectel/">Selectel</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/selectelv2/">Selectel v2</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/selfhostde/">SelfHost.(de|eu)</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/selfhostde/">SelfHost.(de|eu)</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/servercow/">Servercow</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/shellrent/">Shellrent</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/simply/">Simply.com</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/sonic/">Sonic</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/edgeone/">Tencent EdgeOne</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/timewebcloud/">Timeweb Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/safedns/">UKFast SafeDNS</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/safedns/">UKFast SafeDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/ultradns/">Ultradns</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/uniteddomains/">United-Domains</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vegadns/">VegaDNS</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vegadns/">VegaDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vercel/">Vercel</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/versio/">Versio.[nl|eu|uk]</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vkcloud/">VK Cloud</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vkcloud/">VK Cloud</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/volcengine/">Volcano Engine/火山引擎</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vscale/">Vscale</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnamesca/">webnames.ca</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnamesca/">webnames.ca</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/webnames/">webnames.ru</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/websupport/">Websupport</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/wedos/">WEDOS</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/westcn/">West.cn/西部数码</a></td>
|
||||
</tr><tr>
|
||||
<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>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneee/">Zone.ee</a></td>
|
||||
</tr><tr>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneee/">Zone.ee</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zoneedit/">ZoneEdit</a></td>
|
||||
<td><a href="https://go-acme.github.io/lego/dns/zonomi/">Zonomi</a></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr></table>
|
||||
|
||||
<!-- END DNS PROVIDERS LIST -->
|
||||
|
||||
23
cmd/zz_gen_cmd_dnshelp.go
generated
23
cmd/zz_gen_cmd_dnshelp.go
generated
@@ -79,6 +79,7 @@ func allDNSCodes() string {
|
||||
"glesys",
|
||||
"godaddy",
|
||||
"googledomains",
|
||||
"gravity",
|
||||
"hetzner",
|
||||
"hostingde",
|
||||
"hostinger",
|
||||
@@ -1636,6 +1637,28 @@ func displayDNSHelp(w io.Writer, name string) error {
|
||||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/googledomains`)
|
||||
|
||||
case "gravity":
|
||||
// generated from: providers/dns/gravity/gravity.toml
|
||||
ew.writeln(`Configuration for Gravity.`)
|
||||
ew.writeln(`Code: 'gravity'`)
|
||||
ew.writeln(`Since: 'v4.30.0'`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Credentials:`)
|
||||
ew.writeln(` - "GRAVITY_PASSWORD": Password`)
|
||||
ew.writeln(` - "GRAVITY_SERVER_URL": URL of the server`)
|
||||
ew.writeln(` - "GRAVITY_USERNAME": Username`)
|
||||
ew.writeln()
|
||||
|
||||
ew.writeln(`Additional Configuration:`)
|
||||
ew.writeln(` - "GRAVITY_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`)
|
||||
ew.writeln(` - "GRAVITY_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`)
|
||||
ew.writeln(` - "GRAVITY_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`)
|
||||
ew.writeln(` - "GRAVITY_SEQUENCE_INTERVAL": Time between sequential requests in seconds (Default: 1)`)
|
||||
|
||||
ew.writeln()
|
||||
ew.writeln(`More information: https://go-acme.github.io/lego/dns/gravity`)
|
||||
|
||||
case "hetzner":
|
||||
// generated from: providers/dns/hetzner/hetzner.toml
|
||||
ew.writeln(`Configuration for Hetzner.`)
|
||||
|
||||
71
docs/content/dns/zz_gen_gravity.md
generated
Normal file
71
docs/content/dns/zz_gen_gravity.md
generated
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: "Gravity"
|
||||
date: 2019-03-03T16:39:46+01:00
|
||||
draft: false
|
||||
slug: gravity
|
||||
dnsprovider:
|
||||
since: "v4.30.0"
|
||||
code: "gravity"
|
||||
url: "https://gravity.beryju.io/"
|
||||
---
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/gravity/gravity.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
|
||||
|
||||
Configuration for [Gravity](https://gravity.beryju.io/).
|
||||
|
||||
|
||||
<!--more-->
|
||||
|
||||
- Code: `gravity`
|
||||
- Since: v4.30.0
|
||||
|
||||
|
||||
Here is an example bash command using the Gravity provider:
|
||||
|
||||
```bash
|
||||
GRAVITY_SERVER_URL="https://example.org:1234" \
|
||||
GRAVITY_USERNAME="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
GRAVITY_PASSWORD="yyyyyyyyyyyyyyyyyyyyy" \
|
||||
lego --email you@example.com --dns gravity -d '*.example.com' -d example.com run
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
## Credentials
|
||||
|
||||
| Environment Variable Name | Description |
|
||||
|-----------------------|-------------|
|
||||
| `GRAVITY_PASSWORD` | Password |
|
||||
| `GRAVITY_SERVER_URL` | URL of the server |
|
||||
| `GRAVITY_USERNAME` | Username |
|
||||
|
||||
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 |
|
||||
|--------------------------------|-------------|
|
||||
| `GRAVITY_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) |
|
||||
| `GRAVITY_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) |
|
||||
| `GRAVITY_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) |
|
||||
| `GRAVITY_SEQUENCE_INTERVAL` | Time between sequential requests in seconds (Default: 1) |
|
||||
|
||||
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://gravity.beryju.io/docs/api/reference/)
|
||||
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
<!-- providers/dns/gravity/gravity.toml -->
|
||||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
|
||||
2
docs/data/zz_cli_help.toml
generated
2
docs/data/zz_cli_help.toml
generated
@@ -152,7 +152,7 @@ To display the documentation for a specific DNS provider, run:
|
||||
$ lego dnshelp -c code
|
||||
|
||||
Supported DNS providers:
|
||||
acme-dns, active24, alidns, aliesa, allinkl, anexia, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, beget, binarylane, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgecenter, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, gigahostno, glesys, godaddy, googledomains, hetzner, hostingde, hostinger, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, keyhelp, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, octenium, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, uniteddomains, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, webnamesca, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
|
||||
acme-dns, active24, alidns, aliesa, allinkl, anexia, arvancloud, auroradns, autodns, axelname, azion, azure, azuredns, baiducloud, beget, binarylane, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, conohav3, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dyndnsfree, dynu, easydns, edgecenter, edgedns, edgeone, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, gigahostno, glesys, godaddy, googledomains, gravity, hetzner, hostingde, hostinger, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, keyhelp, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nicru, nifcloud, njalla, nodion, ns1, octenium, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, uniteddomains, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, webnamesca, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneedit, zoneee, zonomi
|
||||
|
||||
More information: https://go-acme.github.io/lego/dns
|
||||
"""
|
||||
|
||||
2
go.mod
2
go.mod
@@ -38,6 +38,7 @@ require (
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0
|
||||
github.com/google/go-cmp v0.7.0
|
||||
github.com/google/go-querystring v1.1.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gophercloud/gophercloud v1.14.1
|
||||
github.com/gophercloud/utils v0.0.0-20231010081019-80377eca5d56
|
||||
github.com/hashicorp/go-retryablehttp v0.7.8
|
||||
@@ -157,7 +158,6 @@ require (
|
||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/s2a-go v0.1.9 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.7 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
|
||||
205
providers/dns/gravity/gravity.go
Normal file
205
providers/dns/gravity/gravity.go
Normal file
@@ -0,0 +1,205 @@
|
||||
// Package gravity implements a DNS provider for solving the DNS-01 challenge using Gravity.
|
||||
package gravity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/platform/config/env"
|
||||
"github.com/go-acme/lego/v4/providers/dns/gravity/internal"
|
||||
"github.com/go-acme/lego/v4/providers/dns/internal/clientdebug"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Environment variables names.
|
||||
const (
|
||||
envNamespace = "GRAVITY_"
|
||||
|
||||
EnvUsername = envNamespace + "USERNAME"
|
||||
EnvPassword = envNamespace + "PASSWORD"
|
||||
EnvServerURL = envNamespace + "SERVER_URL"
|
||||
|
||||
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
|
||||
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
|
||||
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
|
||||
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
|
||||
)
|
||||
|
||||
// Config is used to configure the creation of the DNSProvider.
|
||||
type Config struct {
|
||||
Username string
|
||||
Password string
|
||||
ServerURL string
|
||||
|
||||
PropagationTimeout time.Duration
|
||||
PollingInterval time.Duration
|
||||
SequenceInterval time.Duration
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// NewDefaultConfig returns a default configuration for the DNSProvider.
|
||||
func NewDefaultConfig() *Config {
|
||||
return &Config{
|
||||
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
|
||||
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
|
||||
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, 1*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
|
||||
|
||||
records map[string]internal.Record
|
||||
recordsMu sync.Mutex
|
||||
}
|
||||
|
||||
// NewDNSProvider returns a DNSProvider instance configured for Gravity.
|
||||
func NewDNSProvider() (*DNSProvider, error) {
|
||||
values, err := env.Get(EnvUsername, EnvPassword, EnvServerURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gravity: %w", err)
|
||||
}
|
||||
|
||||
config := NewDefaultConfig()
|
||||
config.Username = values[EnvUsername]
|
||||
config.Password = values[EnvPassword]
|
||||
config.ServerURL = values[EnvServerURL]
|
||||
|
||||
return NewDNSProviderConfig(config)
|
||||
}
|
||||
|
||||
// NewDNSProviderConfig return a DNSProvider instance configured for Gravity.
|
||||
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("gravity: the configuration of the DNS provider is nil")
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(config.ServerURL, config.Username, config.Password)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gravity: %w", err)
|
||||
}
|
||||
|
||||
if config.HTTPClient != nil {
|
||||
client.HTTPClient = config.HTTPClient
|
||||
}
|
||||
|
||||
client.HTTPClient = clientdebug.Wrap(client.HTTPClient)
|
||||
|
||||
return &DNSProvider{
|
||||
config: config,
|
||||
client: client,
|
||||
records: make(map[string]internal.Record),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
_, err := d.client.Login(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gravity: login: %w", err)
|
||||
}
|
||||
|
||||
zone, err := d.findZone(ctx, info.EffectiveFQDN)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gravity: %w", err)
|
||||
}
|
||||
|
||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, zone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gravity: %w", err)
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
record := internal.Record{
|
||||
Data: info.Value,
|
||||
Hostname: subDomain,
|
||||
Type: "TXT",
|
||||
UID: id.String(),
|
||||
}
|
||||
|
||||
err = d.client.CreateDNSRecord(ctx, zone, record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gravity: create DNS record: %w", err)
|
||||
}
|
||||
|
||||
d.recordsMu.Lock()
|
||||
|
||||
record.Fqdn = zone
|
||||
d.records[token] = record
|
||||
d.recordsMu.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanUp removes the TXT record matching the specified parameters.
|
||||
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||
info := dns01.GetChallengeInfo(domain, keyAuth)
|
||||
|
||||
d.recordsMu.Lock()
|
||||
record, ok := d.records[token]
|
||||
d.recordsMu.Unlock()
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("gravity: unknown record for '%s' '%s'", info.EffectiveFQDN, token)
|
||||
}
|
||||
|
||||
err := d.client.DeleteDNSRecord(context.Background(), record.Fqdn, record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("gravity: delete record: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Timeout returns the timeout and interval to use when checking for DNS propagation.
|
||||
// Adjusting here to cope with spikes in propagation times.
|
||||
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
||||
return d.config.PropagationTimeout, d.config.PollingInterval
|
||||
}
|
||||
|
||||
// Sequential implements the [dns01.sequential] interface.
|
||||
// It changes the behavior of the provider to resolve DNS challenges sequentially.
|
||||
// Returns the interval between each iteration.
|
||||
//
|
||||
// Gravity supports adding multiple records for the same domain, but the DNS server doesn't work as expected:
|
||||
// if you call the DNS server, it will answer only the latest record instead of all of them.
|
||||
func (d *DNSProvider) Sequential() time.Duration {
|
||||
return d.config.SequenceInterval
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findZone(ctx context.Context, effectiveFQDN string) (string, error) {
|
||||
var zone string
|
||||
|
||||
for fqdn := range dns01.DomainsSeq(effectiveFQDN) {
|
||||
zones, err := d.client.GetDNSZones(ctx, fqdn)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("get DNS zones: %w", err)
|
||||
}
|
||||
|
||||
if len(zones) != 0 {
|
||||
zone = zones[0].Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if zone == "" {
|
||||
return "", fmt.Errorf("could not find zone for %q", effectiveFQDN)
|
||||
}
|
||||
|
||||
return zone, nil
|
||||
}
|
||||
26
providers/dns/gravity/gravity.toml
Normal file
26
providers/dns/gravity/gravity.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
Name = "Gravity"
|
||||
Description = ''''''
|
||||
URL = "https://gravity.beryju.io/"
|
||||
Code = "gravity"
|
||||
Since = "v4.30.0"
|
||||
|
||||
Example = '''
|
||||
GRAVITY_SERVER_URL="https://example.org:1234" \
|
||||
GRAVITY_USERNAME="xxxxxxxxxxxxxxxxxxxxx" \
|
||||
GRAVITY_PASSWORD="yyyyyyyyyyyyyyyyyyyyy" \
|
||||
lego --email you@example.com --dns gravity -d '*.example.com' -d example.com run
|
||||
'''
|
||||
|
||||
[Configuration]
|
||||
[Configuration.Credentials]
|
||||
GRAVITY_SERVER_URL = "URL of the server"
|
||||
GRAVITY_USERNAME = "Username"
|
||||
GRAVITY_PASSWORD = "Password"
|
||||
[Configuration.Additional]
|
||||
GRAVITY_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)"
|
||||
GRAVITY_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)"
|
||||
GRAVITY_SEQUENCE_INTERVAL = "Time between sequential requests in seconds (Default: 1)"
|
||||
GRAVITY_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)"
|
||||
|
||||
[Links]
|
||||
API = "https://gravity.beryju.io/docs/api/reference/"
|
||||
254
providers/dns/gravity/gravity_test.go
Normal file
254
providers/dns/gravity/gravity_test.go
Normal file
@@ -0,0 +1,254 @@
|
||||
package gravity
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/platform/tester"
|
||||
"github.com/go-acme/lego/v4/platform/tester/servermock"
|
||||
"github.com/go-acme/lego/v4/providers/dns/gravity/internal"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const envDomain = envNamespace + "DOMAIN"
|
||||
|
||||
var envTest = tester.NewEnvTest(
|
||||
EnvUsername,
|
||||
EnvPassword,
|
||||
EnvServerURL,
|
||||
).WithDomain(envDomain)
|
||||
|
||||
func TestNewDNSProvider(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
envVars map[string]string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "success",
|
||||
envVars: map[string]string{
|
||||
EnvUsername: "user",
|
||||
EnvPassword: "secret",
|
||||
EnvServerURL: "https://example.org:1234",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing EnvUsername",
|
||||
envVars: map[string]string{
|
||||
EnvUsername: "",
|
||||
EnvPassword: "secret",
|
||||
EnvServerURL: "https://example.org:1234",
|
||||
},
|
||||
expected: "gravity: some credentials information are missing: GRAVITY_USERNAME",
|
||||
},
|
||||
{
|
||||
desc: "missing EnvPassword",
|
||||
envVars: map[string]string{
|
||||
EnvUsername: "user",
|
||||
EnvPassword: "",
|
||||
EnvServerURL: "https://example.org:1234",
|
||||
},
|
||||
expected: "gravity: some credentials information are missing: GRAVITY_PASSWORD",
|
||||
},
|
||||
{
|
||||
desc: "missing EnvServerURL",
|
||||
envVars: map[string]string{
|
||||
EnvUsername: "user",
|
||||
EnvPassword: "secret",
|
||||
EnvServerURL: "",
|
||||
},
|
||||
expected: "gravity: some credentials information are missing: GRAVITY_SERVER_URL",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
envVars: map[string]string{},
|
||||
expected: "gravity: some credentials information are missing: GRAVITY_USERNAME,GRAVITY_PASSWORD,GRAVITY_SERVER_URL",
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
username string
|
||||
password string
|
||||
serverURL string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
desc: "success",
|
||||
username: "user",
|
||||
password: "secret",
|
||||
serverURL: "https://example.org:1234",
|
||||
},
|
||||
{
|
||||
desc: "missing username",
|
||||
username: "",
|
||||
password: "secret",
|
||||
serverURL: "https://example.org:1234",
|
||||
expected: "gravity: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing password",
|
||||
username: "user",
|
||||
password: "",
|
||||
serverURL: "https://example.org:1234",
|
||||
expected: "gravity: credentials missing",
|
||||
},
|
||||
{
|
||||
desc: "missing server URL",
|
||||
username: "user",
|
||||
password: "secret",
|
||||
serverURL: "",
|
||||
expected: "gravity: server URL missing",
|
||||
},
|
||||
{
|
||||
desc: "missing credentials",
|
||||
expected: "gravity: credentials missing",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := NewDefaultConfig()
|
||||
config.Username = test.username
|
||||
config.Password = test.password
|
||||
config.ServerURL = test.serverURL
|
||||
|
||||
p, err := NewDNSProviderConfig(config)
|
||||
|
||||
if test.expected == "" {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
require.NotNil(t, p.config)
|
||||
require.NotNil(t, p.client)
|
||||
} else {
|
||||
require.EqualError(t, err, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLivePresent(t *testing.T) {
|
||||
if !envTest.IsLiveTest() {
|
||||
t.Skip("skipping live test")
|
||||
}
|
||||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = provider.Present(envTest.GetDomain(), "", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLiveCleanUp(t *testing.T) {
|
||||
if !envTest.IsLiveTest() {
|
||||
t.Skip("skipping live test")
|
||||
}
|
||||
|
||||
envTest.RestoreEnv()
|
||||
|
||||
provider, err := NewDNSProvider()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func mockBuilder() *servermock.Builder[*DNSProvider] {
|
||||
return servermock.NewBuilder(
|
||||
func(server *httptest.Server) (*DNSProvider, error) {
|
||||
config := NewDefaultConfig()
|
||||
|
||||
config.Username = "user"
|
||||
config.Password = "secret"
|
||||
config.ServerURL = server.URL
|
||||
|
||||
config.HTTPClient = server.Client()
|
||||
|
||||
p, err := NewDNSProviderConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p, nil
|
||||
},
|
||||
servermock.CheckHeader().
|
||||
WithJSONHeaders(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestDNSProvider_Present(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("POST /api/v1/auth/login",
|
||||
servermock.ResponseFromInternal("login.json"),
|
||||
servermock.CheckRequestJSONBodyFromInternal("login-request.json")).
|
||||
Route("GET /api/v1/dns/",
|
||||
http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.Query().Get("name") != "example.com." {
|
||||
servermock.ResponseFromInternal("zones.json").ServeHTTP(rw, req)
|
||||
return
|
||||
}
|
||||
|
||||
servermock.ResponseFromInternal("zones_empty.json").ServeHTTP(rw, req)
|
||||
}),
|
||||
).
|
||||
Route("POST /api/v1/dns/zones/records",
|
||||
servermock.Noop().
|
||||
WithStatusCode(http.StatusNoContent),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("zone", "example.com.").
|
||||
WithRegexp("uid", `\w{8}-\w{4}-\w{4}-\w{4}-\w{12}`).
|
||||
With("hostname", "_acme-challenge")).
|
||||
Build(t)
|
||||
|
||||
err := provider.Present("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("DELETE /api/v1/dns/zones/records",
|
||||
servermock.Noop().
|
||||
WithStatusCode(http.StatusNoContent),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("zone", "example.com.").
|
||||
With("uid", "123").
|
||||
With("type", "TXT").
|
||||
With("hostname", "_acme-challenge")).
|
||||
Build(t)
|
||||
|
||||
provider.records["abc"] = internal.Record{
|
||||
Fqdn: "example.com.",
|
||||
Hostname: "_acme-challenge",
|
||||
Type: "TXT",
|
||||
UID: "123",
|
||||
}
|
||||
|
||||
err := provider.CleanUp("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
234
providers/dns/gravity/internal/client.go
Normal file
234
providers/dns/gravity/internal/client.go
Normal file
@@ -0,0 +1,234 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
|
||||
"github.com/go-acme/lego/v4/providers/dns/internal/useragent"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
// Client the Gravity API client.
|
||||
type Client struct {
|
||||
username string
|
||||
password string
|
||||
|
||||
baseURL *url.URL
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new Client.
|
||||
func NewClient(serverURL, username, password string) (*Client, error) {
|
||||
if username == "" || password == "" {
|
||||
return nil, errors.New("credentials missing")
|
||||
}
|
||||
|
||||
if serverURL == "" {
|
||||
return nil, errors.New("server URL missing")
|
||||
}
|
||||
|
||||
baseURL, err := url.Parse(serverURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{
|
||||
username: username,
|
||||
password: password,
|
||||
baseURL: baseURL,
|
||||
HTTPClient: &http.Client{Timeout: 10 * time.Second},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Login(ctx context.Context) (*Auth, error) {
|
||||
jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.HTTPClient.Jar = jar
|
||||
|
||||
login := Login{
|
||||
Username: c.username,
|
||||
Password: c.password,
|
||||
}
|
||||
|
||||
endpoint := c.baseURL.JoinPath("api", "v1", "auth", "login")
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, login)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &Auth{}
|
||||
|
||||
err = c.do(req, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *Client) Me(ctx context.Context) (*UserInfo, error) {
|
||||
endpoint := c.baseURL.JoinPath("api", "v1", "auth", "me")
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &UserInfo{}
|
||||
|
||||
err = c.do(req, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (c *Client) GetDNSZones(ctx context.Context, name string) ([]Zone, error) {
|
||||
endpoint := c.baseURL.JoinPath("api", "v1", "dns", "zones")
|
||||
|
||||
if name != "" {
|
||||
query := endpoint.Query()
|
||||
query.Set("name", name)
|
||||
endpoint.RawQuery = query.Encode()
|
||||
}
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := Zones{}
|
||||
|
||||
err = c.do(req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Zones, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateDNSRecord(ctx context.Context, zone string, record Record) error {
|
||||
endpoint := c.baseURL.JoinPath("api", "v1", "dns", "zones", "records")
|
||||
|
||||
query := endpoint.Query()
|
||||
|
||||
query.Set("zone", zone)
|
||||
query.Set("hostname", record.Hostname)
|
||||
|
||||
// When the UID is the same as an existing one, the record is updated, else a new record is created.
|
||||
// An explicit UID is not required to create a record.
|
||||
if record.UID != "" {
|
||||
query.Set("uid", record.UID)
|
||||
}
|
||||
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodPost, endpoint, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.do(req, nil)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteDNSRecord(ctx context.Context, zone string, record Record) error {
|
||||
endpoint := c.baseURL.JoinPath("api", "v1", "dns", "zones", "records")
|
||||
|
||||
query := endpoint.Query()
|
||||
|
||||
query.Set("zone", zone)
|
||||
query.Set("hostname", record.Hostname)
|
||||
query.Set("uid", record.UID)
|
||||
query.Set("type", record.Type)
|
||||
|
||||
endpoint.RawQuery = query.Encode()
|
||||
|
||||
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.do(req, nil)
|
||||
}
|
||||
|
||||
func (c *Client) do(req *http.Request, result any) error {
|
||||
useragent.SetHeader(req.Header)
|
||||
|
||||
resp, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return errutils.NewHTTPDoError(req, err)
|
||||
}
|
||||
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
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
|
||||
}
|
||||
160
providers/dns/gravity/internal/client_test.go
Normal file
160
providers/dns/gravity/internal/client_test.go
Normal file
@@ -0,0 +1,160 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/go-acme/lego/v4/platform/tester/servermock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func mockBuilder() *servermock.Builder[*Client] {
|
||||
return servermock.NewBuilder[*Client](
|
||||
func(server *httptest.Server) (*Client, error) {
|
||||
client, err := NewClient(server.URL, "user", "secret")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client.HTTPClient = server.Client()
|
||||
|
||||
return client, nil
|
||||
},
|
||||
servermock.CheckHeader().
|
||||
WithJSONHeaders(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestClient_Login(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("POST /api/v1/auth/login",
|
||||
http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
http.SetCookie(rw, &http.Cookie{
|
||||
Name: "gravity_session",
|
||||
Value: "session_id",
|
||||
Path: "/",
|
||||
})
|
||||
|
||||
servermock.ResponseFromFixture("login.json").ServeHTTP(rw, req)
|
||||
}),
|
||||
servermock.CheckRequestJSONBodyFromFixture("login-request.json")).
|
||||
Build(t)
|
||||
|
||||
auth, err := client.Login(t.Context())
|
||||
require.NoError(t, err)
|
||||
|
||||
cookies := client.HTTPClient.Jar.Cookies(client.baseURL)
|
||||
|
||||
require.Len(t, cookies, 1)
|
||||
|
||||
assert.Equal(t, "gravity_session", cookies[0].Name)
|
||||
assert.Equal(t, "session_id", cookies[0].Value)
|
||||
|
||||
expected := &Auth{Successful: true}
|
||||
|
||||
assert.Equal(t, expected, auth)
|
||||
}
|
||||
|
||||
func TestClient_Login_error(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("POST /api/v1/auth/login",
|
||||
servermock.ResponseFromFixture("error.json").
|
||||
WithStatusCode(http.StatusUnauthorized)).
|
||||
Build(t)
|
||||
|
||||
_, err := client.Login(t.Context())
|
||||
require.EqualError(t, err, "status: UNAUTHENTICATED, error: unauthenticated, additionalProp1: string")
|
||||
}
|
||||
|
||||
func TestClient_Me(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("GET /api/v1/auth/me",
|
||||
servermock.ResponseFromFixture("me.json")).
|
||||
Build(t)
|
||||
|
||||
info, err := client.Me(t.Context())
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := &UserInfo{
|
||||
Username: "admin",
|
||||
Authenticated: true,
|
||||
Permissions: []Permission{{
|
||||
Methods: []string{"GET", "POST", "PUT", "HEAD", "DELETE"},
|
||||
Path: "/*",
|
||||
}},
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, info)
|
||||
}
|
||||
|
||||
func TestClient_GetDNSZones(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("GET /api/v1/dns/",
|
||||
servermock.ResponseFromFixture("zones.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("name", "example.com.")).
|
||||
Build(t)
|
||||
|
||||
zones, err := client.GetDNSZones(t.Context(), "example.com.")
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []Zone{{
|
||||
Name: "example.com.",
|
||||
HandlerConfigs: []HandlerConfig{
|
||||
{Type: "memory"},
|
||||
{Type: "etcd"},
|
||||
},
|
||||
DefaultTTL: 86400,
|
||||
RecordCount: 1,
|
||||
}}
|
||||
|
||||
assert.Equal(t, expected, zones)
|
||||
}
|
||||
|
||||
func TestClient_CreateDNSRecord(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("POST /api/v1/dns/zones/records",
|
||||
servermock.Noop().
|
||||
WithStatusCode(http.StatusNoContent),
|
||||
servermock.CheckRequestJSONBodyFromFixture("create_record-request.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("zone", "example.com.").
|
||||
With("uid", "123").
|
||||
With("hostname", "_acme-challenge")).
|
||||
Build(t)
|
||||
|
||||
record := Record{
|
||||
Data: "txtTXTtxt",
|
||||
Hostname: "_acme-challenge",
|
||||
Type: "TXT",
|
||||
UID: "123",
|
||||
}
|
||||
|
||||
err := client.CreateDNSRecord(t.Context(), "example.com.", record)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestClient_DeleteDNSRecord(t *testing.T) {
|
||||
client := mockBuilder().
|
||||
Route("DELETE /api/v1/dns/zones/records",
|
||||
servermock.Noop().
|
||||
WithStatusCode(http.StatusNoContent),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("zone", "example.com.").
|
||||
With("uid", "123").
|
||||
With("type", "TXT").
|
||||
With("hostname", "_acme-challenge")).
|
||||
Build(t)
|
||||
|
||||
record := Record{
|
||||
Data: "txtTXTtxt",
|
||||
Hostname: "_acme-challenge",
|
||||
Type: "TXT",
|
||||
UID: "123",
|
||||
}
|
||||
|
||||
err := client.DeleteDNSRecord(t.Context(), "example.com.", record)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"data": "txtTXTtxt",
|
||||
"hostname": "_acme-challenge",
|
||||
"type": "TXT",
|
||||
"uid": "123"
|
||||
}
|
||||
8
providers/dns/gravity/internal/fixtures/error.json
Normal file
8
providers/dns/gravity/internal/fixtures/error.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"code": 0,
|
||||
"context": {
|
||||
"additionalProp1": "string"
|
||||
},
|
||||
"error": "unauthenticated",
|
||||
"status": "UNAUTHENTICATED"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"username": "user",
|
||||
"password": "secret"
|
||||
}
|
||||
3
providers/dns/gravity/internal/fixtures/login.json
Normal file
3
providers/dns/gravity/internal/fixtures/login.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"successful": true
|
||||
}
|
||||
16
providers/dns/gravity/internal/fixtures/me.json
Normal file
16
providers/dns/gravity/internal/fixtures/me.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"username": "admin",
|
||||
"authenticated": true,
|
||||
"permissions": [
|
||||
{
|
||||
"path": "/*",
|
||||
"methods": [
|
||||
"GET",
|
||||
"POST",
|
||||
"PUT",
|
||||
"HEAD",
|
||||
"DELETE"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"username": "",
|
||||
"authenticated": false,
|
||||
"permissions": null
|
||||
}
|
||||
19
providers/dns/gravity/internal/fixtures/zones.json
Normal file
19
providers/dns/gravity/internal/fixtures/zones.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"zones": [
|
||||
{
|
||||
"name": "example.com.",
|
||||
"handlerConfigs": [
|
||||
{
|
||||
"type": "memory"
|
||||
},
|
||||
{
|
||||
"type": "etcd"
|
||||
}
|
||||
],
|
||||
"defaultTTL": 86400,
|
||||
"authoritative": false,
|
||||
"hook": "",
|
||||
"recordCount": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
3
providers/dns/gravity/internal/fixtures/zones_empty.json
Normal file
3
providers/dns/gravity/internal/fixtures/zones_empty.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"zones": null
|
||||
}
|
||||
82
providers/dns/gravity/internal/types.go
Normal file
82
providers/dns/gravity/internal/types.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
Status string `json:"status"`
|
||||
ErrorMsg string `json:"error"`
|
||||
Code int `json:"code"`
|
||||
Context map[string]string `json:"context"`
|
||||
}
|
||||
|
||||
func (a *APIError) Error() string {
|
||||
var msg strings.Builder
|
||||
|
||||
msg.WriteString(fmt.Sprintf("status: %s, error: %s", a.Status, a.ErrorMsg))
|
||||
|
||||
if a.Code != 0 {
|
||||
msg.WriteString(fmt.Sprintf(", code: %d", a.Code))
|
||||
}
|
||||
|
||||
if len(a.Context) != 0 {
|
||||
for k, v := range a.Context {
|
||||
msg.WriteString(fmt.Sprintf(", %s: %s", k, v))
|
||||
}
|
||||
}
|
||||
|
||||
return msg.String()
|
||||
}
|
||||
|
||||
type Login struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
Successful bool `json:"successful"`
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
Username string `json:"username"`
|
||||
Authenticated bool `json:"authenticated"`
|
||||
Permissions []Permission `json:"permissions"`
|
||||
}
|
||||
|
||||
type Permission struct {
|
||||
Methods []string `json:"methods"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type Zones struct {
|
||||
Zones []Zone `json:"zones"`
|
||||
}
|
||||
|
||||
type Zone struct {
|
||||
Name string `json:"name"`
|
||||
HandlerConfigs []HandlerConfig `json:"handlerConfigs"`
|
||||
DefaultTTL int `json:"defaultTTL"`
|
||||
Authoritative bool `json:"authoritative"`
|
||||
Hook string `json:"hook"`
|
||||
RecordCount int `json:"recordCount"`
|
||||
}
|
||||
|
||||
type HandlerConfig struct {
|
||||
Type string `json:"type"`
|
||||
CacheTTL int `json:"cache_ttl,omitempty"`
|
||||
To []string `json:"to,omitempty"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
Data string `json:"data,omitempty"`
|
||||
Fqdn string `json:"fqdn,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
MxPreference int `json:"mxPreference,omitempty"`
|
||||
SrvPort int `json:"srvPort,omitempty"`
|
||||
SrvPriority int `json:"srvPriority,omitempty"`
|
||||
SrvWeight int `json:"srvWeight,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
UID string `json:"uid,omitempty"`
|
||||
}
|
||||
3
providers/dns/zz_gen_dns_providers.go
generated
3
providers/dns/zz_gen_dns_providers.go
generated
@@ -73,6 +73,7 @@ import (
|
||||
"github.com/go-acme/lego/v4/providers/dns/glesys"
|
||||
"github.com/go-acme/lego/v4/providers/dns/godaddy"
|
||||
"github.com/go-acme/lego/v4/providers/dns/googledomains"
|
||||
"github.com/go-acme/lego/v4/providers/dns/gravity"
|
||||
"github.com/go-acme/lego/v4/providers/dns/hetzner"
|
||||
"github.com/go-acme/lego/v4/providers/dns/hostingde"
|
||||
"github.com/go-acme/lego/v4/providers/dns/hostinger"
|
||||
@@ -315,6 +316,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
||||
return godaddy.NewDNSProvider()
|
||||
case "googledomains":
|
||||
return googledomains.NewDNSProvider()
|
||||
case "gravity":
|
||||
return gravity.NewDNSProvider()
|
||||
case "hetzner":
|
||||
return hetzner.NewDNSProvider()
|
||||
case "hostingde":
|
||||
|
||||
Reference in New Issue
Block a user