...
1
16
17 package resource
18
19 import (
20 "k8s.io/apimachinery/pkg/api/meta"
21 "k8s.io/apimachinery/pkg/types"
22 "k8s.io/client-go/discovery"
23 "k8s.io/client-go/rest"
24 "k8s.io/client-go/restmapper"
25 )
26
27 type RESTClientGetter interface {
28 ToRESTConfig() (*rest.Config, error)
29 ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
30 ToRESTMapper() (meta.RESTMapper, error)
31 }
32
33 type ClientConfigFunc func() (*rest.Config, error)
34 type RESTMapperFunc func() (meta.RESTMapper, error)
35 type CategoryExpanderFunc func() (restmapper.CategoryExpander, error)
36
37
38
39 type RESTClient interface {
40 Get() *rest.Request
41 Post() *rest.Request
42 Patch(types.PatchType) *rest.Request
43 Delete() *rest.Request
44 Put() *rest.Request
45 }
46
47
48 type RequestTransform func(*rest.Request)
49
50
51
52 func NewClientWithOptions(c RESTClient, transforms ...RequestTransform) RESTClient {
53 if len(transforms) == 0 {
54 return c
55 }
56 return &clientOptions{c: c, transforms: transforms}
57 }
58
59 type clientOptions struct {
60 c RESTClient
61 transforms []RequestTransform
62 }
63
64 func (c *clientOptions) modify(req *rest.Request) *rest.Request {
65 for _, transform := range c.transforms {
66 transform(req)
67 }
68 return req
69 }
70
71 func (c *clientOptions) Get() *rest.Request {
72 return c.modify(c.c.Get())
73 }
74
75 func (c *clientOptions) Post() *rest.Request {
76 return c.modify(c.c.Post())
77 }
78 func (c *clientOptions) Patch(t types.PatchType) *rest.Request {
79 return c.modify(c.c.Patch(t))
80 }
81 func (c *clientOptions) Delete() *rest.Request {
82 return c.modify(c.c.Delete())
83 }
84 func (c *clientOptions) Put() *rest.Request {
85 return c.modify(c.c.Put())
86 }
87
88
89 type ContentValidator interface {
90 ValidateBytes(data []byte) error
91 }
92
93
94 type Visitor interface {
95 Visit(VisitorFunc) error
96 }
97
98
99
100
101
102
103 type VisitorFunc func(*Info, error) error
104
View as plain text