fed_clusterrolebinding.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 Yunion
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package k8s
  15. import (
  16. "yunion.io/x/jsonutils"
  17. )
  18. type FedClusterRoleBindingCreatOpt struct {
  19. FedResourceCreateOptions
  20. RoleRef RoleRef `json:"roleRef"`
  21. Subject Subject `help:"Subject is role bind subject, e.g: User=jane"`
  22. }
  23. func (o *FedClusterRoleBindingCreatOpt) Params() (jsonutils.JSONObject, error) {
  24. input, err := o.ToInput()
  25. if err != nil {
  26. return nil, err
  27. }
  28. return input.JSON(input), nil
  29. }
  30. func (o *FedClusterRoleBindingCreatOpt) ToInput() (*FedClusterRoleBindingCreateInput, error) {
  31. input := &FedClusterRoleBindingCreateInput{
  32. FedResourceCreateOptions: o.FedResourceCreateOptions,
  33. }
  34. if err := validateRoleRef(&o.RoleRef); err != nil {
  35. return nil, err
  36. }
  37. if err := validateSubject(&o.Subject); err != nil {
  38. return nil, err
  39. }
  40. input.Spec.Template.RoleRef = o.RoleRef
  41. subs := []Subject{o.Subject}
  42. input.Spec.Template.Subjects = subs
  43. return input, nil
  44. }
  45. type FedClusterRoleBindingCreateInput struct {
  46. FedResourceCreateOptions
  47. Spec FedClusterRoleBindingSpec `json:"spec"`
  48. }
  49. type FedClusterRoleBindingSpec struct {
  50. Template RoleBindingTemplate `json:"template"`
  51. }