forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
65 lines (56 loc) · 1.91 KB
/
users.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
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
userapi "github.com/openshift/origin/pkg/user/api"
)
// UsersInterface has methods to work with User resources
type UsersInterface interface {
Users() UserInterface
}
// UserInterface exposes methods on user resources.
type UserInterface interface {
List(label labels.Selector, field fields.Selector) (*userapi.UserList, error)
Get(name string) (*userapi.User, error)
Create(user *userapi.User) (*userapi.User, error)
Update(user *userapi.User) (*userapi.User, error)
}
// users implements UserInterface interface
type users struct {
r *Client
}
// newUsers returns a users
func newUsers(c *Client) *users {
return &users{
r: c,
}
}
// List returns a list of users that match the label and field selectors.
func (c *users) List(label labels.Selector, field fields.Selector) (result *userapi.UserList, err error) {
result = &userapi.UserList{}
err = c.r.Get().
Resource("users").
LabelsSelectorParam(label).
FieldsSelectorParam(field).
Do().
Into(result)
return
}
// Get returns information about a particular user or an error
func (c *users) Get(name string) (result *userapi.User, err error) {
result = &userapi.User{}
err = c.r.Get().Resource("users").Name(name).Do().Into(result)
return
}
// Create creates a new user. Returns the server's representation of the user and error if one occurs.
func (c *users) Create(user *userapi.User) (result *userapi.User, err error) {
result = &userapi.User{}
err = c.r.Post().Resource("users").Body(user).Do().Into(result)
return
}
// Update updates the user on server. Returns the server's representation of the user and error if one occurs.
func (c *users) Update(user *userapi.User) (result *userapi.User, err error) {
result = &userapi.User{}
err = c.r.Put().Resource("users").Name(user.Name).Body(user).Do().Into(result)
return
}