forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh_policy_client.sk.go
118 lines (99 loc) · 3.22 KB
/
mesh_policy_client.sk.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Code generated by solo-kit. DO NOT EDIT.
package v1alpha1
import (
"github.com/solo-io/solo-kit/pkg/api/v1/clients"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/factory"
"github.com/solo-io/solo-kit/pkg/api/v1/resources"
"github.com/solo-io/solo-kit/pkg/errors"
)
type MeshPolicyClient interface {
BaseClient() clients.ResourceClient
Register() error
Read(name string, opts clients.ReadOpts) (*MeshPolicy, error)
Write(resource *MeshPolicy, opts clients.WriteOpts) (*MeshPolicy, error)
Delete(name string, opts clients.DeleteOpts) error
List(opts clients.ListOpts) (MeshPolicyList, error)
Watch(opts clients.WatchOpts) (<-chan MeshPolicyList, <-chan error, error)
}
type meshPolicyClient struct {
rc clients.ResourceClient
}
func NewMeshPolicyClient(rcFactory factory.ResourceClientFactory) (MeshPolicyClient, error) {
return NewMeshPolicyClientWithToken(rcFactory, "")
}
func NewMeshPolicyClientWithToken(rcFactory factory.ResourceClientFactory, token string) (MeshPolicyClient, error) {
rc, err := rcFactory.NewResourceClient(factory.NewResourceClientParams{
ResourceType: &MeshPolicy{},
Token: token,
})
if err != nil {
return nil, errors.Wrapf(err, "creating base MeshPolicy resource client")
}
return NewMeshPolicyClientWithBase(rc), nil
}
func NewMeshPolicyClientWithBase(rc clients.ResourceClient) MeshPolicyClient {
return &meshPolicyClient{
rc: rc,
}
}
func (client *meshPolicyClient) BaseClient() clients.ResourceClient {
return client.rc
}
func (client *meshPolicyClient) Register() error {
return client.rc.Register()
}
func (client *meshPolicyClient) Read(name string, opts clients.ReadOpts) (*MeshPolicy, error) {
opts = opts.WithDefaults()
resource, err := client.rc.Read("", name, opts)
if err != nil {
return nil, err
}
return resource.(*MeshPolicy), nil
}
func (client *meshPolicyClient) Write(meshPolicy *MeshPolicy, opts clients.WriteOpts) (*MeshPolicy, error) {
opts = opts.WithDefaults()
resource, err := client.rc.Write(meshPolicy, opts)
if err != nil {
return nil, err
}
return resource.(*MeshPolicy), nil
}
func (client *meshPolicyClient) Delete(name string, opts clients.DeleteOpts) error {
opts = opts.WithDefaults()
return client.rc.Delete("", name, opts)
}
func (client *meshPolicyClient) List(opts clients.ListOpts) (MeshPolicyList, error) {
opts = opts.WithDefaults()
resourceList, err := client.rc.List("", opts)
if err != nil {
return nil, err
}
return convertToMeshPolicy(resourceList), nil
}
func (client *meshPolicyClient) Watch(opts clients.WatchOpts) (<-chan MeshPolicyList, <-chan error, error) {
opts = opts.WithDefaults()
resourcesChan, errs, initErr := client.rc.Watch("", opts)
if initErr != nil {
return nil, nil, initErr
}
meshpoliciesChan := make(chan MeshPolicyList)
go func() {
for {
select {
case resourceList := <-resourcesChan:
meshpoliciesChan <- convertToMeshPolicy(resourceList)
case <-opts.Ctx.Done():
close(meshpoliciesChan)
return
}
}
}()
return meshpoliciesChan, errs, nil
}
func convertToMeshPolicy(resources resources.ResourceList) MeshPolicyList {
var meshPolicyList MeshPolicyList
for _, resource := range resources {
meshPolicyList = append(meshPolicyList, resource.(*MeshPolicy))
}
return meshPolicyList
}