blob: 31cb7a36ab4d8c4f4c74b104347a8a7a33866bde [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
3import (
4 "github.com/rackspace/gophercloud/pagination"
5
6 "github.com/mitchellh/mapstructure"
7)
8
9// RoleAssignment is the result of a role assignments query.
10type RoleAssignment struct {
11 Role *Role `json:"role,omitempty"`
12 Scope *Scope `json:"scope,omitempty"`
13 User *User `json:"user,omitempty"`
14 Group *Group `json:"group,omitempty"`
15}
16
17type Role struct {
18 ID string `json:"id,omitempty"`
19}
20
21type Scope struct {
22 Domain *Domain `json:"domain,omitempty"`
23 Project *Project `json:"domain,omitempty"`
24}
25
26type Domain struct {
27 ID string `json:"id,omitempty"`
28}
29
30type Project struct {
31 ID string `json:"id,omitempty"`
32}
33
34type User struct {
35 ID string `json:"id,omitempty"`
36}
37
38type Group struct {
39 ID string `json:"id,omitempty"`
40}
41
42// RoleAssignmentsPage is a single page of RoleAssignments results.
43type RoleAssignmentsPage struct {
44 pagination.LinkedPageBase
45}
46
47// IsEmpty returns true if the page contains no results.
48func (p RoleAssignmentsPage) IsEmpty() (bool, error) {
49 roleAssignments, err := ExtractRoleAssignments(p)
50 if err != nil {
51 return true, err
52 }
53 return len(roleAssignments) == 0, nil
54}
55
56// ExtractRoleAssignments extracts a slice of RoleAssignments from a Collection acquired from List.
57func ExtractRoleAssignments(page pagination.Page) ([]RoleAssignment, error) {
58 var response struct {
59 RoleAssignments []RoleAssignment `mapstructure:"role_assignments"`
60 }
61
62 err := mapstructure.Decode(page.(RoleAssignmentsPage).Body, &response)
63 return response.RoleAssignments, err
64}