forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
223 lines (191 loc) · 6.63 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
package client
import (
"fmt"
"os"
"path"
"runtime"
"strings"
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"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
ImagesNamespacer
ImageRepositoriesNamespacer
ImageRepositoryMappingsNamespacer
ImageRepositoryTagsNamespacer
DeploymentsNamespacer
DeploymentConfigsNamespacer
RoutesNamespacer
UsersInterface
UserIdentityMappingsInterface
ProjectsInterface
PoliciesNamespacer
RolesNamespacer
RoleBindingsNamespacer
PolicyBindingsNamespacer
ResourceAccessReviewsNamespacer
RootResourceAccessReviews
SubjectAccessReviewsNamespacer
TemplatesNamespacer
}
// 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) BuildLogInterface {
return newBuildLogs(c, namespace)
}
// Images provides a REST client for Images
func (c *Client) Images(namespace string) ImageInterface {
return newImages(c, namespace)
}
// ImageRepositories provides a REST client for ImageRepository
func (c *Client) ImageRepositories(namespace string) ImageRepositoryInterface {
return newImageRepositories(c, namespace)
}
// ImageRepositoryMappings provides a REST client for ImageRepositoryMapping
func (c *Client) ImageRepositoryMappings(namespace string) ImageRepositoryMappingInterface {
return newImageRepositoryMappings(c, namespace)
}
// ImageRepositoryTags provides a REST client for ImageRepositoryTag
func (c *Client) ImageRepositoryTags(namespace string) ImageRepositoryTagInterface {
return newImageRepositoryTags(c, namespace)
}
// Deployments provides a REST client for Deployment
func (c *Client) Deployments(namespace string) DeploymentInterface {
return newDeployments(c, namespace)
}
// DeploymentConfigs provides a REST client for DeploymentConfig
func (c *Client) DeploymentConfigs(namespace string) DeploymentConfigInterface {
return newDeploymentConfigs(c, namespace)
}
// Routes provides a REST client for Route
func (c *Client) Routes(namespace string) RouteInterface {
return newRoutes(c, namespace)
}
// Users provides a REST client for User
func (c *Client) Users() UserInterface {
return newUsers(c)
}
// UserIdentityMappings provides a REST client for UserIdentityMapping
func (c *Client) UserIdentityMappings() UserIdentityMappingInterface {
return newUserIdentityMappings(c)
}
// Projects provides a REST client for Projects
func (c *Client) Projects() ProjectInterface {
return newProjects(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)
}
// ResourceAccessReviews provides a REST client for ResourceAccessReviews
func (c *Client) ResourceAccessReviews(namespace string) ResourceAccessReviewInterface {
return newResourceAccessReviews(c, namespace)
}
// RootResourceAccessReviews provides a REST client for RootResourceAccessReviews
func (c *Client) RootResourceAccessReviews() ResourceAccessReviewInterface {
return newRootResourceAccessReviews(c)
}
// SubjectAccessReviews provides a REST client for SubjectAccessReviews
func (c *Client) SubjectAccessReviews(namespace string) SubjectAccessReviewInterface {
return newSubjectAccessReviews(c, namespace)
}
func (c *Client) RootSubjectAccessReviews() SubjectAccessReviewInterface {
return newRootSubjectAccessReviews(c)
}
// Client is an OpenShift client object
type Client struct {
*kclient.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 *kclient.Config) (*Client, error) {
config := *c
if err := SetOpenShiftDefaults(&config); err != nil {
return nil, err
}
client, err := kclient.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &Client{client}, nil
}
// SetOpenShiftDefaults sets the default settings on the passed
// client configuration
func SetOpenShiftDefaults(config *kclient.Config) error {
if config.Prefix == "" {
config.Prefix = "/osapi"
}
if len(config.UserAgent) == 0 {
config.UserAgent = DefaultOpenShiftUserAgent()
}
if config.Version == "" {
// Clients default to the preferred code API version
// TODO: implement version negotiation (highest version supported by server)
config.Version = latest.Version
}
version := config.Version
versionInterfaces, err := latest.InterfacesFor(version)
if err != nil {
return fmt.Errorf("API version '%s' is not recognized (valid values: %s)", version, strings.Join(latest.Versions, ", "))
}
if config.Codec == nil {
config.Codec = versionInterfaces.Codec
}
config.LegacyBehavior = (config.Version == "v1beta1")
return nil
}
// NewOrDie creates an OpenShift client and panics if the provided API version is not recognized.
func NewOrDie(c *kclient.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)
}