feat(custom): allow empty ipv4 and ipv6 keys

- Fix #875
This commit is contained in:
Quentin McGaw
2024-12-23 08:29:01 +00:00
parent 6b61b8c6b8
commit be6679273f
3 changed files with 7 additions and 11 deletions

View File

@@ -30,8 +30,8 @@ Feel free to open issues to extend its configuration options.
- `"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.
- `"url"` is the URL to update your records and should contain all the information EXCEPT the IP address to update
- `"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`.
- `"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.
- `"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": ""`.
- `"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": ""`.
- `"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".
### Optional parameters

View File

@@ -19,8 +19,6 @@ var (
ErrGCPProjectNotSet = errors.New("GCP project is not set")
ErrDomainNotValid = errors.New("domain is not valid")
ErrOwnerWildcard = errors.New(`owner cannot be "*"`)
ErrIPv4KeyNotSet = errors.New("IPv4 key is not set")
ErrIPv6KeyNotSet = errors.New("IPv6 key is not set")
ErrKeyNotSet = errors.New("key is not set")
ErrKeyNotValid = errors.New("key is not valid")
ErrPasswordNotSet = errors.New("password is not set")

View File

@@ -49,7 +49,7 @@ func New(data json.RawMessage, domain, owner string,
return nil, fmt.Errorf("parsing URL: %w", err)
}
err = validateSettings(domain, parsedURL, extraSettings.IPv4Key, extraSettings.IPv6Key, extraSettings.SuccessRegex)
err = validateSettings(domain, parsedURL, extraSettings.SuccessRegex)
if err != nil {
return nil, fmt.Errorf("validating provider specific settings: %w", err)
}
@@ -67,7 +67,7 @@ func New(data json.RawMessage, domain, owner string,
}
func validateSettings(domain string, url *url.URL,
ipv4Key, ipv6Key string, successRegex regexp.Regexp,
successRegex regexp.Regexp,
) (err error) {
err = utils.CheckDomain(domain)
if err != nil {
@@ -79,10 +79,6 @@ func validateSettings(domain string, url *url.URL,
return fmt.Errorf("%w", errors.ErrURLNotSet)
case url.Scheme != "https":
return fmt.Errorf("%w: %s", errors.ErrURLNotHTTPS, url.Scheme)
case ipv4Key == "":
return fmt.Errorf("%w", errors.ErrIPv4KeyNotSet)
case ipv6Key == "":
return fmt.Errorf("%w", errors.ErrIPv6KeyNotSet)
case successRegex.String() == "":
return fmt.Errorf("%w", errors.ErrSuccessRegexNotSet)
default:
@@ -138,7 +134,9 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
if ip.Is6() {
ipKey = p.ipv6Key
}
values.Set(ipKey, ip.String())
if ipKey != "" {
values.Set(ipKey, ip.String())
}
p.url.RawQuery = values.Encode()
request, err := http.NewRequestWithContext(ctx, http.MethodGet, p.url.String(), nil)