fed_role.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 FedApiResourecesOptions struct{}
  19. func (opts *FedApiResourecesOptions) GetId() string {
  20. return "api-resources"
  21. }
  22. func (opts *FedApiResourecesOptions) Params() (jsonutils.JSONObject, error) {
  23. return nil, nil
  24. }
  25. type FedClusterUsersOptions struct{}
  26. func (opts *FedClusterUsersOptions) GetId() string {
  27. return "cluster-users"
  28. }
  29. func (opts *FedClusterUsersOptions) Params() (jsonutils.JSONObject, error) {
  30. return nil, nil
  31. }
  32. type FedClusterUserGroupsOptions struct{}
  33. func (opts *FedClusterUserGroupsOptions) GetId() string {
  34. return "cluster-user-groups"
  35. }
  36. func (opts *FedClusterUserGroupsOptions) Params() (jsonutils.JSONObject, error) {
  37. return nil, nil
  38. }
  39. type FedRoleListOptions struct {
  40. FedNamespaceResourceListOptions
  41. }
  42. type FedRoleCreateOptions struct {
  43. FedNamespaceResourceCreateOptions
  44. Rule []string `help:"role rule, e.g: 'apps/v1:deployments:get,watch,list'"`
  45. }
  46. type FedRoleCreateInput struct {
  47. FedNamespaceResourceCreateInput
  48. Spec FedRoleSpec `json:"spec"`
  49. }
  50. type FedRoleSpec struct {
  51. Template RoleTemplate `json:"template"`
  52. }
  53. type RoleTemplate struct {
  54. Rules []PolicyRule `json:"rules"`
  55. }
  56. func (o *FedRoleCreateOptions) Params() (jsonutils.JSONObject, error) {
  57. rules := make([]PolicyRule, 0)
  58. for _, rule := range o.Rule {
  59. ret, err := parsePolicyRule(rule)
  60. if err != nil {
  61. return nil, err
  62. }
  63. rules = append(rules, *ret)
  64. }
  65. input := FedRoleCreateInput{
  66. FedNamespaceResourceCreateInput: o.FedNamespaceResourceCreateOptions.ToInput(),
  67. Spec: FedRoleSpec{
  68. Template: RoleTemplate{
  69. Rules: rules,
  70. },
  71. },
  72. }
  73. return input.JSON(input), nil
  74. }