plugin/clouddns: add endpoint directive (#8618)

Brings clouddns to parity with route53, which already exposes
aws_endpoint for overriding the API endpoint (useful for pointing at a
local emulator or test environment). clouddns has no equivalent - its
client constructor only ever accepts a credentials option.

Changes f's single option.ClientOption parameter to variadic
...option.ClientOption so credentials and endpoint can be combined, and
adds the endpoint case wired to option.WithEndpoint, Google's own
client option for this exact purpose.

Extends TestSetupCloudDNS with endpoint coverage (valid value, missing
arg). Verified it fails without the setup.go change (unknown property
error) and passes with it.

Signed-off-by: stackedbyaradhya <aradhyaj736@gmail.com>
This commit is contained in:
Aradhya Jain
2026-10-09 13:58:35 +05:30
committed by GitHub
parent ef18404448
commit 123829d3b3
3 changed files with 34 additions and 14 deletions

View File

@@ -25,16 +25,10 @@ var log = clog.NewWithPlugin("clouddns")
func init() { plugin.Register("clouddns", setup) }
// exposed for testing
var f = func(ctx context.Context, opt option.ClientOption) (gcpDNS, error) {
var err error
var client *gcp.Service
if opt != nil {
client, err = gcp.NewService(ctx, opt)
} else {
// if credentials file is not provided in the Corefile
// authenticate the client using env variables
client, err = gcp.NewService(ctx)
}
var f = func(ctx context.Context, opts ...option.ClientOption) (gcpDNS, error) {
// if credentials file is not provided in the Corefile, authenticate the
// client using env variables; option.WithEndpoint, if any, still applies.
client, err := gcp.NewService(ctx, opts...)
return gcpClient{client}, err
}
@@ -65,7 +59,7 @@ func setup(c *caddy.Controller) error {
keys[dnsName] = append(keys[dnsName], projectName+":"+hostedZone)
}
var opt option.ClientOption
var opts []option.ClientOption
refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute
for c.NextBlock() {
switch c.Val() {
@@ -79,7 +73,12 @@ func setup(c *caddy.Controller) error {
if err != nil {
return plugin.Error("clouddns", c.Errf("invalid credentials file %q: %v", c.Val(), err))
}
opt = option.WithAuthCredentialsFile(credType, c.Val())
opts = append(opts, option.WithAuthCredentialsFile(credType, c.Val()))
case "endpoint":
if !c.NextArg() {
return plugin.Error("clouddns", c.ArgErr())
}
opts = append(opts, option.WithEndpoint(c.Val()))
case "fallthrough":
fall.SetZonesFromArgs(c.RemainingArgs())
case "refresh":
@@ -104,7 +103,7 @@ func setup(c *caddy.Controller) error {
}
ctx, cancel := context.WithCancel(context.Background())
client, err := f(ctx, opt)
client, err := f(ctx, opts...)
if err != nil {
cancel()
return err