storage_authentication.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 master
  14. import (
  15. "k8s.io/kubernetes/pkg/api/rest"
  16. "k8s.io/kubernetes/pkg/apis/authentication"
  17. authenticationv1beta1 "k8s.io/kubernetes/pkg/apis/authentication/v1beta1"
  18. "k8s.io/kubernetes/pkg/auth/authenticator"
  19. "k8s.io/kubernetes/pkg/genericapiserver"
  20. "k8s.io/kubernetes/pkg/registry/tokenreview"
  21. )
  22. type AuthenticationRESTStorageProvider struct {
  23. Authenticator authenticator.Request
  24. }
  25. var _ RESTStorageProvider = &AuthenticationRESTStorageProvider{}
  26. func (p AuthenticationRESTStorageProvider) NewRESTStorage(apiResourceConfigSource genericapiserver.APIResourceConfigSource, restOptionsGetter RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) {
  27. // TODO figure out how to make the swagger generation stable, while allowing this endpoint to be disabled.
  28. // if p.Authenticator == nil {
  29. // return genericapiserver.APIGroupInfo{}, false
  30. // }
  31. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(authentication.GroupName)
  32. if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1beta1.SchemeGroupVersion) {
  33. apiGroupInfo.VersionedResourcesStorageMap[authenticationv1beta1.SchemeGroupVersion.Version] = p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter)
  34. apiGroupInfo.GroupMeta.GroupVersion = authenticationv1beta1.SchemeGroupVersion
  35. }
  36. return apiGroupInfo, true
  37. }
  38. func (p AuthenticationRESTStorageProvider) v1beta1Storage(apiResourceConfigSource genericapiserver.APIResourceConfigSource, restOptionsGetter RESTOptionsGetter) map[string]rest.Storage {
  39. version := authenticationv1beta1.SchemeGroupVersion
  40. storage := map[string]rest.Storage{}
  41. if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1beta1.SchemeGroupVersion) {
  42. if apiResourceConfigSource.ResourceEnabled(version.WithResource("tokenreviews")) {
  43. tokenReviewStorage := tokenreview.NewREST(p.Authenticator)
  44. storage["tokenreviews"] = tokenReviewStorage
  45. }
  46. }
  47. return storage
  48. }