-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f09e15f
Showing
5 changed files
with
1,001 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Duck DNS module for Caddy | ||
=========================== | ||
|
||
This package contains a DNS provider module for [Caddy](https://github.com/caddyserver/caddy). It can be used to manage DNS records for Duck DNS. | ||
|
||
## Caddy module name | ||
|
||
``` | ||
dns.providers.duckdns | ||
``` | ||
|
||
## Config examples | ||
|
||
To use this module for the ACME DNS challenge, [configure the ACME issuer in your Caddy JSON](https://caddyserver.com/docs/json/apps/tls/automation/policies/issuer/acme/) like so: | ||
|
||
``` | ||
{ | ||
"module": "acme", | ||
"challenges": { | ||
"dns": { | ||
"provider": { | ||
"name": "duckdns", | ||
"api_token": "YOUR_DUCKDNS_API_TOKEN" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
or with the Caddyfile: | ||
|
||
``` | ||
tls { | ||
dns cloudflare {env.DUCKDNS_API_TOKEN} | ||
} | ||
``` | ||
|
||
You can replace `{env.DUCKDNS_API_TOKEN}` with the actual auth token if you prefer to put it directly in your config instead of an environment variable. | ||
|
||
|
||
## Authenticating | ||
|
||
See [the associated README in the libdns package](https://github.com/libdns/duckdns) for important information about credentials. Your token can be found at the top of the page when logged in at https://www.duckdns.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package duckdns | ||
|
||
import ( | ||
"github.com/caddyserver/caddy/v2" | ||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | ||
"github.com/libdns/duckdns" | ||
) | ||
|
||
// Provider wraps the provider implementation as a Caddy module. | ||
type Provider struct{ *duckdns.Provider } | ||
|
||
func init() { | ||
caddy.RegisterModule(Provider{}) | ||
} | ||
|
||
// CaddyModule returns the Caddy module information. | ||
func (Provider) CaddyModule() caddy.ModuleInfo { | ||
return caddy.ModuleInfo{ | ||
ID: "dns.providers.duckdns", | ||
New: func() caddy.Module { return &Provider{new(duckdns.Provider)} }, | ||
} | ||
} | ||
|
||
// UnmarshalCaddyfile sets up the DNS provider from Caddyfile tokens. Syntax: | ||
// | ||
// duckdns [<api_token>] { | ||
// api_token <api_token> | ||
// } | ||
// | ||
func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { | ||
repl := caddy.NewReplacer() | ||
for d.Next() { | ||
if d.NextArg() { | ||
p.Provider.APIToken = repl.ReplaceAll(d.Val(), "") | ||
} | ||
if d.NextArg() { | ||
return d.ArgErr() | ||
} | ||
for nesting := d.Nesting(); d.NextBlock(nesting); { | ||
switch d.Val() { | ||
case "api_token": | ||
if p.Provider.APIToken != "" { | ||
return d.Err("API token already set") | ||
} | ||
p.Provider.APIToken = repl.ReplaceAll(d.Val(), "") | ||
if d.NextArg() { | ||
return d.ArgErr() | ||
} | ||
default: | ||
return d.Errf("unrecognized subdirective '%s'", d.Val()) | ||
} | ||
} | ||
} | ||
if p.Provider.APIToken == "" { | ||
return d.Err("missing API token") | ||
} | ||
return nil | ||
} | ||
|
||
// Interface guard | ||
var _ caddyfile.Unmarshaler = (*Provider)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/caddy-dns/duckdns | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/caddyserver/caddy/v2 v2.2.3 | ||
github.com/libdns/duckdns v0.0.0-20201222042124-b3088d77f212 | ||
) |
Oops, something went wrong.