rbac.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/apis/rbac"
  16. "k8s.io/kubernetes/pkg/client/restclient"
  17. )
  18. // Interface holds the methods for clients of Kubernetes to allow mock testing.
  19. type RbacInterface interface {
  20. RoleBindingsNamespacer
  21. RolesNamespacer
  22. ClusterRoleBindings
  23. ClusterRoles
  24. }
  25. type RbacClient struct {
  26. *restclient.RESTClient
  27. }
  28. func (c *RbacClient) RoleBindings(namespace string) RoleBindingInterface {
  29. return newRoleBindings(c, namespace)
  30. }
  31. func (c *RbacClient) Roles(namespace string) RoleInterface {
  32. return newRoles(c, namespace)
  33. }
  34. func (c *RbacClient) ClusterRoleBindings() ClusterRoleBindingInterface {
  35. return newClusterRoleBindings(c)
  36. }
  37. func (c *RbacClient) ClusterRoles() ClusterRoleInterface {
  38. return newClusterRoles(c)
  39. }
  40. // NewRbac creates a new RbacClient for the given config.
  41. func NewRbac(c *restclient.Config) (*RbacClient, error) {
  42. config := *c
  43. if err := setGroupDefaults(rbac.GroupName, &config); err != nil {
  44. return nil, err
  45. }
  46. client, err := restclient.RESTClientFor(&config)
  47. if err != nil {
  48. return nil, err
  49. }
  50. return &RbacClient{client}, nil
  51. }
  52. // NewRbacOrDie creates a new RbacClient for the given config and
  53. // panics if there is an error in the config.
  54. func NewRbacOrDie(c *restclient.Config) *RbacClient {
  55. client, err := NewRbac(c)
  56. if err != nil {
  57. panic(err)
  58. }
  59. return client
  60. }