blob: dfa2665fa3fbe643d868f631c4b08f9f30fc4104 [file] [log] [blame]
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01001package roles
2
3import (
4 "github.com/mitchellh/mapstructure"
Jamie Hannaford9b642e02014-10-30 13:20:06 +01005 "github.com/rackspace/gophercloud"
Jamie Hannaford0ca076c2014-10-30 13:12:35 +01006 "github.com/rackspace/gophercloud/pagination"
7)
8
9type Role struct {
10 // The unique ID for the role.
11 ID string
12
13 // The human-readable name of the role.
14 Name string
15
16 // The description of the role.
17 Description string
18}
19
20// RolePage is a single page of a user Role collection.
21type RolePage struct {
22 pagination.SinglePageBase
23}
24
25// IsEmpty determines whether or not a page of Tenants contains any results.
26func (page RolePage) IsEmpty() (bool, error) {
27 users, err := ExtractRoles(page)
28 if err != nil {
29 return false, err
30 }
31 return len(users) == 0, nil
32}
33
34// ExtractRoles returns a slice of roles contained in a single page of results.
35func ExtractRoles(page pagination.Page) ([]Role, error) {
36 casted := page.(RolePage).Body
37 var response struct {
38 Roles []Role `mapstructure:"roles"`
39 }
40
41 err := mapstructure.Decode(casted, &response)
42 return response.Roles, err
43}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010044
45type AddRoleResult struct {
46 gophercloud.ErrResult
47}