-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain.go
165 lines (132 loc) · 4.47 KB
/
domain.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package api
import (
"context"
"strings"
"time"
"github.com/asaskevich/govalidator"
"github.com/moonrhythm/validator"
)
type Domain interface {
Create(ctx context.Context, m *DomainCreate) (*Empty, error)
Get(ctx context.Context, m *DomainGet) (*DomainItem, error)
List(ctx context.Context, m *DomainList) (*DomainListResult, error)
Delete(ctx context.Context, m *DomainDelete) (*Empty, error)
PurgeCache(ctx context.Context, m *DomainPurgeCache) (*Empty, error)
}
type DomainCreate struct {
Project string `json:"project" yaml:"project"`
Location string `json:"location" yaml:"location"`
Domain string `json:"domain" yaml:"domain"`
Wildcard bool `json:"wildcard" yaml:"wildcard"`
CDN bool `json:"cdn" yaml:"cdn"`
Type DomainType `json:"type" yaml:"type"` // deprecated
}
func (m *DomainCreate) Valid() error {
v := validator.New()
v.Must(m.Project != "", "project required")
v.Must(m.Location != "", "location required")
v.Must(govalidator.IsDNSName(m.Domain), "domain invalid")
v.Must(!strings.HasSuffix(m.Domain, ".deploys.app"), "domain invalid")
return WrapValidate(v)
}
type DomainGet struct {
Project string `json:"project" yaml:"project"`
Domain string `json:"domain" yaml:"domain"`
}
func (m *DomainGet) Valid() error {
v := validator.New()
v.Must(m.Project != "", "project required")
v.Must(govalidator.IsDNSName(m.Domain), "domain invalid")
return WrapValidate(v)
}
type DomainList struct {
Project string `json:"project" yaml:"project"`
Location string `json:"location" yaml:"location"`
}
func (m *DomainList) Valid() error {
v := validator.New()
v.Must(m.Project != "", "project required")
return WrapValidate(v)
}
type DomainListResult struct {
Items []*DomainItem `json:"items" yaml:"items"`
}
func (m *DomainListResult) Table() [][]string {
table := [][]string{
{"DOMAIN", "LOCATION"},
}
for _, x := range m.Items {
table = append(table, []string{
x.Domain,
x.Location,
})
}
return table
}
type DomainItem struct {
Project string `json:"project" yaml:"project"`
Location string `json:"location" yaml:"location"`
Domain string `json:"domain" yaml:"domain"`
Type DomainType `json:"type" yaml:"type"` // deprecated
Wildcard bool `json:"wildcard" yaml:"wildcard"`
CDN bool `json:"cdn" yaml:"cdn"`
Verification DomainVerification `json:"verification" yaml:"verification"`
DNSConfig DomainDNSConfig `json:"dnsConfig" yaml:"dnsConfig"`
Status DomainStatus `json:"status" yaml:"status"`
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
CreatedBy string `json:"createdBy" yaml:"createdBy"`
}
type DomainVerification struct {
Ownership DomainVerificationOwnership `json:"ownership"`
SSL DomainVerificationSSL `json:"ssl"`
}
type DomainVerificationOwnership struct {
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
Errors []string `json:"errors"`
}
type DomainVerificationSSL struct {
Pending bool `json:"pending"`
DCV DomainVerificationSSLDCV `json:"dcv"`
Records []DomainVerificationSSLRecord `json:"records"`
Errors []string `json:"errors"`
}
type DomainVerificationSSLDCV struct {
Name string `json:"name"`
Value string `json:"value"`
}
type DomainVerificationSSLRecord struct {
TxtName string `json:"txtName"`
TxtValue string `json:"txtValue"`
}
type DomainDNSConfig struct {
IPv4 []string `json:"ipv4" yaml:"ipv4"`
IPv6 []string `json:"ipv6" yaml:"ipv6"`
CName []string `json:"cname" yaml:"cname"`
}
type DomainDelete struct {
Project string `json:"project" yaml:"project"`
Domain string `json:"domain" yaml:"domain"`
}
func (m *DomainDelete) Valid() error {
v := validator.New()
v.Must(m.Project != "", "project required")
v.Must(govalidator.IsDNSName(m.Domain), "domain invalid")
return WrapValidate(v)
}
type DomainPurgeCache struct {
Project string `json:"project" yaml:"project"`
Domain string `json:"domain" yaml:"domain"`
File string `json:"file" yaml:"file"`
Prefix string `json:"prefix" yaml:"prefix"`
}
func (m *DomainPurgeCache) Valid() error {
v := validator.New()
m.Domain = strings.TrimSpace(m.Domain)
m.File = strings.TrimSpace(m.File)
m.Prefix = strings.TrimSpace(m.Prefix)
v.Must(m.Project != "", "project required")
v.Must(govalidator.IsDNSName(m.Domain), "domain invalid")
return WrapValidate(v)
}