forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ca.go
46 lines (38 loc) · 900 Bytes
/
ca.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
package aiven
import (
"encoding/json"
"errors"
)
type (
// CAHandler is the client which interacts with the Projects CA endpoint
// on Aiven.
CAHandler struct {
client *Client
}
// ProjectCAResponse is the response from Aiven for project CA Certificate.
ProjectCAResponse struct {
APIResponse
CACertificate string `json:"certificate"`
}
)
// Get gets the specified Project CA Certificate
func (h *CAHandler) Get(project string) (string, error) {
bts, err := h.client.doGetRequest("/project/"+project+"/kms/ca", nil)
if err != nil {
return "", err
}
if bts == nil {
return "", ErrNoResponseData
}
var rsp *ProjectCAResponse
if err := json.Unmarshal(bts, &rsp); err != nil {
return "", err
}
if rsp == nil {
return "", ErrNoResponseData
}
if rsp.Errors != nil && len(rsp.Errors) != 0 {
return "", errors.New(rsp.Message)
}
return rsp.CACertificate, nil
}