-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclient.go
More file actions
38 lines (33 loc) · 996 Bytes
/
client.go
File metadata and controls
38 lines (33 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package dreamhost
import (
"strings"
"github.com/adamantal/go-dreamhost/api"
"github.com/libdns/libdns"
)
func (p *Provider) init() error {
client, err := api.NewClient(p.APIKey, nil)
if err != nil {
return err
}
p.client = *client
return nil
}
func recordFromApiDnsRecord(apiDnsRecord api.DNSRecord) libdns.Record {
rec, _ := libdns.RR{
Type: string(apiDnsRecord.Type),
Data: apiDnsRecord.Value,
// We need to get the name minus the zone to match what libdns expects
Name: libdns.RelativeName(apiDnsRecord.Record, apiDnsRecord.Zone),
}.Parse()
return rec
}
func apiDnsRecordInputFromRecord(record libdns.Record, zone string) api.DNSRecordInput {
rr := record.RR()
var recordInput api.DNSRecordInput
recordInput.Type = api.RecordType(rr.Type)
recordInput.Value = rr.Data
// Dreamhost expects the record name to be absolute, without a dot at the end
zone = strings.TrimRight(zone, ".")
recordInput.Record = libdns.AbsoluteName(rr.Name, zone)
return recordInput
}