forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
377 lines (317 loc) · 11.2 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package client
import (
"fmt"
"os"
"path"
"runtime"
"strings"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/version"
)
// Interface exposes methods on OpenShift resources.
type Interface interface {
BuildsNamespacer
BuildConfigsNamespacer
BuildLogsNamespacer
ImagesInterfacer
ImageSignaturesInterfacer
ImageStreamsNamespacer
ImageStreamMappingsNamespacer
ImageStreamTagsNamespacer
ImageStreamImagesNamespacer
ImageStreamSecretsNamespacer
DeploymentConfigsNamespacer
DeploymentLogsNamespacer
RoutesNamespacer
HostSubnetsInterface
NetNamespacesInterface
ClusterNetworkingInterface
EgressNetworkPoliciesNamespacer
IdentitiesInterface
UsersInterface
GroupsInterface
UserIdentityMappingsInterface
ProjectsInterface
ProjectRequestsInterface
LocalSubjectAccessReviewsImpersonator
SubjectAccessReviewsImpersonator
LocalResourceAccessReviewsNamespacer
ResourceAccessReviews
SubjectAccessReviews
LocalSubjectAccessReviewsNamespacer
SelfSubjectRulesReviewsNamespacer
SubjectRulesReviewsNamespacer
TemplatesNamespacer
TemplateConfigsNamespacer
OAuthClientsInterface
OAuthClientAuthorizationsInterface
OAuthAccessTokensInterface
OAuthAuthorizeTokensInterface
PoliciesNamespacer
PolicyBindingsNamespacer
RolesNamespacer
RoleBindingsNamespacer
ClusterPoliciesInterface
ClusterPolicyBindingsInterface
ClusterRolesInterface
ClusterRoleBindingsInterface
ClusterResourceQuotasInterface
AppliedClusterResourceQuotasNamespacer
RoleBindingRestrictionsNamespacer
}
// Builds provides a REST client for Builds
func (c *Client) Builds(namespace string) BuildInterface {
return newBuilds(c, namespace)
}
// BuildConfigs provides a REST client for BuildConfigs
func (c *Client) BuildConfigs(namespace string) BuildConfigInterface {
return newBuildConfigs(c, namespace)
}
// BuildLogs provides a REST client for BuildLogs
func (c *Client) BuildLogs(namespace string) BuildLogsInterface {
return newBuildLogs(c, namespace)
}
// Images provides a REST client for Images
func (c *Client) Images() ImageInterface {
return newImages(c)
}
// ImageSignatures provides a REST client for ImageSignatures
func (c *Client) ImageSignatures() ImageSignatureInterface {
return newImageSignatures(c)
}
// ImageStreamImages provides a REST client for retrieving image secrets in a namespace
func (c *Client) ImageStreamSecrets(namespace string) ImageStreamSecretInterface {
return newImageStreamSecrets(c, namespace)
}
// ImageStreams provides a REST client for ImageStream
func (c *Client) ImageStreams(namespace string) ImageStreamInterface {
return newImageStreams(c, namespace)
}
// ImageStreamMappings provides a REST client for ImageStreamMapping
func (c *Client) ImageStreamMappings(namespace string) ImageStreamMappingInterface {
return newImageStreamMappings(c, namespace)
}
// ImageStreamTags provides a REST client for ImageStreamTag
func (c *Client) ImageStreamTags(namespace string) ImageStreamTagInterface {
return newImageStreamTags(c, namespace)
}
// ImageStreamImages provides a REST client for ImageStreamImage
func (c *Client) ImageStreamImages(namespace string) ImageStreamImageInterface {
return newImageStreamImages(c, namespace)
}
// DeploymentConfigs provides a REST client for DeploymentConfig
func (c *Client) DeploymentConfigs(namespace string) DeploymentConfigInterface {
return newDeploymentConfigs(c, namespace)
}
// DeploymentLogs provides a REST client for DeploymentLog
func (c *Client) DeploymentLogs(namespace string) DeploymentLogInterface {
return newDeploymentLogs(c, namespace)
}
// Routes provides a REST client for Route
func (c *Client) Routes(namespace string) RouteInterface {
return newRoutes(c, namespace)
}
// HostSubnets provides a REST client for HostSubnet
func (c *Client) HostSubnets() HostSubnetInterface {
return newHostSubnet(c)
}
// NetNamespaces provides a REST client for NetNamespace
func (c *Client) NetNamespaces() NetNamespaceInterface {
return newNetNamespace(c)
}
// ClusterNetwork provides a REST client for ClusterNetworking
func (c *Client) ClusterNetwork() ClusterNetworkInterface {
return newClusterNetwork(c)
}
// EgressNetworkPolicies provides a REST client for EgressNetworkPolicy
func (c *Client) EgressNetworkPolicies(namespace string) EgressNetworkPolicyInterface {
return newEgressNetworkPolicy(c, namespace)
}
// Users provides a REST client for User
func (c *Client) Users() UserInterface {
return newUsers(c)
}
// Identities provides a REST client for Identity
func (c *Client) Identities() IdentityInterface {
return newIdentities(c)
}
// UserIdentityMappings provides a REST client for UserIdentityMapping
func (c *Client) UserIdentityMappings() UserIdentityMappingInterface {
return newUserIdentityMappings(c)
}
// Groups provides a REST client for Groups
func (c *Client) Groups() GroupInterface {
return newGroups(c)
}
// Projects provides a REST client for Projects
func (c *Client) Projects() ProjectInterface {
return newProjects(c)
}
// ProjectRequests provides a REST client for Projects
func (c *Client) ProjectRequests() ProjectRequestInterface {
return newProjectRequests(c)
}
// TemplateConfigs provides a REST client for TemplateConfig
func (c *Client) TemplateConfigs(namespace string) TemplateConfigInterface {
return newTemplateConfigs(c, namespace)
}
// Templates provides a REST client for Templates
func (c *Client) Templates(namespace string) TemplateInterface {
return newTemplates(c, namespace)
}
// Policies provides a REST client for Policies
func (c *Client) Policies(namespace string) PolicyInterface {
return newPolicies(c, namespace)
}
// PolicyBindings provides a REST client for PolicyBindings
func (c *Client) PolicyBindings(namespace string) PolicyBindingInterface {
return newPolicyBindings(c, namespace)
}
// Roles provides a REST client for Roles
func (c *Client) Roles(namespace string) RoleInterface {
return newRoles(c, namespace)
}
// RoleBindings provides a REST client for RoleBindings
func (c *Client) RoleBindings(namespace string) RoleBindingInterface {
return newRoleBindings(c, namespace)
}
// LocalResourceAccessReviews provides a REST client for LocalResourceAccessReviews
func (c *Client) LocalResourceAccessReviews(namespace string) LocalResourceAccessReviewInterface {
return newLocalResourceAccessReviews(c, namespace)
}
// ClusterResourceAccessReviews provides a REST client for ClusterResourceAccessReviews
func (c *Client) ResourceAccessReviews() ResourceAccessReviewInterface {
return newResourceAccessReviews(c)
}
// ImpersonateSubjectAccessReviews provides a REST client for SubjectAccessReviews
func (c *Client) ImpersonateSubjectAccessReviews(token string) SubjectAccessReviewInterface {
return newImpersonatingSubjectAccessReviews(c, token)
}
// ImpersonateLocalSubjectAccessReviews provides a REST client for SubjectAccessReviews
func (c *Client) ImpersonateLocalSubjectAccessReviews(namespace, token string) LocalSubjectAccessReviewInterface {
return newImpersonatingLocalSubjectAccessReviews(c, namespace, token)
}
// LocalSubjectAccessReviews provides a REST client for LocalSubjectAccessReviews
func (c *Client) LocalSubjectAccessReviews(namespace string) LocalSubjectAccessReviewInterface {
return newLocalSubjectAccessReviews(c, namespace)
}
// SubjectAccessReviews provides a REST client for SubjectAccessReviews
func (c *Client) SubjectAccessReviews() SubjectAccessReviewInterface {
return newSubjectAccessReviews(c)
}
func (c *Client) SelfSubjectRulesReviews(namespace string) SelfSubjectRulesReviewInterface {
return newSelfSubjectRulesReviews(c, namespace)
}
func (c *Client) SubjectRulesReviews(namespace string) SubjectRulesReviewInterface {
return newSubjectRulesReviews(c, namespace)
}
func (c *Client) OAuthClients() OAuthClientInterface {
return newOAuthClients(c)
}
func (c *Client) OAuthClientAuthorizations() OAuthClientAuthorizationInterface {
return newOAuthClientAuthorizations(c)
}
func (c *Client) OAuthAccessTokens() OAuthAccessTokenInterface {
return newOAuthAccessTokens(c)
}
func (c *Client) OAuthAuthorizeTokens() OAuthAuthorizeTokenInterface {
return newOAuthAuthorizeTokens(c)
}
func (c *Client) ClusterPolicies() ClusterPolicyInterface {
return newClusterPolicies(c)
}
func (c *Client) ClusterPolicyBindings() ClusterPolicyBindingInterface {
return newClusterPolicyBindings(c)
}
func (c *Client) ClusterRoles() ClusterRoleInterface {
return newClusterRoles(c)
}
func (c *Client) ClusterRoleBindings() ClusterRoleBindingInterface {
return newClusterRoleBindings(c)
}
func (c *Client) ClusterResourceQuotas() ClusterResourceQuotaInterface {
return newClusterResourceQuotas(c)
}
func (c *Client) AppliedClusterResourceQuotas(namespace string) AppliedClusterResourceQuotaInterface {
return newAppliedClusterResourceQuotas(c, namespace)
}
func (c *Client) RoleBindingRestrictions(namespace string) RoleBindingRestrictionInterface {
return newRoleBindingRestrictions(c, namespace)
}
// Client is an OpenShift client object
type Client struct {
*restclient.RESTClient
}
// New creates an OpenShift client for the given config. This client works with builds, deployments,
// templates, routes, and images. It allows operations such as list, get, update and delete on these
// objects. An error is returned if the provided configuration is not valid.
func New(c *restclient.Config) (*Client, error) {
config := *c
if err := SetOpenShiftDefaults(&config); err != nil {
return nil, err
}
client, err := restclient.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &Client{client}, nil
}
// DiscoveryClient returns a discovery client.
func (c *Client) Discovery() discovery.DiscoveryInterface {
d := NewDiscoveryClient(c.RESTClient)
return d
}
// SetOpenShiftDefaults sets the default settings on the passed
// client configuration
func SetOpenShiftDefaults(config *restclient.Config) error {
if len(config.UserAgent) == 0 {
config.UserAgent = DefaultOpenShiftUserAgent()
}
if config.GroupVersion == nil {
// Clients default to the preferred code API version
groupVersionCopy := latest.Version
config.GroupVersion = &groupVersionCopy
}
if config.APIPath == "" {
config.APIPath = "/oapi"
}
if config.NegotiatedSerializer == nil {
config.NegotiatedSerializer = kapi.Codecs
}
return nil
}
// NewOrDie creates an OpenShift client and panics if the provided API version is not recognized.
func NewOrDie(c *restclient.Config) *Client {
client, err := New(c)
if err != nil {
panic(err)
}
return client
}
// DefaultOpenShiftUserAgent returns the default user agent that clients can use.
func DefaultOpenShiftUserAgent() string {
commit := version.Get().GitCommit
if len(commit) > 7 {
commit = commit[:7]
}
if len(commit) == 0 {
commit = "unknown"
}
version := version.Get().GitVersion
seg := strings.SplitN(version, "-", 2)
version = seg[0]
return fmt.Sprintf("%s/%s (%s/%s) openshift/%s", path.Base(os.Args[0]), version, runtime.GOOS, runtime.GOARCH, commit)
}
// IsStatusErrorKind returns true if this error describes the provided kind.
func IsStatusErrorKind(err error, kind string) bool {
if s, ok := err.(errors.APIStatus); ok {
if details := s.Status().Details; details != nil {
return kind == details.Kind
}
}
return false
}