Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Dec 22, 2020
0 parents commit f09e15f
Show file tree
Hide file tree
Showing 5 changed files with 1,001 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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/
43 changes: 43 additions & 0 deletions README.md
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.
61 changes: 61 additions & 0 deletions duckdns.go
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)
8 changes: 8 additions & 0 deletions go.mod
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
)
Loading

0 comments on commit f09e15f

Please sign in to comment.