roles.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 identity
  15. import (
  16. "yunion.io/x/jsonutils"
  17. "yunion.io/x/pkg/errors"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type RoleListOptions struct {
  21. options.BaseListOptions
  22. OrderByDomain string `help:"order by domain name" choices:"asc|desc"`
  23. }
  24. func (opts *RoleListOptions) Params() (jsonutils.JSONObject, error) {
  25. return options.ListStructToParams(opts)
  26. }
  27. type RoleIdOptions struct {
  28. ID string `help:"ID or name of role"`
  29. }
  30. func (opts *RoleIdOptions) GetId() string {
  31. return opts.ID
  32. }
  33. type RoleDetailOptions struct {
  34. RoleIdOptions
  35. Domain string `help:"Domain"`
  36. }
  37. func (opts *RoleDetailOptions) Params() (jsonutils.JSONObject, error) {
  38. ret := jsonutils.NewDict()
  39. if len(opts.Domain) > 0 {
  40. ret.Add(jsonutils.NewString(opts.Domain), "domain_id")
  41. }
  42. return ret, nil
  43. }
  44. type RoleCreateOptions struct {
  45. NAME string `help:"Role name"`
  46. Domain string `help:"Domain"`
  47. Desc string `help:"Description"`
  48. PublicScope string `help:"public scope" choices:"none|system"`
  49. }
  50. func (opts *RoleCreateOptions) Params() (jsonutils.JSONObject, error) {
  51. params := jsonutils.NewDict()
  52. params.Add(jsonutils.NewString(opts.NAME), "name")
  53. if len(opts.Domain) > 0 {
  54. params.Add(jsonutils.NewString(opts.Domain), "domain_id")
  55. }
  56. if len(opts.Desc) > 0 {
  57. params.Add(jsonutils.NewString(opts.Desc), "description")
  58. }
  59. if len(opts.PublicScope) > 0 {
  60. params.Add(jsonutils.NewString(opts.PublicScope), "public_scope")
  61. }
  62. return params, nil
  63. }
  64. type RoleGetPropertyTagValuePairOptions struct {
  65. RoleListOptions
  66. options.TagValuePairsOptions
  67. }
  68. func (opts *RoleGetPropertyTagValuePairOptions) Params() (jsonutils.JSONObject, error) {
  69. params, err := opts.RoleListOptions.Params()
  70. if err != nil {
  71. return nil, errors.Wrap(err, "RoleListOptions.Params")
  72. }
  73. tagParams, _ := opts.TagValuePairsOptions.Params()
  74. params.(*jsonutils.JSONDict).Update(tagParams)
  75. return params, nil
  76. }
  77. type RoleGetPropertyTagValueTreeOptions struct {
  78. RoleListOptions
  79. options.TagValueTreeOptions
  80. }
  81. func (opts *RoleGetPropertyTagValueTreeOptions) Params() (jsonutils.JSONObject, error) {
  82. params, err := opts.RoleListOptions.Params()
  83. if err != nil {
  84. return nil, errors.Wrap(err, "RoleListOptions.Params")
  85. }
  86. tagParams, _ := opts.TagValueTreeOptions.Params()
  87. params.(*jsonutils.JSONDict).Update(tagParams)
  88. return params, nil
  89. }
  90. type RoleGetPropertyDomainTagValuePairOptions struct {
  91. RoleListOptions
  92. options.DomainTagValuePairsOptions
  93. }
  94. func (opts *RoleGetPropertyDomainTagValuePairOptions) Params() (jsonutils.JSONObject, error) {
  95. params, err := opts.RoleListOptions.Params()
  96. if err != nil {
  97. return nil, errors.Wrap(err, "RoleListOptions.Params")
  98. }
  99. tagParams, _ := opts.DomainTagValuePairsOptions.Params()
  100. params.(*jsonutils.JSONDict).Update(tagParams)
  101. return params, nil
  102. }
  103. type RoleGetPropertyDomainTagValueTreeOptions struct {
  104. RoleListOptions
  105. options.DomainTagValueTreeOptions
  106. }
  107. func (opts *RoleGetPropertyDomainTagValueTreeOptions) Params() (jsonutils.JSONObject, error) {
  108. params, err := opts.RoleListOptions.Params()
  109. if err != nil {
  110. return nil, errors.Wrap(err, "RoleListOptions.Params")
  111. }
  112. tagParams, _ := opts.DomainTagValueTreeOptions.Params()
  113. params.(*jsonutils.JSONDict).Update(tagParams)
  114. return params, nil
  115. }