-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal_policy_client.go
56 lines (49 loc) · 1.39 KB
/
internal_policy_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
52
53
54
55
56
package policy_client
import (
"errors"
"policy-server/api"
"strings"
"code.cloudfoundry.org/cf-networking-helpers/json_client"
"code.cloudfoundry.org/lager"
)
type InternalClient struct {
JsonClient json_client.JsonClient
}
func NewInternal(logger lager.Logger, httpClient json_client.HttpClient, baseURL string) *InternalClient {
return &InternalClient{
JsonClient: json_client.New(logger, httpClient, baseURL),
}
}
func (c *InternalClient) GetPolicies() ([]api.Policy, error) {
var policies struct {
Policies []api.Policy `json:"policies"`
}
err := c.JsonClient.Do("GET", "/networking/v1/internal/policies", nil, &policies, "")
if err != nil {
return nil, err
}
return policies.Policies, nil
}
func (c *InternalClient) GetPoliciesByID(ids ...string) ([]api.Policy, error) {
var policies struct {
Policies []api.Policy `json:"policies"`
}
if len(ids) == 0 {
return nil, errors.New("ids cannot be empty")
}
err := c.JsonClient.Do("GET", "/networking/v1/internal/policies?id="+strings.Join(ids, ","), nil, &policies, "")
if err != nil {
return nil, err
}
return policies.Policies, nil
}
func (c *InternalClient) HealthCheck() (bool, error) {
var healthcheck struct {
Healthcheck bool `json:"healthcheck"`
}
err := c.JsonClient.Do("GET", "/networking/v1/internal/healthcheck", nil, &healthcheck, "")
if err != nil {
return false, err
}
return healthcheck.Healthcheck, nil
}