-
Notifications
You must be signed in to change notification settings - Fork 1
/
domain.go
76 lines (63 loc) · 1.61 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
package go_certcentral
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"time"
)
const domainURL = "/domain"
type Domain struct {
ID int `json:"id"`
Name string `json:"name"`
IsActive bool `json:"is_active,omitempty"`
DateCreated *time.Time `json:"date_created,omitempty"`
Organization *Organization `json:"organization,omitempty"`
Validations []Validation `json:"validations,omitempty"`
DCV *DCV `json:"dcv,omitempty"`
Container *Container `json:"container,omitempty"`
}
func (c *Client) ListDomains(containerID string) ([]Domain, error) {
if containerID == "" {
return nil, errors.New("cannot list domains without container ID")
}
req, err := http.NewRequest(http.MethodGet, makeURL(domainURL, "?container_id", containerID), nil)
if err != nil {
return nil, err
}
res, err := c.do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
type data struct {
Domains []Domain `json:"domains"`
}
var d data
err = json.Unmarshal(resBody, &d)
return d.Domains, err
}
func (c *Client) GetDomain(domainID string) (*Domain, error) {
req, err := http.NewRequest(
http.MethodGet, makeURL(domainURL, domainID, "include_dcv=true&include_validation=true"), nil,
)
if err != nil {
return nil, err
}
res, err := c.do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
var d Domain
err = json.Unmarshal(resBody, &d)
return &d, err
}