Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 5 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | ) |
| 8 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 9 | // Role represents an API role resource. |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 10 | type 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 Hannaford | 41020d5 | 2014-10-30 13:53:31 +0100 | [diff] [blame^] | 19 | |
| 20 | // The associated service for this role. |
| 21 | ServiceID string |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | // RolePage is a single page of a user Role collection. |
| 25 | type RolePage struct { |
| 26 | pagination.SinglePageBase |
| 27 | } |
| 28 | |
| 29 | // IsEmpty determines whether or not a page of Tenants contains any results. |
| 30 | func (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. |
| 39 | func 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 Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 48 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 49 | // UserRoleResult represents the result of either an AddUserRole or |
| 50 | // a DeleteUserRole operation. |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 51 | type UserRoleResult struct { |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 52 | gophercloud.ErrResult |
| 53 | } |