blob: 45652b147ae160a91c3c614bfc7af0a4d864783c [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
Jamie Hannafordede36712014-10-30 13:43:42 +01009// Role represents an API role resource.
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010010type Role struct {
11 // The unique ID for the role.
12 ID string
13
14 // The human-readable name of the role.
15 Name string
16
17 // The description of the role.
18 Description string
19}
20
21// RolePage is a single page of a user Role collection.
22type RolePage struct {
23 pagination.SinglePageBase
24}
25
26// IsEmpty determines whether or not a page of Tenants contains any results.
27func (page RolePage) IsEmpty() (bool, error) {
28 users, err := ExtractRoles(page)
29 if err != nil {
30 return false, err
31 }
32 return len(users) == 0, nil
33}
34
35// ExtractRoles returns a slice of roles contained in a single page of results.
36func ExtractRoles(page pagination.Page) ([]Role, error) {
37 casted := page.(RolePage).Body
38 var response struct {
39 Roles []Role `mapstructure:"roles"`
40 }
41
42 err := mapstructure.Decode(casted, &response)
43 return response.Roles, err
44}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010045
Jamie Hannafordede36712014-10-30 13:43:42 +010046// UserRoleResult represents the result of either an AddUserRole or
47// a DeleteUserRole operation.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010048type UserRoleResult struct {
Jamie Hannaford9b642e02014-10-30 13:20:06 +010049 gophercloud.ErrResult
50}