storage_auditregistration.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright 2018 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 rest
  14. import (
  15. auditv1alpha1 "k8s.io/api/auditregistration/v1alpha1"
  16. "k8s.io/apiserver/pkg/registry/generic"
  17. "k8s.io/apiserver/pkg/registry/rest"
  18. genericapiserver "k8s.io/apiserver/pkg/server"
  19. serverstorage "k8s.io/apiserver/pkg/server/storage"
  20. "k8s.io/kubernetes/pkg/api/legacyscheme"
  21. auditstorage "k8s.io/kubernetes/pkg/registry/auditregistration/auditsink/storage"
  22. )
  23. // RESTStorageProvider is a REST storage provider for audit.k8s.io
  24. type RESTStorageProvider struct{}
  25. // NewRESTStorage returns a RESTStorageProvider
  26. func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, bool) {
  27. apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(auditv1alpha1.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs)
  28. if apiResourceConfigSource.VersionEnabled(auditv1alpha1.SchemeGroupVersion) {
  29. apiGroupInfo.VersionedResourcesStorageMap[auditv1alpha1.SchemeGroupVersion.Version] = p.v1alpha1Storage(apiResourceConfigSource, restOptionsGetter)
  30. }
  31. return apiGroupInfo, true
  32. }
  33. func (p RESTStorageProvider) v1alpha1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
  34. storage := map[string]rest.Storage{}
  35. s := auditstorage.NewREST(restOptionsGetter)
  36. storage["auditsinks"] = s
  37. return storage
  38. }
  39. // GroupName is the group name for the storage provider
  40. func (p RESTStorageProvider) GroupName() string {
  41. return auditv1alpha1.GroupName
  42. }