Skip to content

Commit

Permalink
dnsimple: Upgrade client to 0.60.0 (go-acme#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos authored May 10, 2020
1 parent 25ea7ac commit f13a88f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ func displayDNSHelp(name string) error {
ew.writeln()

ew.writeln(`Credentials:`)
ew.writeln(` - "DNSIMPLE_BASE_URL": API endpoint URL`)
ew.writeln(` - "DNSIMPLE_OAUTH_TOKEN": OAuth token`)
ew.writeln()

ew.writeln(`Additional Configuration:`)
ew.writeln(` - "DNSIMPLE_BASE_URL": API endpoint URL`)
ew.writeln(` - "DNSIMPLE_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "DNSIMPLE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "DNSIMPLE_TTL": The TTL of the TXT record used for the DNS challenge`)
Expand Down
26 changes: 22 additions & 4 deletions docs/content/dns/zz_gen_dnsimple.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ Configuration for [DNSimple](https://dnsimple.com/).

- Code: `dnsimple`

{{% notice note %}}
_Please contribute by adding a CLI example._
{{% /notice %}}
Here is an example bash command using the DNSimple provider:

```bash
DNSIMPLE_OAUTH_TOKEN=1234567890abcdefghijklmnopqrstuvwxyz \
lego --dns dnsimple --domains my.domain.com --email [email protected] run
```



Expand All @@ -29,7 +32,6 @@ _Please contribute by adding a CLI example._

| Environment Variable Name | Description |
|-----------------------|-------------|
| `DNSIMPLE_BASE_URL` | API endpoint URL |
| `DNSIMPLE_OAUTH_TOKEN` | OAuth token |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
Expand All @@ -40,13 +42,29 @@ More information [here](/lego/dns/#configuration-and-credentials).

| Environment Variable Name | Description |
|--------------------------------|-------------|
| `DNSIMPLE_BASE_URL` | API endpoint URL |
| `DNSIMPLE_POLLING_INTERVAL` | Time between DNS propagation check |
| `DNSIMPLE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `DNSIMPLE_TTL` | The TTL of the TXT record used for the DNS challenge |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here](/lego/dns/#configuration-and-credentials).

## Description

`DNSIMPLE_BASE_URL` is optional and must be set to production (https://api.dnsimple.com).
if `DNSIMPLE_BASE_URL` is not defined or empty, the production URL is used by default.

While you can manage DNS records in the [DNSimple Sandbox environment](https://developer.dnsimple.com/sandbox/),
DNS records will not resolve and you will not be able to satisfy the ACME DNS challenge.

To authenticate you need to provide a valid API token.
HTTP Basic Authentication is intentionally not supported.

### API tokens

You can [generate a new API token](https://support.dnsimple.com/articles/api-access-token/) from your account page.
Only Account API tokens are supported, if you try to use an User API token you will receive an error message.



Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/cenkalti/backoff/v4 v4.0.0
github.com/cloudflare/cloudflare-go v0.10.2
github.com/cpu/goacmedns v0.0.2
github.com/dnsimple/dnsimple-go v0.30.0
github.com/dnsimple/dnsimple-go v0.60.0
github.com/exoscale/egoscale v0.18.1
github.com/google/go-querystring v1.0.0
github.com/gophercloud/gophercloud v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TR
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2 h1:G9/PqfhOrt8JXnw0DGTfVoOkKHDhOlEZqhE/cu+NvQM=
github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/dnsimple/dnsimple-go v0.30.0 h1:IBIrn9jMKRMwporIRwdFyKdnHXVmwy6obnguB+ZMDIY=
github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg=
github.com/dnsimple/dnsimple-go v0.60.0 h1:N+q+ML1CZGf+5r4udu9Opy7WJNtOaFT9aM86Af9gLhk=
github.com/dnsimple/dnsimple-go v0.60.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
17 changes: 9 additions & 8 deletions providers/dns/dnsimple/dnsimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {

ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.AccessToken})
client := dnsimple.NewClient(oauth2.NewClient(context.Background(), ts))
client.SetUserAgent("go-acme/lego")

if config.BaseURL != "" {
client.BaseURL = config.BaseURL
Expand All @@ -98,7 +99,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
}

recordAttributes := newTxtRecord(zoneName, fqdn, value, d.config.TTL)
_, err = d.client.Zones.CreateRecord(accountID, zoneName, recordAttributes)
_, err = d.client.Zones.CreateRecord(context.Background(), accountID, zoneName, recordAttributes)
if err != nil {
return fmt.Errorf("dnsimple: API call failed: %w", err)
}
Expand All @@ -122,7 +123,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {

var lastErr error
for _, rec := range records {
_, err := d.client.Zones.DeleteRecord(accountID, rec.ZoneID, rec.ID)
_, err := d.client.Zones.DeleteRecord(context.Background(), accountID, rec.ZoneID, rec.ID)
if err != nil {
lastErr = fmt.Errorf("dnsimple: %w", err)
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func (d *DNSProvider) getHostedZone(domain string) (string, error) {

zoneName := dns01.UnFqdn(authZone)

zones, err := d.client.Zones.ListZones(accountID, &dnsimple.ZoneListOptions{NameLike: zoneName})
zones, err := d.client.Zones.ListZones(context.Background(), accountID, &dnsimple.ZoneListOptions{NameLike: &zoneName})
if err != nil {
return "", fmt.Errorf("API call failed: %w", err)
}
Expand Down Expand Up @@ -182,20 +183,20 @@ func (d *DNSProvider) findTxtRecords(domain, fqdn string) ([]dnsimple.ZoneRecord

recordName := extractRecordName(fqdn, zoneName)

result, err := d.client.Zones.ListRecords(accountID, zoneName, &dnsimple.ZoneRecordListOptions{Name: recordName, Type: "TXT", ListOptions: dnsimple.ListOptions{}})
result, err := d.client.Zones.ListRecords(context.Background(), accountID, zoneName, &dnsimple.ZoneRecordListOptions{Name: &recordName, Type: dnsimple.String("TXT"), ListOptions: dnsimple.ListOptions{}})
if err != nil {
return nil, fmt.Errorf("API call has failed: %w", err)
}

return result.Data, nil
}

func newTxtRecord(zoneName, fqdn, value string, ttl int) dnsimple.ZoneRecord {
func newTxtRecord(zoneName, fqdn, value string, ttl int) dnsimple.ZoneRecordAttributes {
name := extractRecordName(fqdn, zoneName)

return dnsimple.ZoneRecord{
return dnsimple.ZoneRecordAttributes{
Type: "TXT",
Name: name,
Name: &name,
Content: value,
TTL: ttl,
}
Expand All @@ -210,7 +211,7 @@ func extractRecordName(fqdn, domain string) string {
}

func (d *DNSProvider) getAccountID() (string, error) {
whoamiResponse, err := d.client.Identity.Whoami()
whoamiResponse, err := d.client.Identity.Whoami(context.Background())
if err != nil {
return "", err
}
Expand Down
25 changes: 23 additions & 2 deletions providers/dns/dnsimple/dnsimple.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@ URL = "https://dnsimple.com/"
Code = "dnsimple"
Since = "v0.3.0"

Example = ''''''
Example = '''
DNSIMPLE_OAUTH_TOKEN=1234567890abcdefghijklmnopqrstuvwxyz \
lego --dns dnsimple --domains my.domain.com --email [email protected] run
'''

Additional = '''
## Description
`DNSIMPLE_BASE_URL` is optional and must be set to production (https://api.dnsimple.com).
if `DNSIMPLE_BASE_URL` is not defined or empty, the production URL is used by default.
While you can manage DNS records in the [DNSimple Sandbox environment](https://developer.dnsimple.com/sandbox/),
DNS records will not resolve and you will not be able to satisfy the ACME DNS challenge.
To authenticate you need to provide a valid API token.
HTTP Basic Authentication is intentionally not supported.
### API tokens
You can [generate a new API token](https://support.dnsimple.com/articles/api-access-token/) from your account page.
Only Account API tokens are supported, if you try to use an User API token you will receive an error message.
'''

[Configuration]
[Configuration.Credentials]
DNSIMPLE_OAUTH_TOKEN = "OAuth token"
DNSIMPLE_BASE_URL = "API endpoint URL"
[Configuration.Additional]
DNSIMPLE_BASE_URL = "API endpoint URL"
DNSIMPLE_POLLING_INTERVAL = "Time between DNS propagation check"
DNSIMPLE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
DNSIMPLE_TTL = "The TTL of the TXT record used for the DNS challenge"
Expand Down

0 comments on commit f13a88f

Please sign in to comment.