From 4675ef7d9afb1a5d508755d3e6f946d654b23e3c Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 3 Mar 2025 18:01:11 +0100 Subject: [PATCH] Add DNS provider for F5 XC (#2409) --- README.md | 54 ++--- cmd/zz_gen_cmd_dnshelp.go | 23 ++ docs/content/dns/zz_gen_f5xc.md | 71 ++++++ docs/data/zz_cli_help.toml | 2 +- providers/dns/f5xc/f5xc.go | 180 ++++++++++++++ providers/dns/f5xc/f5xc.toml | 27 +++ providers/dns/f5xc/f5xc_test.go | 166 +++++++++++++ providers/dns/f5xc/internal/client.go | 210 +++++++++++++++++ providers/dns/f5xc/internal/client_test.go | 219 ++++++++++++++++++ .../dns/f5xc/internal/fixtures/create.json | 204 ++++++++++++++++ .../dns/f5xc/internal/fixtures/delete.json | 207 +++++++++++++++++ .../dns/f5xc/internal/fixtures/error_404.json | 5 + .../dns/f5xc/internal/fixtures/error_503.json | 5 + providers/dns/f5xc/internal/fixtures/get.json | 207 +++++++++++++++++ .../dns/f5xc/internal/fixtures/replace.json | 206 ++++++++++++++++ providers/dns/f5xc/internal/types.go | 48 ++++ providers/dns/zz_gen_dns_providers.go | 3 + 17 files changed, 1809 insertions(+), 28 deletions(-) create mode 100644 docs/content/dns/zz_gen_f5xc.md create mode 100644 providers/dns/f5xc/f5xc.go create mode 100644 providers/dns/f5xc/f5xc.toml create mode 100644 providers/dns/f5xc/f5xc_test.go create mode 100644 providers/dns/f5xc/internal/client.go create mode 100644 providers/dns/f5xc/internal/client_test.go create mode 100644 providers/dns/f5xc/internal/fixtures/create.json create mode 100644 providers/dns/f5xc/internal/fixtures/delete.json create mode 100644 providers/dns/f5xc/internal/fixtures/error_404.json create mode 100644 providers/dns/f5xc/internal/fixtures/error_503.json create mode 100644 providers/dns/f5xc/internal/fixtures/get.json create mode 100644 providers/dns/f5xc/internal/fixtures/replace.json create mode 100644 providers/dns/f5xc/internal/types.go diff --git a/README.md b/README.md index 844a0fa66..80eed622f 100644 --- a/README.md +++ b/README.md @@ -110,138 +110,138 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns). Exoscale External program + F5 XC freemyip.com - G-Core + G-Core Gandi Gandi Live DNS (v5) Glesys - Go Daddy + Go Daddy Google Cloud Google Domains Hetzner - Hosting.de + Hosting.de Hosttech HTTP request http.net - Huawei Cloud + Huawei Cloud Hurricane Electric DNS HyperOne IBM Cloud (SoftLayer) - IIJ DNS Platform Service + IIJ DNS Platform Service Infoblox Infomaniak Internet Initiative Japan - Internet.bs + Internet.bs INWX Ionos IPv64 - iwantmyname + iwantmyname Joker Joohoi's ACME-DNS Liara - Lima-City + Lima-City Linode (v4) Liquid Web Loopia - LuaDNS + LuaDNS Mail-in-a-Box ManageEngine CloudDNS Manual - Metaname + Metaname Metaregistrar mijn.host Mittwald - myaddr.{tools,dev,io} + myaddr.{tools,dev,io} MyDNS.jp MythicBeasts Name.com - Namecheap + Namecheap Namesilo NearlyFreeSpeech.NET Netcup - Netlify + Netlify Nicmanager NIFCloud Njalla - Nodion + Nodion NS1 Open Telekom Cloud Oracle Cloud - OVH + OVH plesk.com Porkbun PowerDNS - Rackspace + Rackspace Rain Yun/雨云 RcodeZero reg.ru - Regfish + Regfish RFC2136 RimuHosting Sakura Cloud - Scaleway + Scaleway Selectel Selectel v2 SelfHost.(de|eu) - Servercow + Servercow Shellrent Simply.com Sonic - Spaceship + Spaceship Stackpath Technitium Tencent Cloud DNS - Timeweb Cloud + Timeweb Cloud TransIP UKFast SafeDNS Ultradns - Variomedia + Variomedia VegaDNS Vercel Versio.[nl|eu|uk] - VinylDNS + VinylDNS VK Cloud Volcano Engine/火山引擎 Vscale - Vultr + Vultr Webnames Websupport WEDOS - West.cn/西部数码 + West.cn/西部数码 Yandex 360 Yandex Cloud Yandex PDD - Zone.ee + Zone.ee Zonomi - diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 3668f661c..80f9ab243 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -58,6 +58,7 @@ func allDNSCodes() string { "epik", "exec", "exoscale", + "f5xc", "freemyip", "gandi", "gandiv5", @@ -1148,6 +1149,28 @@ func displayDNSHelp(w io.Writer, name string) error { ew.writeln() ew.writeln(`More information: https://go-acme.github.io/lego/dns/exoscale`) + case "f5xc": + // generated from: providers/dns/f5xc/f5xc.toml + ew.writeln(`Configuration for F5 XC.`) + ew.writeln(`Code: 'f5xc'`) + ew.writeln(`Since: 'v4.23.0'`) + ew.writeln() + + ew.writeln(`Credentials:`) + ew.writeln(` - "F5XC_API_TOKEN": API token`) + ew.writeln(` - "F5XC_GROUP_NAME": Group name`) + ew.writeln(` - "F5XC_TENANT_NAME": XC Tenant shortname`) + ew.writeln() + + ew.writeln(`Additional Configuration:`) + ew.writeln(` - "F5XC_HTTP_TIMEOUT": API request timeout in seconds (Default: 30)`) + ew.writeln(` - "F5XC_POLLING_INTERVAL": Time between DNS propagation check in seconds (Default: 2)`) + ew.writeln(` - "F5XC_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation in seconds (Default: 60)`) + ew.writeln(` - "F5XC_TTL": The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)`) + + ew.writeln() + ew.writeln(`More information: https://go-acme.github.io/lego/dns/f5xc`) + case "freemyip": // generated from: providers/dns/freemyip/freemyip.toml ew.writeln(`Configuration for freemyip.com.`) diff --git a/docs/content/dns/zz_gen_f5xc.md b/docs/content/dns/zz_gen_f5xc.md new file mode 100644 index 000000000..c8a664a00 --- /dev/null +++ b/docs/content/dns/zz_gen_f5xc.md @@ -0,0 +1,71 @@ +--- +title: "F5 XC" +date: 2019-03-03T16:39:46+01:00 +draft: false +slug: f5xc +dnsprovider: + since: "v4.23.0" + code: "f5xc" + url: "https://www.f5.com/products/distributed-cloud-services" +--- + + + + + + +Configuration for [F5 XC](https://www.f5.com/products/distributed-cloud-services). + + + + +- Code: `f5xc` +- Since: v4.23.0 + + +Here is an example bash command using the F5 XC provider: + +```bash +F5XC_API_TOKEN="xxx" \ +F5XC_TENANT_NAME="yyy" \ +F5XC_GROUP_NAME="zzz" \ +lego --email you@example.com --dns f5xc -d '*.example.com' -d example.com run +``` + + + + +## Credentials + +| Environment Variable Name | Description | +|-----------------------|-------------| +| `F5XC_API_TOKEN` | API token | +| `F5XC_GROUP_NAME` | Group name | +| `F5XC_TENANT_NAME` | XC Tenant shortname | + +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 | +|--------------------------------|-------------| +| `F5XC_HTTP_TIMEOUT` | API request timeout in seconds (Default: 30) | +| `F5XC_POLLING_INTERVAL` | Time between DNS propagation check in seconds (Default: 2) | +| `F5XC_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation in seconds (Default: 60) | +| `F5XC_TTL` | The TTL of the TXT record used for the DNS challenge in seconds (Default: 120) | + +The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. +More information [here]({{% ref "dns#configuration-and-credentials" %}}). + + + + +## More information + +- [API documentation](https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset) + + + + diff --git a/docs/data/zz_cli_help.toml b/docs/data/zz_cli_help.toml index aff8766a2..1cbfdbf4e 100644 --- a/docs/data/zz_cli_help.toml +++ b/docs/data/zz_cli_help.toml @@ -149,7 +149,7 @@ To display the documentation for a specific DNS provider, run: $ lego dnshelp -c code Supported DNS providers: - acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi + acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, bookmyname, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, f5xc, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, metaregistrar, mijnhost, mittwald, myaddr, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, spaceship, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi More information: https://go-acme.github.io/lego/dns """ diff --git a/providers/dns/f5xc/f5xc.go b/providers/dns/f5xc/f5xc.go new file mode 100644 index 000000000..2ed1f0c4f --- /dev/null +++ b/providers/dns/f5xc/f5xc.go @@ -0,0 +1,180 @@ +// Package f5xc implements a DNS provider for solving the DNS-01 challenge using F5 XC. +package f5xc + +import ( + "context" + "errors" + "fmt" + "net/http" + "time" + + "github.com/go-acme/lego/v4/challenge/dns01" + "github.com/go-acme/lego/v4/platform/config/env" + "github.com/go-acme/lego/v4/platform/wait" + "github.com/go-acme/lego/v4/providers/dns/f5xc/internal" +) + +// Environment variables names. +const ( + envNamespace = "F5XC_" + + EnvToken = envNamespace + "API_TOKEN" + EnvTenantName = envNamespace + "TENANT_NAME" + EnvGroupName = envNamespace + "GROUP_NAME" + + EnvTTL = envNamespace + "TTL" + EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT" + EnvPollingInterval = envNamespace + "POLLING_INTERVAL" + EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT" +) + +// Config is used to configure the creation of the DNSProvider. +type Config struct { + APIToken string + TenantName string + GroupName string + + PropagationTimeout time.Duration + PollingInterval time.Duration + TTL int + HTTPClient *http.Client +} + +// NewDefaultConfig returns a default configuration for the DNSProvider. +func NewDefaultConfig() *Config { + return &Config{ + TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL), + PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout), + PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval), + HTTPClient: &http.Client{ + Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second), + }, + } +} + +// DNSProvider implements the challenge.Provider interface. +type DNSProvider struct { + config *Config + client *internal.Client +} + +// NewDNSProvider returns a DNSProvider instance configured for F5 XC. +func NewDNSProvider() (*DNSProvider, error) { + values, err := env.Get(EnvToken, EnvTenantName, EnvGroupName) + if err != nil { + return nil, fmt.Errorf("f5xc: %w", err) + } + + config := NewDefaultConfig() + config.APIToken = values[EnvToken] + config.TenantName = values[EnvTenantName] + config.GroupName = values[EnvGroupName] + + return NewDNSProviderConfig(config) +} + +// NewDNSProviderConfig return a DNSProvider instance configured for F5 XC. +func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { + if config == nil { + return nil, errors.New("f5xc: the configuration of the DNS provider is nil") + } + + if config.GroupName == "" { + return nil, errors.New("f5xc: missing group name") + } + + client, err := internal.NewClient(config.APIToken, config.TenantName) + if err != nil { + return nil, fmt.Errorf("f5xc: %w", err) + } + + if config.HTTPClient != nil { + client.HTTPClient = config.HTTPClient + } + + return &DNSProvider{ + config: config, + client: client, + }, nil +} + +// Present creates a TXT record using the specified parameters. +func (d *DNSProvider) Present(domain, token, keyAuth string) error { + info := dns01.GetChallengeInfo(domain, keyAuth) + + authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("f5xc: could not find zone for domain %q: %w", domain, err) + } + + subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone) + if err != nil { + return fmt.Errorf("f5xc: %w", err) + } + + existingRRSet, err := d.client.GetRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, subDomain, "TXT") + if err != nil { + return fmt.Errorf("f5xc: get RR Set: %w", err) + } + + // New RRSet. + if existingRRSet == nil || existingRRSet.RRSet.TXTRecord == nil { + rrSet := internal.RRSet{ + Description: "lego", + TTL: d.config.TTL, + TXTRecord: &internal.TXTRecord{ + Name: subDomain, + Values: []string{info.Value}, + }, + } + + return wait.For("f5xc create", 60*time.Second, 2*time.Second, func() (bool, error) { + _, err = d.client.CreateRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, rrSet) + if err != nil { + return false, fmt.Errorf("f5xc: create RR set: %w", err) + } + + return true, nil + }) + } + + // Update RRSet. + existingRRSet.RRSet.TXTRecord.Values = append(existingRRSet.RRSet.TXTRecord.Values, info.Value) + + return wait.For("f5xc replace", 60*time.Second, 2*time.Second, func() (bool, error) { + _, err = d.client.ReplaceRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, subDomain, "TXT", existingRRSet.RRSet) + if err != nil { + return false, fmt.Errorf("f5xc: replace RR set: %w", err) + } + + return true, nil + }) +} + +// CleanUp removes the TXT record matching the specified parameters. +func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { + info := dns01.GetChallengeInfo(domain, keyAuth) + + authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("f5xc: could not find zone for domain %q: %w", domain, err) + } + + subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone) + if err != nil { + return fmt.Errorf("f5xc: %w", err) + } + + _, err = d.client.DeleteRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, subDomain, "TXT") + if err != nil { + return fmt.Errorf("f5xc: delete RR set: %w", err) + } + + return nil +} + +// Timeout returns the timeout and interval to use when checking for DNS propagation. +// Adjusting here to cope with spikes in propagation times. +func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { + return d.config.PropagationTimeout, d.config.PollingInterval +} diff --git a/providers/dns/f5xc/f5xc.toml b/providers/dns/f5xc/f5xc.toml new file mode 100644 index 000000000..7a4cab419 --- /dev/null +++ b/providers/dns/f5xc/f5xc.toml @@ -0,0 +1,27 @@ +Name = "F5 XC" +Description = '''''' +URL = "https://www.f5.com/products/distributed-cloud-services" +Code = "f5xc" +Since = "v4.23.0" + +Example = ''' +F5XC_API_TOKEN="xxx" \ +F5XC_TENANT_NAME="yyy" \ +F5XC_GROUP_NAME="zzz" \ +lego --email you@example.com --dns f5xc -d '*.example.com' -d example.com run +''' + +[Configuration] + [Configuration.Credentials] + F5XC_API_TOKEN = "API token" + F5XC_TENANT_NAME = "XC Tenant shortname" + F5XC_GROUP_NAME = "Group name" + [Configuration.Additional] + F5XC_POLLING_INTERVAL = "Time between DNS propagation check in seconds (Default: 2)" + F5XC_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation in seconds (Default: 60)" + F5XC_TTL = "The TTL of the TXT record used for the DNS challenge in seconds (Default: 120)" + F5XC_HTTP_TIMEOUT = "API request timeout in seconds (Default: 30)" + +[Links] + API = "https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset" + Documentation = "https://my.f5.com/manage/s/article/K000147937" diff --git a/providers/dns/f5xc/f5xc_test.go b/providers/dns/f5xc/f5xc_test.go new file mode 100644 index 000000000..a298b9e51 --- /dev/null +++ b/providers/dns/f5xc/f5xc_test.go @@ -0,0 +1,166 @@ +package f5xc + +import ( + "testing" + + "github.com/go-acme/lego/v4/platform/tester" + "github.com/stretchr/testify/require" +) + +const envDomain = envNamespace + "DOMAIN" + +var envTest = tester.NewEnvTest(EnvToken, EnvTenantName, EnvGroupName).WithDomain(envDomain) + +func TestNewDNSProvider(t *testing.T) { + testCases := []struct { + desc string + envVars map[string]string + expected string + }{ + { + desc: "success", + envVars: map[string]string{ + EnvToken: "secret", + EnvTenantName: "shortname", + EnvGroupName: "group", + }, + }, + { + desc: "missing API token", + envVars: map[string]string{ + EnvToken: "", + EnvTenantName: "shortname", + EnvGroupName: "group", + }, + expected: "f5xc: some credentials information are missing: F5XC_API_TOKEN", + }, + { + desc: "missing tenant name", + envVars: map[string]string{ + EnvToken: "secret", + EnvTenantName: "", + EnvGroupName: "group", + }, + expected: "f5xc: some credentials information are missing: F5XC_TENANT_NAME", + }, + { + desc: "missing group name", + envVars: map[string]string{ + EnvToken: "secret", + EnvTenantName: "shortname", + EnvGroupName: "", + }, + expected: "f5xc: some credentials information are missing: F5XC_GROUP_NAME", + }, + { + desc: "missing credentials", + envVars: map[string]string{}, + expected: "f5xc: some credentials information are missing: F5XC_API_TOKEN,F5XC_TENANT_NAME,F5XC_GROUP_NAME", + }, + } + + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + defer envTest.RestoreEnv() + envTest.ClearEnv() + + envTest.Apply(test.envVars) + + p, err := NewDNSProvider() + + if test.expected == "" { + require.NoError(t, err) + require.NotNil(t, p) + require.NotNil(t, p.config) + require.NotNil(t, p.client) + } else { + require.EqualError(t, err, test.expected) + } + }) + } +} + +func TestNewDNSProviderConfig(t *testing.T) { + testCases := []struct { + desc string + apiToken string + tenantName string + groupName string + expected string + }{ + { + desc: "success", + apiToken: "secret", + tenantName: "shortname", + groupName: "group", + }, + { + desc: "missing API token", + tenantName: "shortname", + groupName: "group", + expected: "f5xc: credentials missing", + }, + { + desc: "missing tenant name", + apiToken: "secret", + groupName: "group", + expected: "f5xc: missing tenant name", + }, + { + desc: "missing group name", + apiToken: "secret", + tenantName: "shortname", + expected: "f5xc: missing group name", + }, + { + desc: "missing credentials", + expected: "f5xc: missing group name", + }, + } + + for _, test := range testCases { + t.Run(test.desc, func(t *testing.T) { + config := NewDefaultConfig() + config.APIToken = test.apiToken + config.TenantName = test.tenantName + config.GroupName = test.groupName + + p, err := NewDNSProviderConfig(config) + + if test.expected == "" { + require.NoError(t, err) + require.NotNil(t, p) + require.NotNil(t, p.config) + require.NotNil(t, p.client) + } else { + require.EqualError(t, err, test.expected) + } + }) + } +} + +func TestLivePresent(t *testing.T) { + if !envTest.IsLiveTest() { + t.Skip("skipping live test") + } + + envTest.RestoreEnv() + provider, err := NewDNSProvider() + require.NoError(t, err) + + err = provider.Present(envTest.GetDomain(), "", "123d==") + require.NoError(t, err) +} + +func TestLiveCleanUp(t *testing.T) { + if !envTest.IsLiveTest() { + t.Skip("skipping live test") + } + + envTest.RestoreEnv() + provider, err := NewDNSProvider() + require.NoError(t, err) + + err = provider.CleanUp(envTest.GetDomain(), "", "123d==") + require.NoError(t, err) +} diff --git a/providers/dns/f5xc/internal/client.go b/providers/dns/f5xc/internal/client.go new file mode 100644 index 000000000..620336c88 --- /dev/null +++ b/providers/dns/f5xc/internal/client.go @@ -0,0 +1,210 @@ +package internal + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "net/url" + "time" + + "github.com/go-acme/lego/v4/providers/dns/internal/errutils" +) + +const defaultHost = "console.ves.volterra.io" + +const authorizationHeader = "Authorization" + +// Client the F5 XC API client. +type Client struct { + apiToken string + + baseURL *url.URL + HTTPClient *http.Client +} + +// NewClient creates a new Client. +func NewClient(apiToken string, tenantName string) (*Client, error) { + if apiToken == "" { + return nil, errors.New("credentials missing") + } + + if tenantName == "" { + return nil, errors.New("missing tenant name") + } + + baseURL, err := url.Parse(fmt.Sprintf("https://%s.%s", tenantName, defaultHost)) + if err != nil { + return nil, fmt.Errorf("parse base URL: %w", err) + } + + return &Client{ + apiToken: apiToken, + baseURL: baseURL, + HTTPClient: &http.Client{Timeout: 10 * time.Second}, + }, nil +} + +// CreateRRSet creates RRSet. +// https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset#operation/ves.io.schema.dns_zone.rrset.CustomAPI.Create +func (c *Client) CreateRRSet(ctx context.Context, dnsZoneName, groupName string, rrSet RRSet) (*APIRRSet, error) { + endpoint := c.baseURL.JoinPath("api", "config", "dns", "namespaces", "system", "dns_zones", dnsZoneName, "rrsets", groupName) + + req, err := newJSONRequest(ctx, http.MethodPost, endpoint, APIRRSet{ + DNSZoneName: dnsZoneName, + GroupName: groupName, + RRSet: rrSet, + }) + if err != nil { + return nil, err + } + + result := &APIRRSet{} + + err = c.do(req, result) + if err != nil { + return nil, err + } + + return result, nil +} + +// GetRRSet gets RRSets. +// https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset#operation/ves.io.schema.dns_zone.rrset.CustomAPI.Get +func (c *Client) GetRRSet(ctx context.Context, dnsZoneName, groupName, recordName, recordType string) (*APIRRSet, error) { + endpoint := c.baseURL.JoinPath("api", "config", "dns", "namespaces", "system", "dns_zones", dnsZoneName, "rrsets", groupName, recordName, recordType) + + req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil) + if err != nil { + return nil, err + } + + result := &APIRRSet{} + + err = c.do(req, result) + if err != nil { + usce := &APIError{} + if errors.As(err, &usce) && usce.StatusCode == http.StatusNotFound { + return nil, nil + } + + return nil, err + } + + return result, nil +} + +// DeleteRRSet deletes RRSet. +// https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset#operation/ves.io.schema.dns_zone.rrset.CustomAPI.Delete +func (c *Client) DeleteRRSet(ctx context.Context, dnsZoneName, groupName, recordName, recordType string) (*APIRRSet, error) { + endpoint := c.baseURL.JoinPath("api", "config", "dns", "namespaces", "system", "dns_zones", dnsZoneName, "rrsets", groupName, recordName, recordType) + + req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil) + if err != nil { + return nil, err + } + + result := &APIRRSet{} + + err = c.do(req, result) + if err != nil { + return nil, err + } + + return result, nil +} + +// ReplaceRRSet replaces RRSet. +// https://docs.cloud.f5.com/docs-v2/api/dns-zone-rrset#operation/ves.io.schema.dns_zone.rrset.CustomAPI.Replace +func (c *Client) ReplaceRRSet(ctx context.Context, dnsZoneName, groupName, recordName, recordType string, rrSet RRSet) (*APIRRSet, error) { + endpoint := c.baseURL.JoinPath("api", "config", "dns", "namespaces", "system", "dns_zones", dnsZoneName, "rrsets", groupName, recordName, recordType) + + req, err := newJSONRequest(ctx, http.MethodPut, endpoint, APIRRSet{ + DNSZoneName: dnsZoneName, + GroupName: groupName, + RRSet: rrSet, + Type: recordType, + }) + if err != nil { + return nil, err + } + + result := &APIRRSet{} + + err = c.do(req, result) + if err != nil { + return nil, err + } + + return result, nil +} + +func (c *Client) do(req *http.Request, result any) error { + req.Header.Set(authorizationHeader, "APIToken "+c.apiToken) + + 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) + + apiErr := APIError{StatusCode: resp.StatusCode} + err := json.Unmarshal(raw, &apiErr) + if err != nil { + return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw) + } + + return &apiErr +} diff --git a/providers/dns/f5xc/internal/client_test.go b/providers/dns/f5xc/internal/client_test.go new file mode 100644 index 000000000..ca9ac2950 --- /dev/null +++ b/providers/dns/f5xc/internal/client_test.go @@ -0,0 +1,219 @@ +package internal + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "net/url" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func setupTest(t *testing.T, pattern string, status int, filename string) *Client { + t.Helper() + + mux := http.NewServeMux() + server := httptest.NewServer(mux) + t.Cleanup(server.Close) + + mux.HandleFunc(pattern, func(rw http.ResponseWriter, req *http.Request) { + if filename == "" { + rw.WriteHeader(status) + return + } + + file, err := os.Open(filepath.Join("fixtures", filename)) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + + defer func() { _ = file.Close() }() + + rw.WriteHeader(status) + _, err = io.Copy(rw, file) + if err != nil { + http.Error(rw, err.Error(), http.StatusInternalServerError) + return + } + }) + + client, err := NewClient("secret", "shortname") + require.NoError(t, err) + + client.HTTPClient = server.Client() + client.baseURL, _ = url.Parse(server.URL) + + return client +} + +func TestClient_Create(t *testing.T) { + client := setupTest(t, "POST /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA", http.StatusOK, "create.json") + + rrSet := RRSet{ + Description: "lego", + TTL: 60, + TXTRecord: &TXTRecord{ + Name: "wwww", + Values: []string{"txt"}, + }, + } + + result, err := client.CreateRRSet(context.Background(), "example.com", "groupA", rrSet) + require.NoError(t, err) + + expected := &APIRRSet{ + DNSZoneName: "string", + GroupName: "string", + RRSet: RRSet{ + Description: "string", + TXTRecord: &TXTRecord{ + Name: "string", + Values: []string{"string"}, + }, + }, + } + + assert.Equal(t, expected, result) +} + +func TestClient_Create_error(t *testing.T) { + client := setupTest(t, "POST /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA", http.StatusBadRequest, "") + + rrSet := RRSet{ + Description: "lego", + TTL: 60, + TXTRecord: &TXTRecord{ + Name: "wwww", + Values: []string{"txt"}, + }, + } + + _, err := client.CreateRRSet(context.Background(), "example.com", "groupA", rrSet) + require.Error(t, err) +} + +func TestClient_Get(t *testing.T) { + client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json") + + result, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT") + require.NoError(t, err) + + expected := &APIRRSet{ + DNSZoneName: "string", + GroupName: "string", + Namespace: "string", + RecordName: "string", + Type: "string", + RRSet: RRSet{ + Description: "string", + TXTRecord: &TXTRecord{ + Name: "string", + Values: []string{"string"}, + }, + }, + } + + assert.Equal(t, expected, result) +} + +func TestClient_Get_not_found(t *testing.T) { + client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusNotFound, "error_404.json") + + result, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT") + require.NoError(t, err) + + assert.Nil(t, result) +} + +func TestClient_Get_error(t *testing.T) { + client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "") + + _, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT") + require.Error(t, err) +} + +func TestClient_Delete(t *testing.T) { + client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json") + + result, err := client.DeleteRRSet(context.Background(), "example.com", "groupA", "www", "TXT") + require.NoError(t, err) + + expected := &APIRRSet{ + DNSZoneName: "string", + GroupName: "string", + Namespace: "string", + RecordName: "string", + Type: "string", + RRSet: RRSet{ + Description: "string", + TXTRecord: &TXTRecord{ + Name: "string", + Values: []string{"string"}, + }, + }, + } + + assert.Equal(t, expected, result) +} + +func TestClient_Delete_error(t *testing.T) { + client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "") + + _, err := client.DeleteRRSet(context.Background(), "example.com", "groupA", "www", "TXT") + require.Error(t, err) +} + +func TestClient_Replace(t *testing.T) { + client := setupTest(t, "PUT /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json") + + rrSet := RRSet{ + Description: "lego", + TTL: 60, + TXTRecord: &TXTRecord{ + Name: "wwww", + Values: []string{"txt"}, + }, + } + + result, err := client.ReplaceRRSet(context.Background(), "example.com", "groupA", "www", "TXT", rrSet) + require.NoError(t, err) + + expected := &APIRRSet{ + DNSZoneName: "string", + GroupName: "string", + Namespace: "string", + RecordName: "string", + Type: "string", + RRSet: RRSet{ + Description: "string", + TXTRecord: &TXTRecord{ + Name: "string", + Values: []string{"string"}, + }, + }, + } + + assert.Equal(t, expected, result) +} + +func TestClient_Replace_error(t *testing.T) { + client := setupTest(t, "PUT /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "") + + rrSet := RRSet{ + Description: "lego", + TTL: 60, + TXTRecord: &TXTRecord{ + Name: "wwww", + Values: []string{"txt"}, + }, + } + + _, err := client.ReplaceRRSet(context.Background(), "example.com", "groupA", "www", "TXT", rrSet) + require.Error(t, err) +} diff --git a/providers/dns/f5xc/internal/fixtures/create.json b/providers/dns/f5xc/internal/fixtures/create.json new file mode 100644 index 000000000..8c852304d --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/create.json @@ -0,0 +1,204 @@ +{ + "dns_zone_name": "string", + "group_name": "string", + "rrset": { + "a_record": { + "name": "string", + "values": [ + "string" + ] + }, + "aaaa_record": { + "name": "string", + "values": [ + "string" + ] + }, + "afsdb_record": { + "name": "string", + "values": [ + { + "hostname": "string", + "subtype": "NONE" + } + ] + }, + "alias_record": { + "value": "string" + }, + "caa_record": { + "name": "string", + "values": [ + { + "flags": 0, + "tag": "string", + "value": "string" + } + ] + }, + "cds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "cert_record": { + "name": "string", + "values": [ + { + "algorithm": "RESERVEDALGORITHM", + "cert_key_tag": 0, + "cert_type": "INVALIDCERTTYPE", + "certificate": "string" + } + ] + }, + "cname_record": { + "name": "string", + "value": "string" + }, + "description": "string", + "ds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "eui48_record": { + "name": "string", + "value": "stringstringstrin" + }, + "eui64_record": { + "name": "string", + "value": "stringstringstringstrin" + }, + "lb_record": { + "name": "string", + "value": { + "name": "string", + "namespace": "string", + "tenant": "string" + } + }, + "loc_record": { + "name": "string", + "values": [ + { + "altitude": 0.1, + "horizontal_precision": 0.1, + "latitude_degree": 0, + "latitude_hemisphere": "N", + "latitude_minute": 0, + "latitude_second": 0.1, + "location_diameter": 0.1, + "longitude_degree": 0, + "longitude_hemisphere": "E", + "longitude_minute": 0, + "longitude_second": 0.1, + "vertical_precision": 0.1 + } + ] + }, + "mx_record": { + "name": "string", + "values": [ + { + "domain": "string", + "priority": 0 + } + ] + }, + "naptr_record": { + "name": "string", + "values": [ + { + "flags": "string", + "order": 0, + "preference": 0, + "regexp": "string", + "replacement": "string", + "service": "string" + } + ] + }, + "ns_record": { + "name": "string", + "values": [ + "string" + ] + }, + "ptr_record": { + "name": "string", + "values": [ + "string" + ] + }, + "srv_record": { + "name": "string", + "values": [ + { + "port": 0, + "priority": 0, + "target": "string", + "weight": 0 + } + ] + }, + "sshfp_record": { + "name": "string", + "values": [ + { + "algorithm": "UNSPECIFIEDALGORITHM", + "sha1_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstri" + }, + "sha256_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstringstringstringstringstri" + } + } + ] + }, + "tlsa_record": { + "name": "string", + "values": [ + { + "certificate_association_data": "string", + "certificate_usage": "CertificateAuthorityConstraint", + "matching_type": "NoHash", + "selector": "FullCertificate" + } + ] + }, + "ttl": 0, + "txt_record": { + "name": "string", + "values": [ + "string" + ] + } + } +} diff --git a/providers/dns/f5xc/internal/fixtures/delete.json b/providers/dns/f5xc/internal/fixtures/delete.json new file mode 100644 index 000000000..5c5143cae --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/delete.json @@ -0,0 +1,207 @@ +{ + "dns_zone_name": "string", + "group_name": "string", + "namespace": "string", + "record_name": "string", + "rrset": { + "a_record": { + "name": "string", + "values": [ + "string" + ] + }, + "aaaa_record": { + "name": "string", + "values": [ + "string" + ] + }, + "afsdb_record": { + "name": "string", + "values": [ + { + "hostname": "string", + "subtype": "NONE" + } + ] + }, + "alias_record": { + "value": "string" + }, + "caa_record": { + "name": "string", + "values": [ + { + "flags": 0, + "tag": "string", + "value": "string" + } + ] + }, + "cds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "cert_record": { + "name": "string", + "values": [ + { + "algorithm": "RESERVEDALGORITHM", + "cert_key_tag": 0, + "cert_type": "INVALIDCERTTYPE", + "certificate": "string" + } + ] + }, + "cname_record": { + "name": "string", + "value": "string" + }, + "description": "string", + "ds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "eui48_record": { + "name": "string", + "value": "stringstringstrin" + }, + "eui64_record": { + "name": "string", + "value": "stringstringstringstrin" + }, + "lb_record": { + "name": "string", + "value": { + "name": "string", + "namespace": "string", + "tenant": "string" + } + }, + "loc_record": { + "name": "string", + "values": [ + { + "altitude": 0.1, + "horizontal_precision": 0.1, + "latitude_degree": 0, + "latitude_hemisphere": "N", + "latitude_minute": 0, + "latitude_second": 0.1, + "location_diameter": 0.1, + "longitude_degree": 0, + "longitude_hemisphere": "E", + "longitude_minute": 0, + "longitude_second": 0.1, + "vertical_precision": 0.1 + } + ] + }, + "mx_record": { + "name": "string", + "values": [ + { + "domain": "string", + "priority": 0 + } + ] + }, + "naptr_record": { + "name": "string", + "values": [ + { + "flags": "string", + "order": 0, + "preference": 0, + "regexp": "string", + "replacement": "string", + "service": "string" + } + ] + }, + "ns_record": { + "name": "string", + "values": [ + "string" + ] + }, + "ptr_record": { + "name": "string", + "values": [ + "string" + ] + }, + "srv_record": { + "name": "string", + "values": [ + { + "port": 0, + "priority": 0, + "target": "string", + "weight": 0 + } + ] + }, + "sshfp_record": { + "name": "string", + "values": [ + { + "algorithm": "UNSPECIFIEDALGORITHM", + "sha1_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstri" + }, + "sha256_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstringstringstringstringstri" + } + } + ] + }, + "tlsa_record": { + "name": "string", + "values": [ + { + "certificate_association_data": "string", + "certificate_usage": "CertificateAuthorityConstraint", + "matching_type": "NoHash", + "selector": "FullCertificate" + } + ] + }, + "ttl": 0, + "txt_record": { + "name": "string", + "values": [ + "string" + ] + } + }, + "type": "string" +} diff --git a/providers/dns/f5xc/internal/fixtures/error_404.json b/providers/dns/f5xc/internal/fixtures/error_404.json new file mode 100644 index 000000000..4abd79dd4 --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/error_404.json @@ -0,0 +1,5 @@ +{ + "code": 5, + "details": [], + "message": "the requested resource record was not found: (group,name,type) (acme-records,_acme-challenge,TXT)" +} diff --git a/providers/dns/f5xc/internal/fixtures/error_503.json b/providers/dns/f5xc/internal/fixtures/error_503.json new file mode 100644 index 000000000..8d286a2a0 --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/error_503.json @@ -0,0 +1,5 @@ +{ + "code": 14, + "details": [], + "message": "Previous DNS zone change is pending. Try again later" +} diff --git a/providers/dns/f5xc/internal/fixtures/get.json b/providers/dns/f5xc/internal/fixtures/get.json new file mode 100644 index 000000000..5c5143cae --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/get.json @@ -0,0 +1,207 @@ +{ + "dns_zone_name": "string", + "group_name": "string", + "namespace": "string", + "record_name": "string", + "rrset": { + "a_record": { + "name": "string", + "values": [ + "string" + ] + }, + "aaaa_record": { + "name": "string", + "values": [ + "string" + ] + }, + "afsdb_record": { + "name": "string", + "values": [ + { + "hostname": "string", + "subtype": "NONE" + } + ] + }, + "alias_record": { + "value": "string" + }, + "caa_record": { + "name": "string", + "values": [ + { + "flags": 0, + "tag": "string", + "value": "string" + } + ] + }, + "cds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "cert_record": { + "name": "string", + "values": [ + { + "algorithm": "RESERVEDALGORITHM", + "cert_key_tag": 0, + "cert_type": "INVALIDCERTTYPE", + "certificate": "string" + } + ] + }, + "cname_record": { + "name": "string", + "value": "string" + }, + "description": "string", + "ds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "eui48_record": { + "name": "string", + "value": "stringstringstrin" + }, + "eui64_record": { + "name": "string", + "value": "stringstringstringstrin" + }, + "lb_record": { + "name": "string", + "value": { + "name": "string", + "namespace": "string", + "tenant": "string" + } + }, + "loc_record": { + "name": "string", + "values": [ + { + "altitude": 0.1, + "horizontal_precision": 0.1, + "latitude_degree": 0, + "latitude_hemisphere": "N", + "latitude_minute": 0, + "latitude_second": 0.1, + "location_diameter": 0.1, + "longitude_degree": 0, + "longitude_hemisphere": "E", + "longitude_minute": 0, + "longitude_second": 0.1, + "vertical_precision": 0.1 + } + ] + }, + "mx_record": { + "name": "string", + "values": [ + { + "domain": "string", + "priority": 0 + } + ] + }, + "naptr_record": { + "name": "string", + "values": [ + { + "flags": "string", + "order": 0, + "preference": 0, + "regexp": "string", + "replacement": "string", + "service": "string" + } + ] + }, + "ns_record": { + "name": "string", + "values": [ + "string" + ] + }, + "ptr_record": { + "name": "string", + "values": [ + "string" + ] + }, + "srv_record": { + "name": "string", + "values": [ + { + "port": 0, + "priority": 0, + "target": "string", + "weight": 0 + } + ] + }, + "sshfp_record": { + "name": "string", + "values": [ + { + "algorithm": "UNSPECIFIEDALGORITHM", + "sha1_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstri" + }, + "sha256_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstringstringstringstringstri" + } + } + ] + }, + "tlsa_record": { + "name": "string", + "values": [ + { + "certificate_association_data": "string", + "certificate_usage": "CertificateAuthorityConstraint", + "matching_type": "NoHash", + "selector": "FullCertificate" + } + ] + }, + "ttl": 0, + "txt_record": { + "name": "string", + "values": [ + "string" + ] + } + }, + "type": "string" +} diff --git a/providers/dns/f5xc/internal/fixtures/replace.json b/providers/dns/f5xc/internal/fixtures/replace.json new file mode 100644 index 000000000..e3e483df5 --- /dev/null +++ b/providers/dns/f5xc/internal/fixtures/replace.json @@ -0,0 +1,206 @@ +{ + "dns_zone_name": "string", + "group_name": "string", + "record_name": "string", + "rrset": { + "a_record": { + "name": "string", + "values": [ + "string" + ] + }, + "aaaa_record": { + "name": "string", + "values": [ + "string" + ] + }, + "afsdb_record": { + "name": "string", + "values": [ + { + "hostname": "string", + "subtype": "NONE" + } + ] + }, + "alias_record": { + "value": "string" + }, + "caa_record": { + "name": "string", + "values": [ + { + "flags": 0, + "tag": "string", + "value": "string" + } + ] + }, + "cds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "cert_record": { + "name": "string", + "values": [ + { + "algorithm": "RESERVEDALGORITHM", + "cert_key_tag": 0, + "cert_type": "INVALIDCERTTYPE", + "certificate": "string" + } + ] + }, + "cname_record": { + "name": "string", + "value": "string" + }, + "description": "string", + "ds_record": { + "name": "string", + "values": [ + { + "ds_key_algorithm": "UNSPECIFIED", + "key_tag": 0, + "sha1_digest": { + "digest": "stringstringstringstringstringstringstri" + }, + "sha256_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstri" + }, + "sha384_digest": { + "digest": "stringstringstringstringstringstringstringstringstringstringstringstringstringstringstringstring" + } + } + ] + }, + "eui48_record": { + "name": "string", + "value": "stringstringstrin" + }, + "eui64_record": { + "name": "string", + "value": "stringstringstringstrin" + }, + "lb_record": { + "name": "string", + "value": { + "name": "string", + "namespace": "string", + "tenant": "string" + } + }, + "loc_record": { + "name": "string", + "values": [ + { + "altitude": 0.1, + "horizontal_precision": 0.1, + "latitude_degree": 0, + "latitude_hemisphere": "N", + "latitude_minute": 0, + "latitude_second": 0.1, + "location_diameter": 0.1, + "longitude_degree": 0, + "longitude_hemisphere": "E", + "longitude_minute": 0, + "longitude_second": 0.1, + "vertical_precision": 0.1 + } + ] + }, + "mx_record": { + "name": "string", + "values": [ + { + "domain": "string", + "priority": 0 + } + ] + }, + "naptr_record": { + "name": "string", + "values": [ + { + "flags": "string", + "order": 0, + "preference": 0, + "regexp": "string", + "replacement": "string", + "service": "string" + } + ] + }, + "ns_record": { + "name": "string", + "values": [ + "string" + ] + }, + "ptr_record": { + "name": "string", + "values": [ + "string" + ] + }, + "srv_record": { + "name": "string", + "values": [ + { + "port": 0, + "priority": 0, + "target": "string", + "weight": 0 + } + ] + }, + "sshfp_record": { + "name": "string", + "values": [ + { + "algorithm": "UNSPECIFIEDALGORITHM", + "sha1_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstri" + }, + "sha256_fingerprint": { + "fingerprint": "stringstringstringstringstringstringstringstringstringstringstri" + } + } + ] + }, + "tlsa_record": { + "name": "string", + "values": [ + { + "certificate_association_data": "string", + "certificate_usage": "CertificateAuthorityConstraint", + "matching_type": "NoHash", + "selector": "FullCertificate" + } + ] + }, + "ttl": 0, + "txt_record": { + "name": "string", + "values": [ + "string" + ] + } + }, + "type": "string" +} diff --git a/providers/dns/f5xc/internal/types.go b/providers/dns/f5xc/internal/types.go new file mode 100644 index 000000000..3122ca4ef --- /dev/null +++ b/providers/dns/f5xc/internal/types.go @@ -0,0 +1,48 @@ +package internal + +import ( + "fmt" + "strings" +) + +type APIError struct { + StatusCode int `json:"-"` + Code int `json:"code"` + Details []string `json:"details"` + Message string `json:"message"` +} + +func (a *APIError) Error() string { + var details string + if len(a.Details) > 0 { + details = " " + strings.Join(a.Details, ", ") + } + + return fmt.Sprintf("code: %d, message: %s%s", a.Code, a.Message, details) +} + +type APIRRSet struct { + DNSZoneName string `json:"dns_zone_name,omitempty"` + GroupName string `json:"group_name,omitempty"` + Namespace string `json:"namespace,omitempty"` + RecordName string `json:"record_name,omitempty"` + Type string `json:"type,omitempty"` + RRSet RRSet `json:"rrset,omitempty"` +} + +type RRSetRequest struct { + DNSZoneName string `json:"dns_zone_name,omitempty"` + GroupName string `json:"group_name,omitempty"` + RRSet RRSet `json:"rrset,omitempty"` +} + +type RRSet struct { + Description string `json:"description,omitempty"` + TTL int `json:"ttl,omitempty"` + TXTRecord *TXTRecord `json:"txt_record,omitempty"` +} + +type TXTRecord struct { + Name string `json:"name,omitempty"` + Values []string `json:"values,omitempty"` +} diff --git a/providers/dns/zz_gen_dns_providers.go b/providers/dns/zz_gen_dns_providers.go index f3afca153..f52feaa25 100644 --- a/providers/dns/zz_gen_dns_providers.go +++ b/providers/dns/zz_gen_dns_providers.go @@ -52,6 +52,7 @@ import ( "github.com/go-acme/lego/v4/providers/dns/epik" "github.com/go-acme/lego/v4/providers/dns/exec" "github.com/go-acme/lego/v4/providers/dns/exoscale" + "github.com/go-acme/lego/v4/providers/dns/f5xc" "github.com/go-acme/lego/v4/providers/dns/freemyip" "github.com/go-acme/lego/v4/providers/dns/gandi" "github.com/go-acme/lego/v4/providers/dns/gandiv5" @@ -252,6 +253,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) { return exec.NewDNSProvider() case "exoscale": return exoscale.NewDNSProvider() + case "f5xc": + return f5xc.NewDNSProvider() case "freemyip": return freemyip.NewDNSProvider() case "gandi":