authentication.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/authentication"
  18. "k8s.io/kubernetes/pkg/client/restclient"
  19. )
  20. type AuthenticationInterface interface {
  21. TokenReviewsInterface
  22. }
  23. // AuthenticationClient is used to interact with Kubernetes authentication features.
  24. type AuthenticationClient struct {
  25. *restclient.RESTClient
  26. }
  27. func (c *AuthenticationClient) TokenReviews() TokenReviewInterface {
  28. return newTokenReviews(c)
  29. }
  30. func NewAuthentication(c *restclient.Config) (*AuthenticationClient, error) {
  31. config := *c
  32. if err := setAuthenticationDefaults(&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 &AuthenticationClient{client}, nil
  40. }
  41. func NewAuthenticationOrDie(c *restclient.Config) *AuthenticationClient {
  42. client, err := NewAuthentication(c)
  43. if err != nil {
  44. panic(err)
  45. }
  46. return client
  47. }
  48. func setAuthenticationDefaults(config *restclient.Config) error {
  49. // if authentication group is not registered, return an error
  50. g, err := registered.Group(authentication.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. }