-
Notifications
You must be signed in to change notification settings - Fork 7
/
abstract.go
146 lines (127 loc) · 3.16 KB
/
abstract.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package godaddygo
import (
"context"
)
// API knows which version to target
type API interface {
V1() V1
V2() V2
}
// V1 knows how to interact with GoDaddy Gateway version 1
type V1 interface {
Domain(name string) Domain
ListDomains(ctx context.Context) ([]DomainSummary, error)
CheckAvailability(ctx context.Context, name string, forTransfer bool) (DomainAvailability, error)
PurchaseDomain(ctx context.Context, dom DomainDetails) error
}
// V2 knows how to interact with GoDaddy Gateway version 2
type V2 interface{}
// Domain knows how to interact with the Domains GoDaddy Gateway endpoint
type Domain interface {
Records() Records
GetDetails(ctx context.Context) (*DomainDetails, error)
}
// Records knows how to interact with the Records GoDaddy Gateway endpoint
type Records interface {
List(ctx context.Context) ([]Record, error)
Add(ctx context.Context, rec []Record) error
FindByType(ctx context.Context, t RecordType) ([]Record, error)
FindByTypeAndName(ctx context.Context, t RecordType, n string) ([]Record, error)
ReplaceByType(ctx context.Context, t RecordType, rec []Record) error
ReplaceByTypeAndName(ctx context.Context, t RecordType, n string, rec Record) error
Update(ctx context.Context, rec []Record) error
Delete(ctx context.Context, rec Record) error
}
//
// APIEnv represents which endpoint to target (dev|prod)
//
type APIEnv string
func (e APIEnv) String() string {
switch e {
case APIProdEnv:
return "prod"
case APIDevEnv:
return "dev"
default:
return ""
}
}
// IsValid determines whether or not the given api env is valid
func (e APIEnv) IsValid() bool {
return e.String() != ""
}
//
// APIVersion represents which endpoint version to target (v1|v2)
//
type APIVersion string
func (v APIVersion) String() string {
switch v {
case APIVersion1:
return "v1"
case APIVersion2:
return "v2"
default:
return ""
}
}
// IsValid determines whether or not the given api version is valid
func (v APIVersion) IsValid() bool {
return v.String() != ""
}
//
// APIURL represents which URL to target
//
type APIURL string
func (u APIURL) String() string {
switch u {
case prodbaseURL:
return "https://api.godaddy.com"
case devbaseURL:
return "https://api.ote-godaddy.com"
default:
return ""
}
}
// IsValid determines whether or not the given api url is valid
func (u APIURL) IsValid() bool {
return u.String() != ""
}
//
// RecordType represents a DNS record type
//
type RecordType string
func (r RecordType) String() string {
switch r {
case RecordTypeA:
return "A"
case RecordTypeAAAA:
return "AAAA"
case RecordTypeCNAME:
return "CNAME"
case RecordTypeMX:
return "MX"
case RecordTypeNS:
return "NS"
case RecordTypeSOA:
return "SOA"
case RecordTypeSRV:
return "SRV"
case RecordTypeTXT:
return "TXT"
default:
return ""
}
}
// IsDeletable determines if the given record can be deleted or not
func (r RecordType) IsDeletable() bool {
switch r {
case RecordTypeA, RecordTypeAAAA, RecordTypeCNAME, RecordTypeMX, RecordTypeSRV, RecordTypeTXT:
return true
default:
return false
}
}
// IsValid determines whether or not the given dns recorsd type is valid
func (r RecordType) IsValid() bool {
return r.String() != ""
}