input.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. "time"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. "yunion.io/x/pkg/util/rbacscope"
  20. "yunion.io/x/onecloud/pkg/apis"
  21. "yunion.io/x/onecloud/pkg/util/tagutils"
  22. )
  23. type IdentityBaseResourceCreateInput struct {
  24. apis.StandaloneResourceCreateInput
  25. apis.DomainizedResourceCreateInput
  26. }
  27. type EnabledIdentityBaseResourceCreateInput struct {
  28. IdentityBaseResourceCreateInput
  29. Enabled *bool `json:"enabled"`
  30. }
  31. type IdentityBaseResourceListInput struct {
  32. apis.StandaloneResourceListInput
  33. apis.DomainizedResourceListInput
  34. }
  35. type EnabledIdentityBaseResourceListInput struct {
  36. IdentityBaseResourceListInput
  37. apis.EnabledResourceBaseListInput
  38. }
  39. type ProjectFilterListInput struct {
  40. // 项目归属域
  41. ProjectDomainId string `json:"project_domain_id"`
  42. // swagger:ignore
  43. // Deprecated
  44. ProjectDomain string `json:"project_domain" yunion-deprecated-by:"project_domain_id"`
  45. // 以项目(ID或Name)过滤列表结果
  46. ProjectId string `json:"project_id"`
  47. // swagger:ignore
  48. // Deprecated
  49. // filter by project_id
  50. Project string `json:"project" yunion-deprecated-by:"project_id"`
  51. // swagger:ignore
  52. // Deprecated
  53. // filter by tenant
  54. Tenant string `json:"tenant" yunion-deprecated-by:"project_id"`
  55. // swagger:ignore
  56. // Deprecated
  57. // filter by tenant_id
  58. TenantId string `json:"tenant_id" yunion-deprecated-by:"project_id"`
  59. }
  60. type UserFilterListInput struct {
  61. // 用户归属域
  62. UserDomainId string `json:"user_domain_id"`
  63. // swagger:ignore
  64. // Deprecated
  65. UserDomain string `json:"user_domain" yunion-deprecated-by:"user_domain_id"`
  66. // filter by user
  67. UserId string `json:"user_id"`
  68. // swagger:ignore
  69. // Deprecated
  70. // filter by user_id
  71. User string `json:"user" yunion-deprecated-by:"user_id"`
  72. }
  73. type GroupFilterListInput struct {
  74. // 组归属域
  75. GroupDomainId string `json:"group_domain_id"`
  76. // swagger:ignore
  77. // Deprecated
  78. GroupDomain string `json:"group_domain" yunion-deprecated-by:"group_domain_id"`
  79. // filter by group
  80. GroupId string `json:"group_id"`
  81. // swagger:ignore
  82. // Deprecated
  83. // filter by group_id
  84. Group string `json:"group" yunion-deprecated-by:"group_id"`
  85. }
  86. type RoleFilterListInput struct {
  87. // 角色归属域
  88. RoleDomainId string `json:"role_domain_id"`
  89. // swagger:ignore
  90. // Deprecated
  91. RoleDomain string `json:"role_domain" yunion-deprecated-by:"role_domain_id"`
  92. // filter by role
  93. RoleId string `json:"role_id"`
  94. // swagger:ignore
  95. // Deprecated
  96. // filter by role_id
  97. Role string `json:"role" yunion-deprecated-by:"role_id"`
  98. }
  99. type ServiceFilterListInput struct {
  100. // 服务类型过滤
  101. ServiceType string `json:"service_type"`
  102. // 服务名称或ID过滤
  103. ServiceId string `json:"service_id"`
  104. // swagger:ignore
  105. // Deprecated
  106. // filter by service_id
  107. Service string `json:"service" yunion-deprecated-by:"service_id"`
  108. // 以服务名称排序
  109. OrderByService string `json:"order_by_service"`
  110. }
  111. type RoleListInput struct {
  112. IdentityBaseResourceListInput
  113. apis.SharableResourceBaseListInput
  114. ProjectFilterListInput
  115. UserFilterListInput
  116. GroupFilterListInput
  117. }
  118. type GroupListInput struct {
  119. IdentityBaseResourceListInput
  120. UserFilterListInput
  121. ProjectFilterListInput
  122. // 名称过滤
  123. Displayname string `json:"displayname"`
  124. // 按IDP过滤
  125. IdpId string `json:"idp_id"`
  126. }
  127. type ProjectListInput struct {
  128. IdentityBaseResourceListInput
  129. UserFilterListInput
  130. GroupFilterListInput
  131. // filter projects by Identity Provider
  132. IdpId string `json:"idp_id"`
  133. // 过滤出指定用户或者组可以加入的项目
  134. Jointable *bool `json:"jointable"`
  135. // project tags filter imposed by policy
  136. PolicyProjectTags tagutils.TTagSetList `json:"policy_project_tags"`
  137. // 通过项目管理员id过滤
  138. AdminId []string `json:"admin_id"`
  139. }
  140. type DomainListInput struct {
  141. apis.StandaloneResourceListInput
  142. Enabled *bool `json:"enabled"`
  143. // 按IDP过滤
  144. IdpId string `json:"idp_id"`
  145. // 按IDP_ENTITY_ID过滤
  146. IdpEntityId string `json:"idp_entity_id"`
  147. // domain tags filter imposed by policy
  148. PolicyDomainTags tagutils.TTagSetList `json:"policy_domain_tags"`
  149. }
  150. type UserListInput struct {
  151. EnabledIdentityBaseResourceListInput
  152. GroupFilterListInput
  153. ProjectFilterListInput
  154. RoleFilterListInput
  155. // 角色生效所在的域
  156. RoleAssignmentDomainId string `json:"role_assignment_domain_id"`
  157. // 角色生效所在的项目
  158. RoleAssignmentProjectId string `json:"role_assignment_project_id"`
  159. // email
  160. Email []string `json:"email"`
  161. // mobile
  162. Mobile []string `json:"mobile"`
  163. // displayname
  164. Displayname []string `json:"displayname"`
  165. // 是否允许web控制台登录
  166. AllowWebConsole *bool `json:"allow_web_console"`
  167. // 是否开启MFA认证
  168. EnableMfa *bool `json:"enable_mfa"`
  169. // 关联IDP
  170. IdpId string `json:"idp_id"`
  171. // 按IDP_ENTITY_ID过滤
  172. IdpEntityId string `json:"idp_entity_id"`
  173. }
  174. type EndpointListInput struct {
  175. apis.StandaloneResourceListInput
  176. ServiceFilterListInput
  177. RegionFilterListInput
  178. // 以Endpoint接口类型过滤,可能值为: internal, internalURL, public, publicURL, admin, adminURL, console
  179. Interface string `json:"interface"`
  180. // 是否启用
  181. Enabled *bool `json:"enabled"`
  182. }
  183. type SJoinProjectsInput struct {
  184. Projects []string `json:"projects"`
  185. Roles []string `json:"roles"`
  186. // 启用用户, 仅用户禁用时生效
  187. Enabled bool `json:"enabled"`
  188. }
  189. func (input SJoinProjectsInput) Validate() error {
  190. if len(input.Projects) == 0 {
  191. return errors.Error("empty projects")
  192. }
  193. if len(input.Roles) == 0 {
  194. return errors.Error("empty roles")
  195. }
  196. return nil
  197. }
  198. type SProjectRole struct {
  199. Project string `json:"project"`
  200. Role string `json:"role"`
  201. }
  202. type SLeaveProjectsInput struct {
  203. ProjectRoles []SProjectRole `json:"project_roles"`
  204. }
  205. func (input SLeaveProjectsInput) Validate() error {
  206. if len(input.ProjectRoles) == 0 {
  207. return errors.Error("empty project_roles")
  208. }
  209. for i := range input.ProjectRoles {
  210. if len(input.ProjectRoles[i].Project) == 0 {
  211. return errors.Error("no project in project_roles")
  212. }
  213. if len(input.ProjectRoles[i].Role) == 0 {
  214. return errors.Error("no role in project_roles")
  215. }
  216. }
  217. return nil
  218. }
  219. type SProjectAddUserGroupInput struct {
  220. Users []string `json:"users"`
  221. Groups []string `json:"groups"`
  222. Roles []string `json:"roles"`
  223. EnableAllUsers bool `json:"enable_all_users"`
  224. }
  225. func (input SProjectAddUserGroupInput) Validate() error {
  226. if len(input.Users) == 0 && len(input.Groups) == 0 {
  227. return errors.Error("empty user and group")
  228. }
  229. if len(input.Roles) == 0 {
  230. return errors.Error("invalid roles")
  231. }
  232. return nil
  233. }
  234. type SUserRole struct {
  235. User string `json:"user"`
  236. Role string `json:"role"`
  237. }
  238. type SGroupRole struct {
  239. Group string `json:"group"`
  240. Role string `json:"role"`
  241. }
  242. type SProjectRemoveUserGroupInput struct {
  243. UserRoles []SUserRole `json:"user_roles"`
  244. GroupRoles []SGroupRole `json:"group_roles"`
  245. }
  246. func (input SProjectRemoveUserGroupInput) Validate() error {
  247. if len(input.UserRoles) == 0 && len(input.GroupRoles) == 0 {
  248. return errors.Error("empty input")
  249. }
  250. for i := range input.UserRoles {
  251. if len(input.UserRoles[i].User) == 0 {
  252. return errors.Error("empty user")
  253. }
  254. if len(input.UserRoles[i].Role) == 0 {
  255. return errors.Error("empty role")
  256. }
  257. }
  258. for i := range input.GroupRoles {
  259. if len(input.GroupRoles[i].Group) == 0 {
  260. return errors.Error("empty group")
  261. }
  262. if len(input.GroupRoles[i].Role) == 0 {
  263. return errors.Error("empty role")
  264. }
  265. }
  266. return nil
  267. }
  268. type IdentityProviderListInput struct {
  269. apis.EnabledStatusStandaloneResourceListInput
  270. apis.DomainizedResourceListInput
  271. // 以驱动类型过滤
  272. Driver []string `json:"driver"`
  273. // 以模板过滤
  274. Template []string `json:"template"`
  275. // 以同步状态过滤
  276. SyncStatus []string `json:"sync_status"`
  277. // 过滤支持SSO的认证源,如果值为all,则列出所有的全局认证源,否则可出sso为域ID的域认证源
  278. // example: all
  279. SsoDomain string `json:"sso_domain"`
  280. AutoCreateProject *bool `json:"auto_create_project"`
  281. AutoCreateUser *bool `json:"auto_create_user"`
  282. }
  283. type CredentialListInput struct {
  284. apis.StandaloneResourceListInput
  285. UserFilterListInput
  286. ProjectFilterListInput
  287. Type []string `json:"type"`
  288. Enabled *bool `json:"enabled"`
  289. }
  290. type PolicyListInput struct {
  291. EnabledIdentityBaseResourceListInput
  292. apis.SharableResourceBaseListInput
  293. // 以类型查询
  294. Type []string `json:"type"`
  295. // 是否显示系统权限
  296. IsSystem *bool `json:"is_system"`
  297. // filter policies by role id
  298. RoleId string `json:"role_id"`
  299. // swagger:ignore
  300. // Deprecated
  301. Role string `json:"role" yunion-deprecated-by:"role_id"`
  302. }
  303. type RegionFilterListInput struct {
  304. // 以区域名称或ID过滤
  305. RegionId string `json:"region_id"`
  306. // swagger:ignore
  307. // Deprecated
  308. Region string `json:"region" yunion-deprecated-by:"region_id"`
  309. }
  310. type RegionListInput struct {
  311. apis.StandaloneResourceListInput
  312. }
  313. type ServiceListInput struct {
  314. apis.StandaloneResourceListInput
  315. // 以Service Type过滤
  316. Type []string `json:"type"`
  317. // 是否启用/禁用
  318. Enabled *bool `json:"enabled"`
  319. }
  320. type IdentityBaseUpdateInput struct {
  321. apis.StandaloneResourceBaseUpdateInput
  322. }
  323. type EnabledIdentityBaseUpdateInput struct {
  324. IdentityBaseUpdateInput
  325. // 是否启用
  326. Enabled *bool `json:"enabled"`
  327. }
  328. type GroupUpdateInput struct {
  329. IdentityBaseUpdateInput
  330. // display name
  331. Displayname string `json:"displayname"`
  332. }
  333. type IdentityProviderUpdateInput struct {
  334. apis.EnabledStatusStandaloneResourceBaseUpdateInput
  335. // TargetDomainId string `json:"target_domain_id"`
  336. // 当认证后用户加入项目不存在时是否自动创建项目
  337. AutoCreateProject *bool `json:"auto_create_project"`
  338. // 当认证后用户不存在时是否自动创建用户
  339. AutoCreateUser *bool `json:"auto_create_user"`
  340. SyncIntervalSeconds *int `json:"sync_interval_seconds"`
  341. // 图标URL
  342. IconUri string `json:"icon_uri"`
  343. }
  344. type PolicyTagInput struct {
  345. // 匹配的资源标签
  346. ObjectTags tagutils.TTagSet `json:"object_tags,allowempty"`
  347. // 匹配的项目标签
  348. ProjectTags tagutils.TTagSet `json:"project_tags,allowempty"`
  349. // 匹配的域标签
  350. DomainTags tagutils.TTagSet `json:"domain_tags,allowempty"`
  351. // 组织架构节点ID
  352. OrgNodeId []string `json:"org_node_id,allowempty"`
  353. }
  354. type PolicyUpdateInput struct {
  355. EnabledIdentityBaseUpdateInput
  356. // Deprecated
  357. // swagger:ignore
  358. Type string `json:"type"`
  359. // Policy内容
  360. Blob jsonutils.JSONObject `json:"blob"`
  361. // 生效范围,project|domain|system
  362. Scope rbacscope.TRbacScope `json:"scope"`
  363. // 是否为系统权限
  364. IsSystem *bool `json:"is_system"`
  365. PolicyTagInput
  366. // Policy tag更新策略,可能的值为:add|remove|remove,默认为add
  367. TagUpdatePolicy string `json:"tag_update_policy"`
  368. }
  369. const (
  370. TAG_UPDATE_POLICY_ADD = "add"
  371. TAG_UPDATE_POLICY_REMOVE = "remove"
  372. TAG_UPDATE_POLICY_REPLACE = "replace"
  373. )
  374. type ProjectUpdateInput struct {
  375. IdentityBaseUpdateInput
  376. // 显示名称
  377. Displayname string `json:"displayname"`
  378. }
  379. type RoleUpdateInput struct {
  380. IdentityBaseUpdateInput
  381. }
  382. type UserUpdateInput struct {
  383. EnabledIdentityBaseUpdateInput
  384. Email string `json:"email"`
  385. Mobile string `json:"mobile"`
  386. Displayname string `json:"displayname"`
  387. IsSystemAccount *bool `json:"is_system_account"`
  388. AllowWebConsole *bool `json:"allow_web_console"`
  389. EnableMfa *bool `json:"enable_mfa"`
  390. Password string `json:"password"`
  391. SkipPasswordComplexityCheck *bool `json:"skip_password_complexity_check"`
  392. Lang string `json:"lang"`
  393. // 过期时间
  394. ExpiredAt *time.Time `json:"expired_at"`
  395. // 清除过期时间
  396. ClearExpire *bool `json:"clear_expire"`
  397. }
  398. type UserCreateInput struct {
  399. EnabledIdentityBaseResourceCreateInput
  400. Email string `json:"email"`
  401. Mobile string `json:"mobile"`
  402. Displayname string `json:"displayname"`
  403. IsSystemAccount *bool `json:"is_system_account"`
  404. AllowWebConsole *bool `json:"allow_web_console"`
  405. EnableMfa *bool `json:"enable_mfa"`
  406. Password string `json:"password"`
  407. SkipPasswordComplexityCheck *bool `json:"skip_password_complexity_check"`
  408. IdpId string `json:"idp_id"`
  409. IdpEntityId string `json:"idp_entity_id"`
  410. Lang string `json:"lang"`
  411. ExpiredAt *time.Time `json:"expired_at"`
  412. }
  413. type ProjectCreateInput struct {
  414. IdentityBaseResourceCreateInput
  415. // 显示名称
  416. Displayname string `json:"displayname"`
  417. }
  418. type GroupCreateInput struct {
  419. IdentityBaseResourceCreateInput
  420. // display name
  421. Displayname string `json:"displayname"`
  422. }
  423. type PolicyCreateInput struct {
  424. EnabledIdentityBaseResourceCreateInput
  425. apis.SharableResourceBaseCreateInput
  426. // Deprecated
  427. // swagger:ignore
  428. Type string `json:"type"`
  429. // policy
  430. Blob jsonutils.JSONObject `json:"blob"`
  431. // 生效范围,project|domain|system
  432. Scope rbacscope.TRbacScope `json:"scope"`
  433. // 是否为系统权限
  434. IsSystem *bool `json:"is_system"`
  435. PolicyTagInput
  436. }
  437. type RoleCreateInput struct {
  438. IdentityBaseResourceCreateInput
  439. apis.SharableResourceBaseCreateInput
  440. }
  441. type PerformGroupAddUsersInput struct {
  442. // 待添加用户列表(ID或名称)
  443. UserIds []string `json:"user_ids"`
  444. // Deprecated
  445. // swagger:ignore
  446. User []string `json:"user" yunion-deprecated-by:"user_ids"`
  447. }
  448. type PerformGroupRemoveUsersInput struct {
  449. // 待删除用户列表(ID或名称)
  450. UserIds []string `json:"user_ids"`
  451. // Deprecated
  452. // swagger:ignore
  453. User []string `json:"user" yunion-deprecated-by:"user_ids"`
  454. }
  455. type UserLinkIdpInput struct {
  456. IdpId string `json:"idp_id"`
  457. IdpEntityId string `json:"idp_entity_id"`
  458. }
  459. type UserUnlinkIdpInput UserLinkIdpInput
  460. type SProjectSetAdminInput struct {
  461. UserId string `json:"user_id"`
  462. }