forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
certificates.go
65 lines (47 loc) · 1.08 KB
/
certificates.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
package client
import (
"fmt"
"strings"
"time"
)
type Certificate struct {
Id string `json:"id"`
Domain string `json:"domain"`
Expiration time.Time `json:"expiration"`
}
type Certificates []Certificate
func (c *Client) CreateCertificate(pub, key, chain string) (*Certificate, error) {
var cert Certificate
params := Params{
"public": pub,
"private": key,
"chain": chain,
}
err := c.Post("/certificates", params, &cert)
if err != nil {
return nil, err
}
return &cert, nil
}
func (c *Client) DeleteCertificate(id string) error {
return c.Delete(fmt.Sprintf("/certificates/%s", id), nil)
}
func (c *Client) GenerateCertificate(domains []string) (*Certificate, error) {
var cert Certificate
params := Params{
"domains": strings.Join(domains, ","),
}
err := c.Post("/certificates/generate", params, &cert)
if err != nil {
return nil, err
}
return &cert, nil
}
func (c *Client) ListCertificates() (Certificates, error) {
var certs Certificates
err := c.Get("/certificates", &certs)
if err != nil {
return nil, err
}
return certs, nil
}