registry.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 clusterrolebinding
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/api/rest"
  17. "k8s.io/kubernetes/pkg/apis/rbac"
  18. "k8s.io/kubernetes/pkg/watch"
  19. )
  20. // Registry is an interface for things that know how to store ClusterRoleBindings.
  21. type Registry interface {
  22. ListClusterRoleBindings(ctx api.Context, options *api.ListOptions) (*rbac.ClusterRoleBindingList, error)
  23. CreateClusterRoleBinding(ctx api.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error
  24. UpdateClusterRoleBinding(ctx api.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error
  25. GetClusterRoleBinding(ctx api.Context, name string) (*rbac.ClusterRoleBinding, error)
  26. DeleteClusterRoleBinding(ctx api.Context, name string) error
  27. WatchClusterRoleBindings(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
  28. }
  29. // storage puts strong typing around storage calls
  30. type storage struct {
  31. rest.StandardStorage
  32. }
  33. // NewRegistry returns a new Registry interface for the given Storage. Any mismatched
  34. // types will panic.
  35. func NewRegistry(s rest.StandardStorage) Registry {
  36. return &storage{s}
  37. }
  38. func (s *storage) ListClusterRoleBindings(ctx api.Context, options *api.ListOptions) (*rbac.ClusterRoleBindingList, error) {
  39. obj, err := s.List(ctx, options)
  40. if err != nil {
  41. return nil, err
  42. }
  43. return obj.(*rbac.ClusterRoleBindingList), nil
  44. }
  45. func (s *storage) CreateClusterRoleBinding(ctx api.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error {
  46. _, err := s.Create(ctx, clusterRoleBinding)
  47. return err
  48. }
  49. func (s *storage) UpdateClusterRoleBinding(ctx api.Context, clusterRoleBinding *rbac.ClusterRoleBinding) error {
  50. _, _, err := s.Update(ctx, clusterRoleBinding.Name, rest.DefaultUpdatedObjectInfo(clusterRoleBinding, api.Scheme))
  51. return err
  52. }
  53. func (s *storage) WatchClusterRoleBindings(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
  54. return s.Watch(ctx, options)
  55. }
  56. func (s *storage) GetClusterRoleBinding(ctx api.Context, name string) (*rbac.ClusterRoleBinding, error) {
  57. obj, err := s.Get(ctx, name)
  58. if err != nil {
  59. return nil, err
  60. }
  61. return obj.(*rbac.ClusterRoleBinding), nil
  62. }
  63. func (s *storage) DeleteClusterRoleBinding(ctx api.Context, name string) error {
  64. _, err := s.Delete(ctx, name, nil)
  65. return err
  66. }