policy.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 PolicyListOptions struct {
  21. options.BaseListOptions
  22. Type string `help:"filter by type"`
  23. IsSystem *bool `help:"filter by is_system" negative:"is_no_system"`
  24. Format string `help:"policy format, default to yaml" default:"yaml" choices:"yaml|json"`
  25. OrderByDomain string `help:"order by domain name" choices:"asc|desc"`
  26. Role string `help:"filter by role"`
  27. }
  28. func (opts *PolicyListOptions) Params() (jsonutils.JSONObject, error) {
  29. return options.ListStructToParams(opts)
  30. }
  31. type PolicyGetPropertyTagValuePairOptions struct {
  32. PolicyListOptions
  33. options.TagValuePairsOptions
  34. }
  35. func (opts *PolicyGetPropertyTagValuePairOptions) Params() (jsonutils.JSONObject, error) {
  36. params, err := opts.PolicyListOptions.Params()
  37. if err != nil {
  38. return nil, errors.Wrap(err, "PolicyListOptions.Params")
  39. }
  40. tagParams, _ := opts.TagValuePairsOptions.Params()
  41. params.(*jsonutils.JSONDict).Update(tagParams)
  42. return params, nil
  43. }
  44. type PolicyGetPropertyTagValueTreeOptions struct {
  45. PolicyListOptions
  46. options.TagValueTreeOptions
  47. }
  48. func (opts *PolicyGetPropertyTagValueTreeOptions) Params() (jsonutils.JSONObject, error) {
  49. params, err := opts.PolicyListOptions.Params()
  50. if err != nil {
  51. return nil, errors.Wrap(err, "PolicyListOptions.Params")
  52. }
  53. tagParams, _ := opts.TagValueTreeOptions.Params()
  54. params.(*jsonutils.JSONDict).Update(tagParams)
  55. return params, nil
  56. }
  57. type PolicyGetPropertyDomainTagValuePairOptions struct {
  58. PolicyListOptions
  59. options.DomainTagValuePairsOptions
  60. }
  61. func (opts *PolicyGetPropertyDomainTagValuePairOptions) Params() (jsonutils.JSONObject, error) {
  62. params, err := opts.PolicyListOptions.Params()
  63. if err != nil {
  64. return nil, errors.Wrap(err, "PolicyListOptions.Params")
  65. }
  66. tagParams, _ := opts.DomainTagValuePairsOptions.Params()
  67. params.(*jsonutils.JSONDict).Update(tagParams)
  68. return params, nil
  69. }
  70. type PolicyGetPropertyDomainTagValueTreeOptions struct {
  71. PolicyListOptions
  72. options.DomainTagValueTreeOptions
  73. }
  74. func (opts *PolicyGetPropertyDomainTagValueTreeOptions) Params() (jsonutils.JSONObject, error) {
  75. params, err := opts.PolicyListOptions.Params()
  76. if err != nil {
  77. return nil, errors.Wrap(err, "PolicyListOptions.Params")
  78. }
  79. tagParams, _ := opts.DomainTagValueTreeOptions.Params()
  80. params.(*jsonutils.JSONDict).Update(tagParams)
  81. return params, nil
  82. }