Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 6 | ) |
| 7 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 8 | // Role represents an API role resource. |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 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 |
Jamie Hannaford | 41020d5 | 2014-10-30 13:53:31 +0100 | [diff] [blame] | 18 | |
| 19 | // The associated service for this role. |
| 20 | ServiceID string |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // RolePage is a single page of a user Role collection. |
| 24 | type RolePage struct { |
| 25 | pagination.SinglePageBase |
| 26 | } |
| 27 | |
| 28 | // IsEmpty determines whether or not a page of Tenants contains any results. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 29 | func (r RolePage) IsEmpty() (bool, error) { |
| 30 | users, err := ExtractRoles(r) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 31 | return len(users) == 0, err |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // ExtractRoles returns a slice of roles contained in a single page of results. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 35 | func ExtractRoles(r pagination.Page) ([]Role, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 36 | var s struct { |
| 37 | Roles []Role `json:"roles"` |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 38 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 39 | err := (r.(RolePage)).ExtractInto(&s) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 40 | return s.Roles, err |
Jamie Hannaford | 0ca076c | 2014-10-30 13:12:35 +0100 | [diff] [blame] | 41 | } |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 42 | |
Jamie Hannaford | ede3671 | 2014-10-30 13:43:42 +0100 | [diff] [blame] | 43 | // UserRoleResult represents the result of either an AddUserRole or |
| 44 | // a DeleteUserRole operation. |
Jamie Hannaford | b15878a | 2014-10-30 13:26:32 +0100 | [diff] [blame] | 45 | type UserRoleResult struct { |
Jamie Hannaford | 9b642e0 | 2014-10-30 13:20:06 +0100 | [diff] [blame] | 46 | gophercloud.ErrResult |
| 47 | } |