-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
54 lines (48 loc) · 1.28 KB
/
client.go
File metadata and controls
54 lines (48 loc) · 1.28 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package pph
import (
"context"
"fmt"
"os"
"github.com/libdns/libdns"
"github.com/libdns/pph/internal/client"
)
const (
applicationName = "github.com/libdns/pph"
endpointURL = "https://fsn-01.api.pph.sh"
envVarName = "API_TOKEN"
)
func (p *Provider) getClient() *client.PPHClient {
p.client = client.New(p.APIToken, endpointURL)
return p.client
}
func (p *Provider) init(_ context.Context) {
p.once.Do(
func() {
if p.APIToken == "" {
p.APIToken = os.Getenv(envVarName)
}
if p.APIToken == "" {
panic(fmt.Sprintf("%s: API token missing", applicationName))
}
p.client = p.getClient()
},
)
}
func (p *Provider) getRecordsWithDomain(_ context.Context, zone string) (records []libdns.Record, domain client.DomainGet, err error) {
clientRecords, domain, err := p.client.GetRecords(zone)
if err != nil {
return records, domain, fmt.Errorf("invoking GetRecords on client: %w", err)
}
for _, clientRecord := range clientRecords {
record, err := toRecord(zone, clientRecord.Record)
if err != nil {
return records, domain, fmt.Errorf("constructing record %+v: %w", clientRecord, err)
}
if record == nil {
// This skips unsupported Records like PTR's and others
continue
}
records = append(records, record)
}
return records, domain, nil
}