conversion.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright 2015 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 v0
  14. import (
  15. api "k8s.io/kubernetes/pkg/apis/abac"
  16. "k8s.io/kubernetes/pkg/conversion"
  17. "k8s.io/kubernetes/pkg/runtime"
  18. )
  19. func addConversionFuncs(scheme *runtime.Scheme) error {
  20. return scheme.AddConversionFuncs(
  21. func(in *Policy, out *api.Policy, s conversion.Scope) error {
  22. // Begin by copying all fields
  23. out.Spec.User = in.User
  24. out.Spec.Group = in.Group
  25. out.Spec.Namespace = in.Namespace
  26. out.Spec.Resource = in.Resource
  27. out.Spec.Readonly = in.Readonly
  28. // In v0, unspecified user and group matches all subjects
  29. if len(in.User) == 0 && len(in.Group) == 0 {
  30. out.Spec.User = "*"
  31. }
  32. // In v0, leaving namespace empty matches all namespaces
  33. if len(in.Namespace) == 0 {
  34. out.Spec.Namespace = "*"
  35. }
  36. // In v0, leaving resource empty matches all resources
  37. if len(in.Resource) == 0 {
  38. out.Spec.Resource = "*"
  39. }
  40. // Any rule in v0 should match all API groups
  41. out.Spec.APIGroup = "*"
  42. // In v0, leaving namespace and resource blank allows non-resource paths
  43. if len(in.Namespace) == 0 && len(in.Resource) == 0 {
  44. out.Spec.NonResourcePath = "*"
  45. }
  46. return nil
  47. },
  48. )
  49. }