Skip to content

Commit be66792

Browse files
committed
feat(custom): allow empty ipv4 and ipv6 keys
- Fix #875
1 parent 6b61b8c commit be66792

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

docs/custom.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Feel free to open issues to extend its configuration options.
3030

3131
- `"domain"` is the domain to update. It can be `example.com` (root domain), `sub.example.com` (subdomain of `example.com`) or `*.example.com` for the wildcard.
3232
- `"url"` is the URL to update your records and should contain all the information EXCEPT the IP address to update
33-
- `"ipv4key"` is the URL query parameter name for the IPv4 address, for example `ipv4` will be added to the URL with `&ipv4=1.2.3.4`.
34-
- `"ipv6key"` is the URL query parameter name for the IPv6 address, for example `ipv6` will be added to the URL with `&ipv6=::aaff`. Even if you don't use IPv6, this must be set to something.
33+
- `"ipv4key"` is the URL query parameter name for the IPv4 address, for example `ipv4` will be added to the URL with `&ipv4=1.2.3.4`. In the rare case you do not wish to send an IPv4 query parameter to the registrar API when updating your A (IPv4) record, leave it to `"ipv4key": ""`.
34+
- `"ipv6key"` is the URL query parameter name for the IPv6 address, for example `ipv6` will be added to the URL with `&ipv6=::aaff`. In the rare case you do not wish to send an IPv6 query parameter to the registrar API when updating your AAAA (IPv6) record, leave it to `"ipv6key": ""`.
3535
- `"success_regex"` is a regular expression to match the response from the server to determine if the update was successful. You can use [regex101.com](https://regex101.com/) to find the regular expression you want. For example `good` would match any response containing the word "good".
3636

3737
### Optional parameters

internal/provider/errors/validation.go

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var (
1919
ErrGCPProjectNotSet = errors.New("GCP project is not set")
2020
ErrDomainNotValid = errors.New("domain is not valid")
2121
ErrOwnerWildcard = errors.New(`owner cannot be "*"`)
22-
ErrIPv4KeyNotSet = errors.New("IPv4 key is not set")
23-
ErrIPv6KeyNotSet = errors.New("IPv6 key is not set")
2422
ErrKeyNotSet = errors.New("key is not set")
2523
ErrKeyNotValid = errors.New("key is not valid")
2624
ErrPasswordNotSet = errors.New("password is not set")

internal/provider/providers/custom/provider.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func New(data json.RawMessage, domain, owner string,
4949
return nil, fmt.Errorf("parsing URL: %w", err)
5050
}
5151

52-
err = validateSettings(domain, parsedURL, extraSettings.IPv4Key, extraSettings.IPv6Key, extraSettings.SuccessRegex)
52+
err = validateSettings(domain, parsedURL, extraSettings.SuccessRegex)
5353
if err != nil {
5454
return nil, fmt.Errorf("validating provider specific settings: %w", err)
5555
}
@@ -67,7 +67,7 @@ func New(data json.RawMessage, domain, owner string,
6767
}
6868

6969
func validateSettings(domain string, url *url.URL,
70-
ipv4Key, ipv6Key string, successRegex regexp.Regexp,
70+
successRegex regexp.Regexp,
7171
) (err error) {
7272
err = utils.CheckDomain(domain)
7373
if err != nil {
@@ -79,10 +79,6 @@ func validateSettings(domain string, url *url.URL,
7979
return fmt.Errorf("%w", errors.ErrURLNotSet)
8080
case url.Scheme != "https":
8181
return fmt.Errorf("%w: %s", errors.ErrURLNotHTTPS, url.Scheme)
82-
case ipv4Key == "":
83-
return fmt.Errorf("%w", errors.ErrIPv4KeyNotSet)
84-
case ipv6Key == "":
85-
return fmt.Errorf("%w", errors.ErrIPv6KeyNotSet)
8682
case successRegex.String() == "":
8783
return fmt.Errorf("%w", errors.ErrSuccessRegexNotSet)
8884
default:
@@ -138,7 +134,9 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
138134
if ip.Is6() {
139135
ipKey = p.ipv6Key
140136
}
141-
values.Set(ipKey, ip.String())
137+
if ipKey != "" {
138+
values.Set(ipKey, ip.String())
139+
}
142140
p.url.RawQuery = values.Encode()
143141

144142
request, err := http.NewRequestWithContext(ctx, http.MethodGet, p.url.String(), nil)

0 commit comments

Comments
 (0)