forked from superfly/flyctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_domains.go
160 lines (139 loc) · 2.96 KB
/
resource_domains.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
package api
import "context"
func (c *Client) GetDomains(ctx context.Context, organizationSlug string) ([]*Domain, error) {
query := `
query($slug: String!) {
organization(slug: $slug) {
domains {
nodes {
id
name
createdAt
registrationStatus
dnsStatus
autoRenew
expiresAt
}
}
}
}
`
req := c.NewRequest(query)
ctx = ctxWithAction(ctx, "get_domains")
req.Var("slug", organizationSlug)
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return *data.Organization.Domains.Nodes, nil
}
func (c *Client) GetDomain(ctx context.Context, name string) (*Domain, error) {
query := `
query($name: String!) {
domain(name: $name) {
id
name
createdAt
registrationStatus
dnsStatus
autoRenew
expiresAt
zoneNameservers
delegatedNameservers
organization {
id
name
slug
}
}
}
`
req := c.NewRequest(query)
ctx = ctxWithAction(ctx, "get_domain")
req.Var("name", name)
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return data.Domain, nil
}
func (c *Client) CreateDomain(organizationID string, name string) (*Domain, error) {
query := `
mutation($input: CreateDomainInput!) {
createDomain(input: $input) {
domain {
id
name
createdAt
registrationStatus
dnsStatus
autoRenew
expiresAt
}
}
}
`
req := c.NewRequest(query)
ctx := ctxWithAction(context.Background(), "create_domain")
req.Var("input", map[string]interface{}{
"organizationId": organizationID,
"name": name,
})
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return data.CreateDomain.Domain, nil
}
func (c *Client) CheckDomain(ctx context.Context, name string) (*CheckDomainResult, error) {
query := `
mutation($input: CheckDomainInput!) {
checkDomain(input: $input) {
domainName
tld
registrationSupported
registrationAvailable
registrationPrice
registrationPeriod
transferAvailable
dnsAvailable
}
}
`
req := c.NewRequest(query)
ctx = ctxWithAction(ctx, "check_domain")
req.Var("input", map[string]string{"domainName": name})
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return data.CheckDomain, nil
}
func (c *Client) CreateAndRegisterDomain(organizationID string, name string) (*Domain, error) {
query := `
mutation($input: CreateAndRegisterDomainInput!) {
createAndRegisterDomain(input: $input) {
domain {
id
name
createdAt
registrationStatus
dnsStatus
autoRenew
expiresAt
}
}
}
`
req := c.NewRequest(query)
ctx := ctxWithAction(context.Background(), "create_and_register_domain")
req.Var("input", map[string]interface{}{
"organizationId": organizationID,
"name": name,
})
data, err := c.RunWithContext(ctx, req)
if err != nil {
return nil, err
}
return data.CreateAndRegisterDomain.Domain, nil
}