Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vultr: Switch to official client #929

Merged
merged 6 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@
[[constraint]]
name = "github.com/nrdcg/namesilo"
version = "0.2.0"

[[constraint]]
name = "github.com/vultr/govultr"
version = "0.1.4"
2 changes: 1 addition & 1 deletion docs/content/dns/zz_gen_vultr.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ More information [here](/lego/dns/#configuration-and-credentials).
## More information

- [API documentation](https://www.vultr.com/api/#dns)
- [Go client](https://github.com/JamesClonk/vultr)
- [Go client](https://github.com/vultr/govultr)

<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/vultr/vultr.toml -->
Expand Down
27 changes: 13 additions & 14 deletions providers/dns/vultr/vultr.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Package vultr implements a DNS provider for solving the DNS-01 challenge using the vultr DNS.
// Package vultr implements a DNS provider for solving the DNS-01 challenge using the Vultr DNS.
// See https://www.vultr.com/api/#dns
package vultr

import (
"context"
"crypto/tls"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"

vultr "github.com/JamesClonk/vultr/lib"
"github.com/go-acme/lego/challenge/dns01"
"github.com/go-acme/lego/platform/config/env"
"github.com/vultr/govultr"
)

// Config is used to configure the creation of the DNSProvider
Expand Down Expand Up @@ -43,7 +45,7 @@ func NewDefaultConfig() *Config {
// DNSProvider is an implementation of the acme.ChallengeProvider interface.
type DNSProvider struct {
config *Config
client *vultr.Client
client *govultr.Client
}

// NewDNSProvider returns a DNSProvider instance with a configured Vultr client.
Expand All @@ -70,10 +72,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
return nil, fmt.Errorf("vultr: credentials missing")
}

options := &vultr.Options{
HTTPClient: config.HTTPClient,
}
client := vultr.NewClient(config.APIKey, options)
client := govultr.NewClient(config.HTTPClient, config.APIKey)

return &DNSProvider{client: client, config: config}, nil
}
Expand All @@ -89,7 +88,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {

name := d.extractRecordName(fqdn, zoneDomain)

err = d.client.CreateDNSRecord(zoneDomain, name, "TXT", `"`+value+`"`, 0, d.config.TTL)
err = d.client.DNSRecord.Create(context.Background(), zoneDomain, name, "TXT", value, d.config.TTL, 0)
if err != nil {
return fmt.Errorf("vultr: API call failed: %v", err)
}
Expand All @@ -108,7 +107,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {

var allErr []string
for _, rec := range records {
err := d.client.DeleteDNSRecord(zoneDomain, rec.RecordID)
err := d.client.DNSRecord.Delete(context.Background(), zoneDomain, strconv.Itoa(rec.RecordID))
if err != nil {
allErr = append(allErr, err.Error())
}
Expand All @@ -128,12 +127,12 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
}

func (d *DNSProvider) getHostedZone(domain string) (string, error) {
domains, err := d.client.GetDNSDomains()
domains, err := d.client.DNSDomain.List(context.Background())
if err != nil {
return "", fmt.Errorf("API call failed: %v", err)
}

var hostedDomain vultr.DNSDomain
var hostedDomain govultr.DNSDomain
for _, dom := range domains {
if strings.HasSuffix(domain, dom.Domain) {
if len(dom.Domain) > len(hostedDomain.Domain) {
Expand All @@ -148,14 +147,14 @@ func (d *DNSProvider) getHostedZone(domain string) (string, error) {
return hostedDomain.Domain, nil
}

func (d *DNSProvider) findTxtRecords(domain, fqdn string) (string, []vultr.DNSRecord, error) {
func (d *DNSProvider) findTxtRecords(domain, fqdn string) (string, []govultr.DNSRecord, error) {
zoneDomain, err := d.getHostedZone(domain)
if err != nil {
return "", nil, err
}

var records []vultr.DNSRecord
result, err := d.client.GetDNSRecords(zoneDomain)
var records []govultr.DNSRecord
result, err := d.client.DNSRecord.List(context.Background(), zoneDomain)
if err != nil {
return "", records, fmt.Errorf("API call has failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion providers/dns/vultr/vultr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Example = ''''''

[Links]
API = "https://www.vultr.com/api/#dns"
GoClient = "https://github.com/JamesClonk/vultr"
GoClient = "https://github.com/vultr/govultr"
71 changes: 0 additions & 71 deletions vendor/github.com/JamesClonk/vultr/lib/account_info.go

This file was deleted.

38 changes: 0 additions & 38 deletions vendor/github.com/JamesClonk/vultr/lib/applications.go

This file was deleted.

Loading