authorization.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/apimachinery/registered"
  17. "k8s.io/kubernetes/pkg/apis/authorization"
  18. "k8s.io/kubernetes/pkg/client/restclient"
  19. )
  20. type AuthorizationInterface interface {
  21. SubjectAccessReviewsInterface
  22. }
  23. // AuthorizationClient is used to interact with Kubernetes authorization features.
  24. type AuthorizationClient struct {
  25. *restclient.RESTClient
  26. }
  27. func (c *AuthorizationClient) SubjectAccessReviews() SubjectAccessReviewInterface {
  28. return newSubjectAccessReviews(c)
  29. }
  30. func NewAuthorization(c *restclient.Config) (*AuthorizationClient, error) {
  31. config := *c
  32. if err := setAuthorizationDefaults(&config); err != nil {
  33. return nil, err
  34. }
  35. client, err := restclient.RESTClientFor(&config)
  36. if err != nil {
  37. return nil, err
  38. }
  39. return &AuthorizationClient{client}, nil
  40. }
  41. func NewAuthorizationOrDie(c *restclient.Config) *AuthorizationClient {
  42. client, err := NewAuthorization(c)
  43. if err != nil {
  44. panic(err)
  45. }
  46. return client
  47. }
  48. func setAuthorizationDefaults(config *restclient.Config) error {
  49. // if authorization group is not registered, return an error
  50. g, err := registered.Group(authorization.GroupName)
  51. if err != nil {
  52. return err
  53. }
  54. config.APIPath = defaultAPIPath
  55. if config.UserAgent == "" {
  56. config.UserAgent = restclient.DefaultKubernetesUserAgent()
  57. }
  58. // TODO: Unconditionally set the config.Version, until we fix the config.
  59. //if config.Version == "" {
  60. copyGroupVersion := g.GroupVersion
  61. config.GroupVersion = &copyGroupVersion
  62. //}
  63. config.NegotiatedSerializer = api.Codecs
  64. return nil
  65. }