mod_groups.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/util/printutils"
  19. "yunion.io/x/onecloud/pkg/mcclient"
  20. "yunion.io/x/onecloud/pkg/mcclient/modulebase"
  21. "yunion.io/x/onecloud/pkg/mcclient/modules"
  22. )
  23. type GroupManager struct {
  24. modulebase.ResourceManager
  25. }
  26. func (this *GroupManager) GetUsers(s *mcclient.ClientSession, gid string, query jsonutils.JSONObject) (*printutils.ListResult, error) {
  27. url := fmt.Sprintf("/groups/%s/users", gid)
  28. if query != nil {
  29. qs := query.QueryString()
  30. if len(qs) > 0 {
  31. url = fmt.Sprintf("%s?%s", url, qs)
  32. }
  33. }
  34. return modulebase.List(this.ResourceManager, s, url, "users")
  35. }
  36. var (
  37. Groups GroupManager
  38. )
  39. func (this *GroupManager) GetProjects(session *mcclient.ClientSession, uid string) (*printutils.ListResult, error) {
  40. url := fmt.Sprintf("/groups/%s/projects?admin=true", uid)
  41. return modulebase.List(this.ResourceManager, session, url, "projects")
  42. }
  43. func init() {
  44. Groups = GroupManager{modules.NewIdentityV3Manager("group", "groups",
  45. []string{},
  46. []string{"ID", "Name", "Domain_Id", "project_domain",
  47. "User_Count", "Description"})}
  48. modules.Register(&Groups)
  49. }