service_accounts.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright 2014 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/watch"
  17. )
  18. type ServiceAccountsNamespacer interface {
  19. ServiceAccounts(namespace string) ServiceAccountsInterface
  20. }
  21. type ServiceAccountsInterface interface {
  22. Create(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error)
  23. Update(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error)
  24. Delete(name string) error
  25. List(opts api.ListOptions) (*api.ServiceAccountList, error)
  26. Get(name string) (*api.ServiceAccount, error)
  27. Watch(opts api.ListOptions) (watch.Interface, error)
  28. }
  29. // serviceAccounts implements ServiceAccounts interface
  30. type serviceAccounts struct {
  31. client *Client
  32. namespace string
  33. }
  34. // newServiceAccounts returns a new serviceAccounts object.
  35. func newServiceAccounts(c *Client, ns string) ServiceAccountsInterface {
  36. return &serviceAccounts{
  37. client: c,
  38. namespace: ns,
  39. }
  40. }
  41. func (s *serviceAccounts) Create(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error) {
  42. result := &api.ServiceAccount{}
  43. err := s.client.Post().
  44. Namespace(s.namespace).
  45. Resource("serviceAccounts").
  46. Body(serviceAccount).
  47. Do().
  48. Into(result)
  49. return result, err
  50. }
  51. // List returns a list of serviceAccounts matching the selectors.
  52. func (s *serviceAccounts) List(opts api.ListOptions) (*api.ServiceAccountList, error) {
  53. result := &api.ServiceAccountList{}
  54. err := s.client.Get().
  55. Namespace(s.namespace).
  56. Resource("serviceAccounts").
  57. VersionedParams(&opts, api.ParameterCodec).
  58. Do().
  59. Into(result)
  60. return result, err
  61. }
  62. // Get returns the given serviceAccount, or an error.
  63. func (s *serviceAccounts) Get(name string) (*api.ServiceAccount, error) {
  64. result := &api.ServiceAccount{}
  65. err := s.client.Get().
  66. Namespace(s.namespace).
  67. Resource("serviceAccounts").
  68. Name(name).
  69. Do().
  70. Into(result)
  71. return result, err
  72. }
  73. // Watch starts watching for serviceAccounts matching the given selectors.
  74. func (s *serviceAccounts) Watch(opts api.ListOptions) (watch.Interface, error) {
  75. return s.client.Get().
  76. Prefix("watch").
  77. Namespace(s.namespace).
  78. Resource("serviceAccounts").
  79. VersionedParams(&opts, api.ParameterCodec).
  80. Watch()
  81. }
  82. func (s *serviceAccounts) Delete(name string) error {
  83. return s.client.Delete().
  84. Namespace(s.namespace).
  85. Resource("serviceAccounts").
  86. Name(name).
  87. Do().
  88. Error()
  89. }
  90. func (s *serviceAccounts) Update(serviceAccount *api.ServiceAccount) (result *api.ServiceAccount, err error) {
  91. result = &api.ServiceAccount{}
  92. err = s.client.Put().
  93. Namespace(s.namespace).
  94. Resource("serviceAccounts").
  95. Name(serviceAccount.Name).
  96. Body(serviceAccount).
  97. Do().
  98. Into(result)
  99. return
  100. }