From c00699867f7b77a5a48305a939300613abf10f5a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 31 Jul 2024 13:38:13 -0400 Subject: [PATCH] fix: respect caddyfile provider config (#50) Adds the new config properties --- README.md | 6 +++++- route53.go | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 791f9c3..816468f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ To use this module for the ACME DNS challenge, [configure the ACME issuer in you "region": "us-east-1", // optional "access_key_id": "AKI...", // optional "secret_access_key": "wJa...", // optional - "session_token": "TOKEN..." // optional + "session_token": "TOKEN...", // optional + "max_wait_dur": 60, // propagation wait duration (optional) + "wait_for_propagation": false // wait for records to propagate (optional) } } } @@ -52,6 +54,8 @@ tls { secret_access_key "wJa..." // optional session_token "TOKEN..." // optional region "us-east-1" // optional + max_wait_dur 60, // propagation wait duration (optional) + wait_for_propagation false // wait for records to propagate (optional) } } ``` diff --git a/route53.go b/route53.go index 1f8e1c5..e9f5413 100644 --- a/route53.go +++ b/route53.go @@ -2,6 +2,7 @@ package route53 import ( "strconv" + "time" "github.com/libdns/route53" @@ -29,25 +30,28 @@ func (Provider) CaddyModule() caddy.ModuleInfo { // Provision implements the Provisioner interface to initialize the AWS Client func (p *Provider) Provision(ctx caddy.Context) error { repl := caddy.NewReplacer() + p.Provider.Profile = repl.ReplaceAll(p.Provider.Profile, "") p.Provider.AWSProfile = repl.ReplaceAll(p.Provider.AWSProfile, "") p.Provider.AccessKeyId = repl.ReplaceAll(p.Provider.AccessKeyId, "") p.Provider.SecretAccessKey = repl.ReplaceAll(p.Provider.SecretAccessKey, "") p.Provider.Token = repl.ReplaceAll(p.Provider.Token, "") + p.Provider.SessionToken = repl.ReplaceAll(p.Provider.SessionToken, "") p.Provider.Region = repl.ReplaceAll(p.Provider.Region, "") return nil } // UnmarshalCaddyfile sets up the DNS provider from Caddyfile tokens. Syntax: // -// route53 { -// max_retries -// aws_profile -// access_key_id -// secret_access_key -// token -// region -// } -// +// route53 { +// region +// profile +// access_key_id +// secret_access_key +// session_token +// max_retries +// max_wait_dur +// wait_for_propagation +// } func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { for d.Next() { if d.NextArg() { @@ -55,6 +59,24 @@ func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } for nesting := d.Nesting(); d.NextBlock(nesting); { switch d.Val() { + case "wait_for_propagation": + if d.NextArg() { + if wait, err := strconv.ParseBool(d.Val()); err == nil { + p.Provider.WaitForPropagation = wait + } + } + if d.NextArg() { + return d.ArgErr() + } + case "max_wait_dur": + if d.NextArg() { + if dur, err := strconv.ParseInt(d.Val(), 10, 64); err == nil { + p.Provider.MaxWaitDur = time.Duration(dur) + } + } + if d.NextArg() { + return d.ArgErr() + } case "max_retries": if d.NextArg() { p.Provider.MaxRetries, _ = strconv.Atoi(d.Val()) @@ -62,6 +84,13 @@ func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if d.NextArg() { return d.ArgErr() } + case "profile": + if d.NextArg() { + p.Provider.Profile = d.Val() + } + if d.NextArg() { + return d.ArgErr() + } case "aws_profile": if d.NextArg() { p.Provider.AWSProfile = d.Val() @@ -83,6 +112,13 @@ func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if d.NextArg() { return d.ArgErr() } + case "session_token": + if d.NextArg() { + p.Provider.SessionToken = d.Val() + } + if d.NextArg() { + return d.ArgErr() + } case "token": if d.NextArg() { p.Provider.Token = d.Val()