diff --git a/README.md b/README.md index cebd033c2c..3656918cf1 100644 --- a/README.md +++ b/README.md @@ -108,134 +108,134 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns). Exoscale External program + F5 XC freemyip.com G-Core - Gandi + Gandi Gandi Live DNS (v5) Glesys Go Daddy - Google Cloud + Google Cloud Google Domains Hetzner Hosting.de - Hosttech + Hosttech HTTP request http.net Huawei Cloud - Hurricane Electric DNS + Hurricane Electric DNS HyperOne IBM Cloud (SoftLayer) IIJ DNS Platform Service - Infoblox + Infoblox Infomaniak Internet Initiative Japan Internet.bs - INWX + INWX Ionos IPv64 iwantmyname - Joker + Joker Joohoi's ACME-DNS Liara Lima-City - Linode (v4) + Linode (v4) Liquid Web Loopia LuaDNS - Mail-in-a-Box + Mail-in-a-Box ManageEngine CloudDNS Manual Metaname - mijn.host + mijn.host Mittwald MyDNS.jp MythicBeasts - Name.com + Name.com Namecheap Namesilo NearlyFreeSpeech.NET - Netcup + Netcup Netlify Nicmanager NIFCloud - Njalla + Njalla Nodion NS1 Open Telekom Cloud - Oracle Cloud + Oracle Cloud OVH plesk.com Porkbun - PowerDNS + PowerDNS Rackspace Rain Yun/雨云 RcodeZero - reg.ru + reg.ru Regfish RFC2136 RimuHosting - Sakura Cloud + Sakura Cloud Scaleway Selectel Selectel v2 - SelfHost.(de|eu) + SelfHost.(de|eu) Servercow Shellrent Simply.com - Sonic + Sonic 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 203cff36f6..6221751457 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -57,6 +57,7 @@ func allDNSCodes() string { "epik", "exec", "exoscale", + "f5xc", "freemyip", "gandi", "gandiv5", @@ -1119,6 +1120,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.22.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 0000000000..6deb30eab0 --- /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.22.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.22.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 f6674e5e59..eb981cc843 100644 --- a/docs/data/zz_cli_help.toml +++ b/docs/data/zz_cli_help.toml @@ -22,7 +22,7 @@ GLOBAL OPTIONS: --domains value, -d value [ --domains value, -d value ] Add a domain to the process. Can be specified multiple times. --server value, -s value CA hostname (and optionally :port). The server certificate must be trusted in order to avoid further modifications to the client. (default: "https://acme-v02.api.letsencrypt.org/directory") [$LEGO_SERVER] --accept-tos, -a By setting this flag to true you indicate that you accept the current Let's Encrypt terms of service. (default: false) - --email value, -m value Email used for registration and recovery contact. + --email value, -m value Email used for registration and recovery contact. [$LEGO_EMAIL] --csr value, -c value Certificate signing request filename, if an external CSR is to be used. --eab Use External Account Binding for account registration. Requires --kid and --hmac. (default: false) [$LEGO_EAB] --kid value Key identifier from External CA. Used for External Account Binding. [$LEGO_EAB_KID] @@ -145,7 +145,7 @@ To display the documentation for a specific DNS provider, run: $ lego dnshelp -c code Supported DNS providers: - acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manageengine, manual, metaname, mijnhost, mittwald, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi + acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, 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, mijnhost, mittwald, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rainyun, rcodezero, regfish, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, stackpath, technitium, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, westcn, yandex, yandex360, yandexcloud, zoneee, zonomi 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 0000000000..e98d5fff93 --- /dev/null +++ b/providers/dns/f5xc/f5xc.go @@ -0,0 +1,175 @@ +// 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/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 err + } + + // New RRSet. + if existingRRSet.RRSet.TXTRecord == nil { + rrSet := internal.RRSet{ + Description: "lego", + TTL: d.config.TTL, + TXTRecord: &internal.TXTRecord{ + Name: subDomain, + Values: []string{info.Value}, + }, + } + + _, err = d.client.CreateRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, rrSet) + if err != nil { + return fmt.Errorf("f5xc: create RR set: %w", err) + } + + return nil + } + + // Update RRSet. + existingRRSet.RRSet.TXTRecord.Values = append(existingRRSet.RRSet.TXTRecord.Values, info.Value) + + _, err = d.client.ReplaceRRSet(context.Background(), dns01.UnFqdn(authZone), d.config.GroupName, subDomain, "TXT", existingRRSet.RRSet) + if err != nil { + return fmt.Errorf("f5xc: replace RR set: %w", err) + } + + return nil +} + +// CleanUp removes the TXT record matching the specified parameters. +func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { + info := dns01.GetChallengeInfo(domain, keyAuth) + + authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("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 0000000000..f1b2bb6a11 --- /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.22.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 0000000000..a298b9e51b --- /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 0000000000..88e4a755f7 --- /dev/null +++ b/providers/dns/f5xc/internal/client.go @@ -0,0 +1,194 @@ +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 { + 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 { + raw, _ := io.ReadAll(resp.Body) + return errutils.NewUnexpectedStatusCodeError(req, resp.StatusCode, raw) + } + + 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 +} diff --git a/providers/dns/f5xc/internal/client_test.go b/providers/dns/f5xc/internal/client_test.go new file mode 100644 index 0000000000..64b880c940 --- /dev/null +++ b/providers/dns/f5xc/internal/client_test.go @@ -0,0 +1,210 @@ +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_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 0000000000..8c852304d0 --- /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 0000000000..5c5143caec --- /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/get.json b/providers/dns/f5xc/internal/fixtures/get.json new file mode 100644 index 0000000000..5c5143caec --- /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 0000000000..e3e483df5e --- /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 0000000000..65ea4932a6 --- /dev/null +++ b/providers/dns/f5xc/internal/types.go @@ -0,0 +1,27 @@ +package internal + +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 053c3c4e7b..c1c5d20354 100644 --- a/providers/dns/zz_gen_dns_providers.go +++ b/providers/dns/zz_gen_dns_providers.go @@ -51,6 +51,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" @@ -246,6 +247,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":