rolebindings.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/apis/rbac"
  17. "k8s.io/kubernetes/pkg/watch"
  18. )
  19. // RoleBindingsNamespacer has methods to work with RoleBinding resources in a namespace
  20. type RoleBindingsNamespacer interface {
  21. RoleBindings(namespace string) RoleBindingInterface
  22. }
  23. // RoleBindingInterface has methods to work with RoleBinding resources.
  24. type RoleBindingInterface interface {
  25. List(opts api.ListOptions) (*rbac.RoleBindingList, error)
  26. Get(name string) (*rbac.RoleBinding, error)
  27. Delete(name string, options *api.DeleteOptions) error
  28. Create(roleBinding *rbac.RoleBinding) (*rbac.RoleBinding, error)
  29. Update(roleBinding *rbac.RoleBinding) (*rbac.RoleBinding, error)
  30. Watch(opts api.ListOptions) (watch.Interface, error)
  31. }
  32. // roleBindings implements RoleBindingsNamespacer interface
  33. type roleBindings struct {
  34. client *RbacClient
  35. ns string
  36. }
  37. // newRoleBindings returns a roleBindings
  38. func newRoleBindings(c *RbacClient, namespace string) *roleBindings {
  39. return &roleBindings{
  40. client: c,
  41. ns: namespace,
  42. }
  43. }
  44. // List takes label and field selectors, and returns the list of roleBindings that match those selectors.
  45. func (c *roleBindings) List(opts api.ListOptions) (result *rbac.RoleBindingList, err error) {
  46. result = &rbac.RoleBindingList{}
  47. err = c.client.Get().Namespace(c.ns).Resource("rolebindings").VersionedParams(&opts, api.ParameterCodec).Do().Into(result)
  48. return
  49. }
  50. // Get takes the name of the roleBinding, and returns the corresponding RoleBinding object, and an error if it occurs
  51. func (c *roleBindings) Get(name string) (result *rbac.RoleBinding, err error) {
  52. result = &rbac.RoleBinding{}
  53. err = c.client.Get().Namespace(c.ns).Resource("rolebindings").Name(name).Do().Into(result)
  54. return
  55. }
  56. // Delete takes the name of the roleBinding and deletes it. Returns an error if one occurs.
  57. func (c *roleBindings) Delete(name string, options *api.DeleteOptions) error {
  58. return c.client.Delete().Namespace(c.ns).Resource("rolebindings").Name(name).Body(options).Do().Error()
  59. }
  60. // Create takes the representation of a roleBinding and creates it. Returns the server's representation of the roleBinding, and an error, if it occurs.
  61. func (c *roleBindings) Create(roleBinding *rbac.RoleBinding) (result *rbac.RoleBinding, err error) {
  62. result = &rbac.RoleBinding{}
  63. err = c.client.Post().Namespace(c.ns).Resource("rolebindings").Body(roleBinding).Do().Into(result)
  64. return
  65. }
  66. // Update takes the representation of a roleBinding and updates it. Returns the server's representation of the roleBinding, and an error, if it occurs.
  67. func (c *roleBindings) Update(roleBinding *rbac.RoleBinding) (result *rbac.RoleBinding, err error) {
  68. result = &rbac.RoleBinding{}
  69. err = c.client.Put().Namespace(c.ns).Resource("rolebindings").Name(roleBinding.Name).Body(roleBinding).Do().Into(result)
  70. return
  71. }
  72. // Watch returns a watch.Interface that watches the requested roleBindings.
  73. func (c *roleBindings) Watch(opts api.ListOptions) (watch.Interface, error) {
  74. return c.client.Get().
  75. Prefix("watch").
  76. Namespace(c.ns).
  77. Resource("rolebindings").
  78. VersionedParams(&opts, api.ParameterCodec).
  79. Watch()
  80. }