Stop custom Client struct from being exported in Provider
This commit is contained in:
parent
120fee4266
commit
77ddd0389e
32
client.go
32
client.go
@ -6,31 +6,31 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/vultr/govultr"
|
|
||||||
"github.com/libdns/libdns"
|
"github.com/libdns/libdns"
|
||||||
|
"github.com/vultr/govultr"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
client *govultr.Client
|
vultr *govultr.Client
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getClient() error {
|
func (p *Provider) getClient() error {
|
||||||
if p.client == nil {
|
if p.client.vultr == nil {
|
||||||
p.client = govultr.NewClient(nil, p.APIToken)
|
p.client.vultr = govultr.NewClient(nil, p.APIToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.Record, error) {
|
func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.Record, error) {
|
||||||
p.mutex.Lock()
|
p.client.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.client.mutex.Unlock()
|
||||||
|
|
||||||
p.getClient()
|
p.getClient()
|
||||||
|
|
||||||
var records []libdns.Record
|
var records []libdns.Record
|
||||||
dns_entries, err := p.client.DNSRecord.List(ctx, domain)
|
dns_entries, err := p.client.vultr.DNSRecord.List(ctx, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return records, err
|
return records, err
|
||||||
}
|
}
|
||||||
@ -50,12 +50,12 @@ func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) addDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
func (p *Provider) addDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||||
p.mutex.Lock()
|
p.client.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.client.mutex.Unlock()
|
||||||
|
|
||||||
p.getClient()
|
p.getClient()
|
||||||
|
|
||||||
err := p.client.DNSRecord.Create(ctx, domain, record.Type, record.Name, record.Value, int(record.TTL.Seconds()), 0)
|
err := p.client.vultr.DNSRecord.Create(ctx, domain, record.Type, record.Name, record.Value, int(record.TTL.Seconds()), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return record, err
|
return record, err
|
||||||
}
|
}
|
||||||
@ -64,12 +64,12 @@ func (p *Provider) addDNSRecord(ctx context.Context, domain string, record libdn
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||||
p.mutex.Lock()
|
p.client.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.client.mutex.Unlock()
|
||||||
|
|
||||||
p.getClient()
|
p.getClient()
|
||||||
|
|
||||||
err := p.client.DNSRecord.Delete(ctx, domain, record.ID)
|
err := p.client.vultr.DNSRecord.Delete(ctx, domain, record.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return record, err
|
return record, err
|
||||||
}
|
}
|
||||||
@ -78,8 +78,8 @@ func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record li
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record libdns.Record) (libdns.Record, error) {
|
||||||
p.mutex.Lock()
|
p.client.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.client.mutex.Unlock()
|
||||||
|
|
||||||
p.getClient()
|
p.getClient()
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record li
|
|||||||
RecordID: id,
|
RecordID: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.client.DNSRecord.Update(ctx, domain, &entry)
|
err = p.client.vultr.DNSRecord.Update(ctx, domain, &entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return record, err
|
return record, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
// Provider implements the libdns interfaces for Vultr
|
// Provider implements the libdns interfaces for Vultr
|
||||||
// Adapted from libdns/digitalocean to work with the Vultr API
|
// Adapted from libdns/digitalocean to work with the Vultr API
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
Client
|
client Client
|
||||||
// APIToken is the Vultr API token
|
// APIToken is the Vultr API token
|
||||||
// see https://my.vultr.com/settings/#settingsapi
|
// see https://my.vultr.com/settings/#settingsapi
|
||||||
APIToken string `json:"auth_token"`
|
APIToken string `json:"auth_token"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user