cast.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 validation
  14. import "k8s.io/kubernetes/pkg/apis/rbac"
  15. // Casting utilities to and from "Cluster" level equivalents.
  16. func toClusterRole(in *rbac.Role) *rbac.ClusterRole {
  17. if in == nil {
  18. return nil
  19. }
  20. ret := &rbac.ClusterRole{}
  21. ret.ObjectMeta = in.ObjectMeta
  22. ret.Rules = in.Rules
  23. return ret
  24. }
  25. func toClusterRoleList(in *rbac.RoleList) *rbac.ClusterRoleList {
  26. ret := &rbac.ClusterRoleList{}
  27. for _, curr := range in.Items {
  28. ret.Items = append(ret.Items, *toClusterRole(&curr))
  29. }
  30. return ret
  31. }
  32. func toClusterRoleBinding(in *rbac.RoleBinding) *rbac.ClusterRoleBinding {
  33. if in == nil {
  34. return nil
  35. }
  36. ret := &rbac.ClusterRoleBinding{}
  37. ret.ObjectMeta = in.ObjectMeta
  38. ret.Subjects = in.Subjects
  39. ret.RoleRef = in.RoleRef
  40. return ret
  41. }
  42. func toClusterRoleBindingList(in *rbac.RoleBindingList) *rbac.ClusterRoleBindingList {
  43. ret := &rbac.ClusterRoleBindingList{}
  44. for _, curr := range in.Items {
  45. ret.Items = append(ret.Items, *toClusterRoleBinding(&curr))
  46. }
  47. return ret
  48. }
  49. func toRole(in *rbac.ClusterRole) *rbac.Role {
  50. if in == nil {
  51. return nil
  52. }
  53. ret := &rbac.Role{}
  54. ret.ObjectMeta = in.ObjectMeta
  55. ret.Rules = in.Rules
  56. return ret
  57. }
  58. func toRoleList(in *rbac.ClusterRoleList) *rbac.RoleList {
  59. ret := &rbac.RoleList{}
  60. for _, curr := range in.Items {
  61. ret.Items = append(ret.Items, *toRole(&curr))
  62. }
  63. return ret
  64. }
  65. func toRoleBinding(in *rbac.ClusterRoleBinding) *rbac.RoleBinding {
  66. if in == nil {
  67. return nil
  68. }
  69. ret := &rbac.RoleBinding{}
  70. ret.ObjectMeta = in.ObjectMeta
  71. ret.Subjects = in.Subjects
  72. ret.RoleRef = in.RoleRef
  73. return ret
  74. }
  75. func toRoleBindingList(in *rbac.ClusterRoleBindingList) *rbac.RoleBindingList {
  76. ret := &rbac.RoleBindingList{}
  77. for _, curr := range in.Items {
  78. ret.Items = append(ret.Items, *toRoleBinding(&curr))
  79. }
  80. return ret
  81. }