-
Notifications
You must be signed in to change notification settings - Fork 0
/
confs.go
83 lines (62 loc) · 1.73 KB
/
confs.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"strings"
"github.com/namedotcom/go/namecom"
)
type EnvironmentConf struct {
LogLevel string
Domains []string
NameDotComClient *namecom.NameCom
}
type Record struct {
Name string
ID int32
}
func Find(slice []Record, val string) (Record, bool) {
for _, item := range slice {
if item.Name == val {
return item, true
}
}
return Record{}, false
}
func (e *EnvironmentConf) ListDomains() (map[string][]string, error) {
ListDomainsRequest := namecom.ListDomainsRequest{}
ListDomainsResponse, ListDomainsResponseErr := e.NameDotComClient.ListDomains(&ListDomainsRequest)
if ListDomainsResponseErr != nil {
return nil, ListDomainsResponseErr
}
toReturn := make(map[string][]string, len(ListDomainsResponse.Domains))
for _, aDomain := range ListDomainsResponse.Domains {
index := 0
for _, aRecord := range e.Domains {
if strings.HasSuffix(aRecord, aDomain.DomainName) {
if toReturn[aDomain.DomainName] == nil {
toReturn[aDomain.DomainName] = make([]string, len(e.Domains))
}
toReturn[aDomain.DomainName][index] = aRecord
index += 1
}
}
}
return toReturn, nil
}
func (e *EnvironmentConf) ListRecords(aDomain *string) ([]Record, error) {
ListRecordsRequest := namecom.ListRecordsRequest{
DomainName: *aDomain,
}
ListRecordsResponse, ListRecordsErr := e.NameDotComClient.ListRecords(&ListRecordsRequest)
if ListRecordsErr != nil {
return nil, ListRecordsErr
}
recordsFromProvider := make([]Record, len(ListRecordsResponse.Records))
for index, aRecord := range ListRecordsResponse.Records {
if aRecord.Type == "A" {
recordsFromProvider[index] = Record{
Name: aRecord.Fqdn,
ID: aRecord.ID,
}
}
}
return recordsFromProvider, nil
}