blob: b32567b23b97e1124667852a3e4aae8019ff8871 [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02003import "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
Daniel Speichert44e3b542015-08-26 20:55:58 -04004
5// RoleAssignment is the result of a role assignments query.
6type RoleAssignment struct {
Daniel Speichert1cc1c842015-09-15 23:19:13 -04007 Role Role `json:"role,omitempty"`
8 Scope Scope `json:"scope,omitempty"`
9 User User `json:"user,omitempty"`
10 Group Group `json:"group,omitempty"`
Daniel Speichert44e3b542015-08-26 20:55:58 -040011}
12
13type Role struct {
14 ID string `json:"id,omitempty"`
15}
16
17type Scope struct {
Daniel Speichert1cc1c842015-09-15 23:19:13 -040018 Domain Domain `json:"domain,omitempty"`
Jon Perritt3c166472016-02-25 03:07:41 -060019 Project Project `json:"project,omitempty"`
Daniel Speichert44e3b542015-08-26 20:55:58 -040020}
21
22type Domain struct {
23 ID string `json:"id,omitempty"`
24}
25
26type Project struct {
27 ID string `json:"id,omitempty"`
28}
29
30type User struct {
31 ID string `json:"id,omitempty"`
32}
33
34type Group struct {
35 ID string `json:"id,omitempty"`
36}
37
Jon Perritt31b66462016-02-25 22:25:30 -060038// RoleAssignmentPage is a single page of RoleAssignments results.
39type RoleAssignmentPage struct {
Daniel Speichert44e3b542015-08-26 20:55:58 -040040 pagination.LinkedPageBase
41}
42
43// IsEmpty returns true if the page contains no results.
Jon Perritt31b66462016-02-25 22:25:30 -060044func (r RoleAssignmentPage) IsEmpty() (bool, error) {
45 roleAssignments, err := ExtractRoleAssignments(r)
Jon Perritt3c166472016-02-25 03:07:41 -060046 return len(roleAssignments) == 0, err
Daniel Speichert44e3b542015-08-26 20:55:58 -040047}
48
Daniel Speichert1cc1c842015-09-15 23:19:13 -040049// NextPageURL uses the response's embedded link reference to navigate to the next page of results.
Jon Perritt31b66462016-02-25 22:25:30 -060050func (r RoleAssignmentPage) NextPageURL() (string, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060051 var s struct {
Daniel Speichert1cc1c842015-09-15 23:19:13 -040052 Links struct {
Jon Perritt3c166472016-02-25 03:07:41 -060053 Next string `json:"next"`
54 } `json:"links"`
Daniel Speichert1cc1c842015-09-15 23:19:13 -040055 }
Jon Perritt31b66462016-02-25 22:25:30 -060056 err := r.ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060057 return s.Links.Next, err
Daniel Speichert1cc1c842015-09-15 23:19:13 -040058}
59
Daniel Speichert44e3b542015-08-26 20:55:58 -040060// ExtractRoleAssignments extracts a slice of RoleAssignments from a Collection acquired from List.
Jon Perritt31b66462016-02-25 22:25:30 -060061func ExtractRoleAssignments(r pagination.Page) ([]RoleAssignment, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060062 var s struct {
63 RoleAssignments []RoleAssignment `json:"role_assignments"`
Daniel Speichert44e3b542015-08-26 20:55:58 -040064 }
Jon Perritt31b66462016-02-25 22:25:30 -060065 err := (r.(RoleAssignmentPage)).ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060066 return s.RoleAssignments, err
Daniel Speichert44e3b542015-08-26 20:55:58 -040067}