assignments.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "yunion.io/x/onecloud/pkg/util/rbacutils"
  16. type SIdentityObject struct {
  17. // UUID
  18. Id string `json:"id"`
  19. // 名称
  20. Name string `json:"name"`
  21. }
  22. type SDomainObject struct {
  23. SIdentityObject
  24. // 归属域信息
  25. Domain SIdentityObject `json:"domain"`
  26. }
  27. type SDomainObjectWithMetadata struct {
  28. SDomainObject
  29. // 标签信息
  30. Metadata map[string]string `json:"metadata"`
  31. }
  32. type SFetchDomainObject struct {
  33. SIdentityObject
  34. // 归属域名称
  35. Domain string `json:"domain"`
  36. // 归属域ID
  37. DomainId string `json:"domain_id"`
  38. }
  39. type SFetchDomainObjectWithMetadata struct {
  40. SFetchDomainObject
  41. // 项目标签
  42. Metadata map[string]string `json:"metadata"`
  43. }
  44. type SRoleAssignment struct {
  45. // 归属范围
  46. Scope struct {
  47. // 归属域信息
  48. Domain SIdentityObject `json:"domain"`
  49. // 归属项目信息,归属范围为项目时有值
  50. Project SDomainObjectWithMetadata `json:"project"`
  51. } `json:"scope"`
  52. // 用户信息
  53. User SDomainObject `json:"user"`
  54. // 用户组信息
  55. Group SDomainObject `json:"group"`
  56. // 用户加入项目的角色信息
  57. Role SDomainObject `json:"role"`
  58. // 用户角色关联的权限信息
  59. Policies struct {
  60. // 关联的项目权限名称列表
  61. Project []string `json:"project"`
  62. // 关联的域权限名称列表
  63. Domain []string `json:"domain"`
  64. // 关联的系统权限名称列表
  65. System []string `json:"system"`
  66. } `json:"policies"`
  67. }
  68. // rbacutils.IRbacIdentity interfaces
  69. func (ra *SRoleAssignment) GetProjectId() string {
  70. return ra.Scope.Project.Id
  71. }
  72. func (ra *SRoleAssignment) GetRoleIds() []string {
  73. return []string{ra.Role.Id}
  74. }
  75. func (ra *SRoleAssignment) GetLoginIp() string {
  76. return ""
  77. }
  78. func (ra *SRoleAssignment) GetTokenString() string {
  79. return rbacutils.FAKE_TOKEN
  80. }
  81. type RAInputObject struct {
  82. Id string `json:"id"`
  83. }
  84. type RoleAssignmentsInput struct {
  85. User RAInputObject `json:"user"`
  86. Group RAInputObject `json:"group"`
  87. Role RAInputObject `json:"role"`
  88. Scope struct {
  89. Project RAInputObject `json:"project"`
  90. Domain RAInputObject `json:"domain"`
  91. } `json:"scope"`
  92. Users []string `json:"users"`
  93. Groups []string `json:"groups"`
  94. Roles []string `json:"roles"`
  95. Projects []string `json:"projects"`
  96. Domains []string `json:"domains"`
  97. ProjectDomainId string `json:"project_domain_id"`
  98. ProjectDomains []string `json:"project_domains"`
  99. IncludeNames *bool `json:"include_names"`
  100. Effective *bool `json:"effective"`
  101. IncludeSubtree *bool `json:"include_subtree"`
  102. IncludeSystem *bool `json:"include_system"`
  103. IncludePolicies *bool `json:"include_policies"`
  104. Limit *int `json:"limit"`
  105. Offset *int `json:"offset"`
  106. }
  107. type RoleAssignmentsOutput struct {
  108. RoleAssignments []SRoleAssignment `json:"role_assignments,allowempty"`
  109. Total int64 `json:"total"`
  110. Limit int `json:"limit"`
  111. Offset int `json:"offset"`
  112. }