storage.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 storage
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime"
  16. "k8s.io/apiserver/pkg/registry/generic"
  17. genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
  18. "k8s.io/kubernetes/pkg/apis/auditregistration"
  19. auditstrategy "k8s.io/kubernetes/pkg/registry/auditregistration/auditsink"
  20. )
  21. // REST implements a RESTStorage for audit sink against etcd
  22. type REST struct {
  23. *genericregistry.Store
  24. }
  25. // NewREST returns a RESTStorage object that will work against audit sinks
  26. func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
  27. store := &genericregistry.Store{
  28. NewFunc: func() runtime.Object { return &auditregistration.AuditSink{} },
  29. NewListFunc: func() runtime.Object { return &auditregistration.AuditSinkList{} },
  30. ObjectNameFunc: func(obj runtime.Object) (string, error) {
  31. return obj.(*auditregistration.AuditSink).Name, nil
  32. },
  33. DefaultQualifiedResource: auditregistration.Resource("auditsinks"),
  34. CreateStrategy: auditstrategy.Strategy,
  35. UpdateStrategy: auditstrategy.Strategy,
  36. DeleteStrategy: auditstrategy.Strategy,
  37. }
  38. options := &generic.StoreOptions{RESTOptions: optsGetter}
  39. if err := store.CompleteWithOptions(options); err != nil {
  40. panic(err) // TODO: Propagate error up
  41. }
  42. return &REST{store}
  43. }