-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
51 lines (39 loc) · 1.05 KB
/
client.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
package httpclient
import (
"errors"
"fmt"
"github.com/dpb587/ssoca/httpclient"
"github.com/dpb587/ssoca/service/ssh/api"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
func New(client *httpclient.Client, service string) (*Client, error) {
if client == nil {
return nil, errors.New("client is nil")
}
return &Client{
client: client,
service: service,
}, nil
}
type Client struct {
client *httpclient.Client
service string
}
func (c Client) GetCAPublicKey() (api.CAPublicKeyResponse, error) {
out := api.CAPublicKeyResponse{}
path := fmt.Sprintf("/%s/ca-public-key", c.service)
err := c.client.APIGet(path, &out)
if err != nil {
return out, bosherr.WrapErrorf(err, "Getting %s", path)
}
return out, nil
}
func (c Client) PostSignPublicKey(in api.SignPublicKeyRequest) (api.SignPublicKeyResponse, error) {
out := api.SignPublicKeyResponse{}
path := fmt.Sprintf("/%s/sign-public-key", c.service)
err := c.client.APIPost(path, &out, in)
if err != nil {
return out, bosherr.WrapErrorf(err, "Posting %s", path)
}
return out, nil
}