2016-07-19 18:47:53 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-09-23 19:10:47 +00:00
|
|
|
package rest
|
2016-07-19 18:47:53 +00:00
|
|
|
|
|
|
|
import (
|
2017-01-04 15:39:05 +00:00
|
|
|
"k8s.io/apiserver/pkg/authentication/authenticator"
|
2017-02-02 09:25:56 +00:00
|
|
|
"k8s.io/apiserver/pkg/registry/generic"
|
|
|
|
"k8s.io/apiserver/pkg/registry/rest"
|
|
|
|
genericapiserver "k8s.io/apiserver/pkg/server"
|
2017-02-11 11:26:43 +00:00
|
|
|
serverstorage "k8s.io/apiserver/pkg/server/storage"
|
2017-02-02 07:30:11 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2016-07-19 18:47:53 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/authentication"
|
2017-06-22 18:04:37 +00:00
|
|
|
authenticationv1 "k8s.io/api/authentication/v1"
|
|
|
|
authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
|
2016-09-21 13:01:02 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/authentication/tokenreview"
|
2016-07-19 18:47:53 +00:00
|
|
|
)
|
|
|
|
|
2016-09-23 19:10:47 +00:00
|
|
|
type RESTStorageProvider struct {
|
2016-07-19 18:47:53 +00:00
|
|
|
Authenticator authenticator.Request
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:26:43 +00:00
|
|
|
func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) {
|
2016-07-19 18:47:53 +00:00
|
|
|
// TODO figure out how to make the swagger generation stable, while allowing this endpoint to be disabled.
|
|
|
|
// if p.Authenticator == nil {
|
|
|
|
// return genericapiserver.APIGroupInfo{}, false
|
|
|
|
// }
|
|
|
|
|
2017-02-02 07:30:11 +00:00
|
|
|
apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(authentication.GroupName, api.Registry, api.Scheme, api.ParameterCodec, api.Codecs)
|
2017-06-09 20:34:04 +00:00
|
|
|
// If you add a version here, be sure to add an entry in `k8s.io/kubernetes/cmd/kube-apiserver/app/aggregator.go with specific priorities.
|
|
|
|
// TODO refactor the plumbing to provide the information in the APIGroupInfo
|
2016-07-19 18:47:53 +00:00
|
|
|
|
|
|
|
if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1beta1.SchemeGroupVersion) {
|
|
|
|
apiGroupInfo.VersionedResourcesStorageMap[authenticationv1beta1.SchemeGroupVersion.Version] = p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter)
|
|
|
|
apiGroupInfo.GroupMeta.GroupVersion = authenticationv1beta1.SchemeGroupVersion
|
|
|
|
}
|
2017-01-30 21:43:05 +00:00
|
|
|
if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1.SchemeGroupVersion) {
|
|
|
|
apiGroupInfo.VersionedResourcesStorageMap[authenticationv1.SchemeGroupVersion.Version] = p.v1Storage(apiResourceConfigSource, restOptionsGetter)
|
|
|
|
apiGroupInfo.GroupMeta.GroupVersion = authenticationv1.SchemeGroupVersion
|
|
|
|
}
|
2016-07-19 18:47:53 +00:00
|
|
|
|
|
|
|
return apiGroupInfo, true
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:26:43 +00:00
|
|
|
func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
|
2016-07-19 18:47:53 +00:00
|
|
|
version := authenticationv1beta1.SchemeGroupVersion
|
|
|
|
|
|
|
|
storage := map[string]rest.Storage{}
|
|
|
|
if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1beta1.SchemeGroupVersion) {
|
|
|
|
if apiResourceConfigSource.ResourceEnabled(version.WithResource("tokenreviews")) {
|
|
|
|
tokenReviewStorage := tokenreview.NewREST(p.Authenticator)
|
|
|
|
storage["tokenreviews"] = tokenReviewStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return storage
|
|
|
|
}
|
2016-10-27 18:24:11 +00:00
|
|
|
|
2017-02-11 11:26:43 +00:00
|
|
|
func (p RESTStorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
|
2017-01-30 21:43:05 +00:00
|
|
|
version := authenticationv1.SchemeGroupVersion
|
|
|
|
|
|
|
|
storage := map[string]rest.Storage{}
|
|
|
|
if apiResourceConfigSource.AnyResourcesForVersionEnabled(authenticationv1.SchemeGroupVersion) {
|
|
|
|
if apiResourceConfigSource.ResourceEnabled(version.WithResource("tokenreviews")) {
|
|
|
|
tokenReviewStorage := tokenreview.NewREST(p.Authenticator)
|
|
|
|
storage["tokenreviews"] = tokenReviewStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return storage
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:24:11 +00:00
|
|
|
func (p RESTStorageProvider) GroupName() string {
|
|
|
|
return authentication.GroupName
|
|
|
|
}
|