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 | |
| 9 | type 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. |
| 21 | type RolePage struct { |
| 22 | pagination.SinglePageBase |
| 23 | } |
| 24 | |
| 25 | // IsEmpty determines whether or not a page of Tenants contains any results. |
| 26 | func (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. |
| 35 | func 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 Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 44 | |
| 45 | type AddRoleResult struct { |
| 46 | gophercloud.ErrResult |
| 47 | } |