blob: 86f21a06866f2164efc9be4e348a7ebc6aff6340 [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
Jon Perritt3c166472016-02-25 03:07:41 -06003import "github.com/gophercloud/gophercloud/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
38// RoleAssignmentsPage is a single page of RoleAssignments results.
39type RoleAssignmentsPage struct {
40 pagination.LinkedPageBase
41}
42
43// IsEmpty returns true if the page contains no results.
44func (p RoleAssignmentsPage) IsEmpty() (bool, error) {
45 roleAssignments, err := ExtractRoleAssignments(p)
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.
50func (page RoleAssignmentsPage) 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 Perritt3c166472016-02-25 03:07:41 -060056 err := page.ExtractInto(&s)
57 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.
61func ExtractRoleAssignments(page pagination.Page) ([]RoleAssignment, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060062 r := page.(RoleAssignmentsPage)
63 var s struct {
64 RoleAssignments []RoleAssignment `json:"role_assignments"`
Daniel Speichert44e3b542015-08-26 20:55:58 -040065 }
Jon Perritt3c166472016-02-25 03:07:41 -060066 err := r.ExtractInto(&s)
67 return s.RoleAssignments, err
Daniel Speichert44e3b542015-08-26 20:55:58 -040068}