blob: ebb3aa530b878e5a27da51ece6675433ec8e77cf [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
Jamie Hannaford41020d52014-10-30 13:53:31 +010019
20 // The associated service for this role.
21 ServiceID string
Jamie Hannaford0ca076c2014-10-30 13:12:35 +010022}
23
24// RolePage is a single page of a user Role collection.
25type RolePage struct {
26 pagination.SinglePageBase
27}
28
29// IsEmpty determines whether or not a page of Tenants contains any results.
30func (page RolePage) IsEmpty() (bool, error) {
31 users, err := ExtractRoles(page)
32 if err != nil {
33 return false, err
34 }
35 return len(users) == 0, nil
36}
37
38// ExtractRoles returns a slice of roles contained in a single page of results.
39func ExtractRoles(page pagination.Page) ([]Role, error) {
40 casted := page.(RolePage).Body
41 var response struct {
42 Roles []Role `mapstructure:"roles"`
43 }
44
45 err := mapstructure.Decode(casted, &response)
46 return response.Roles, err
47}
Jamie Hannaford9b642e02014-10-30 13:20:06 +010048
Jamie Hannafordede36712014-10-30 13:43:42 +010049// UserRoleResult represents the result of either an AddUserRole or
50// a DeleteUserRole operation.
Jamie Hannafordb15878a2014-10-30 13:26:32 +010051type UserRoleResult struct {
Jamie Hannaford9b642e02014-10-30 13:20:06 +010052 gophercloud.ErrResult
53}