roles.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/onecloud/cmd/climc/shell"
  18. "yunion.io/x/onecloud/pkg/mcclient"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
  20. "yunion.io/x/onecloud/pkg/mcclient/options"
  21. "yunion.io/x/onecloud/pkg/mcclient/options/identity"
  22. )
  23. func init() {
  24. cmd := shell.NewResourceCmd(&modules.RolesV3)
  25. cmd.List(&identity.RoleListOptions{})
  26. cmd.Show(&identity.RoleDetailOptions{})
  27. cmd.Delete(&identity.RoleDetailOptions{})
  28. cmd.Create(&identity.RoleCreateOptions{})
  29. cmd.Perform("public", &options.BaseIdOptions{})
  30. cmd.Perform("private", &options.BaseIdOptions{})
  31. cmd.GetProperty(&identity.RoleGetPropertyTagValuePairOptions{})
  32. cmd.GetProperty(&identity.RoleGetPropertyTagValueTreeOptions{})
  33. cmd.GetProperty(&identity.RoleGetPropertyDomainTagValuePairOptions{})
  34. cmd.GetProperty(&identity.RoleGetPropertyDomainTagValueTreeOptions{})
  35. type RoleUpdateOptions struct {
  36. ID string `help:"Role ID or Name"`
  37. Domain string `help:"Domain"`
  38. Name string `help:"Name to alter"`
  39. Desc string `help:"Description"`
  40. }
  41. R(&RoleUpdateOptions{}, "role-update", "Update role", func(s *mcclient.ClientSession, args *RoleUpdateOptions) error {
  42. query := jsonutils.NewDict()
  43. if len(args.Domain) > 0 {
  44. domainId, err := modules.Domains.GetId(s, args.Domain, nil)
  45. if err != nil {
  46. return err
  47. }
  48. query.Add(jsonutils.NewString(domainId), "domain_id")
  49. }
  50. rid, err := modules.RolesV3.GetId(s, args.ID, query)
  51. if err != nil {
  52. return err
  53. }
  54. params := jsonutils.NewDict()
  55. if len(args.Name) > 0 {
  56. params.Add(jsonutils.NewString(args.Name), "name")
  57. }
  58. if len(args.Desc) > 0 {
  59. params.Add(jsonutils.NewString(args.Desc), "description")
  60. }
  61. role, err := modules.RolesV3.Patch(s, rid, params)
  62. if err != nil {
  63. return err
  64. }
  65. printObject(role)
  66. return nil
  67. })
  68. }