forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
107 lines (89 loc) · 2.82 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
package client
import (
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/openshift/origin/pkg/api/latest"
)
// Interface exposes methods on OpenShift resources.
type Interface interface {
BuildsNamespacer
BuildConfigsNamespacer
ImagesNamespacer
ImageRepositoriesNamespacer
ImageRepositoryMappingsNamespacer
ImageRepositoryTagsNamespacer
DeploymentsNamespacer
DeploymentConfigsNamespacer
RoutesNamespacer
UsersInterface
UserIdentityMappingsInterface
ProjectsInterface
}
func (c *Client) Builds(namespace string) BuildInterface {
return newBuilds(c, namespace)
}
func (c *Client) BuildConfigs(namespace string) BuildConfigInterface {
return newBuildConfigs(c, namespace)
}
func (c *Client) Images(namespace string) ImageInterface {
return newImages(c, namespace)
}
func (c *Client) ImageRepositories(namespace string) ImageRepositoryInterface {
return newImageRepositories(c, namespace)
}
func (c *Client) ImageRepositoryMappings(namespace string) ImageRepositoryMappingInterface {
return newImageRepositoryMappings(c, namespace)
}
func (c *Client) ImageRepositoryTags(namespace string) ImageRepositoryTagInterface {
return newImageRepositoryTags(c, namespace)
}
func (c *Client) Deployments(namespace string) DeploymentInterface {
return newDeployments(c, namespace)
}
func (c *Client) DeploymentConfigs(namespace string) DeploymentConfigInterface {
return newDeploymentConfigs(c, namespace)
}
func (c *Client) Routes(namespace string) RouteInterface {
return newRoutes(c, namespace)
}
func (c *Client) Users() UserInterface {
return newUsers(c)
}
func (c *Client) UserIdentityMappings() UserIdentityMappingInterface {
return newUserIdentityMappings(c)
}
func (c *Client) Projects() ProjectInterface {
return newProjects(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 config.Prefix == "" {
config.Prefix = "/osapi"
}
if config.Version == "" {
// Clients default to the preferred code API version
// TODO: implement version negotiation (highest version supported by server)
config.Version = latest.Version
}
config.Codec = latest.Codec
config.LegacyBehavior = (config.Version == "v1beta1")
client, err := kclient.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &Client{client}, 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
}