Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 1 | package roles |
| 2 | |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 3 | import "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 4 | |
| 5 | // RoleAssignment is the result of a role assignments query. |
| 6 | type RoleAssignment struct { |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 7 | Role Role `json:"role,omitempty"` |
| 8 | Scope Scope `json:"scope,omitempty"` |
| 9 | User User `json:"user,omitempty"` |
| 10 | Group Group `json:"group,omitempty"` |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | type Role struct { |
| 14 | ID string `json:"id,omitempty"` |
| 15 | } |
| 16 | |
| 17 | type Scope struct { |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 18 | Domain Domain `json:"domain,omitempty"` |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 19 | Project Project `json:"project,omitempty"` |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | type Domain struct { |
| 23 | ID string `json:"id,omitempty"` |
| 24 | } |
| 25 | |
| 26 | type Project struct { |
| 27 | ID string `json:"id,omitempty"` |
| 28 | } |
| 29 | |
| 30 | type User struct { |
| 31 | ID string `json:"id,omitempty"` |
| 32 | } |
| 33 | |
| 34 | type Group struct { |
| 35 | ID string `json:"id,omitempty"` |
| 36 | } |
| 37 | |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 38 | // RoleAssignmentPage is a single page of RoleAssignments results. |
| 39 | type RoleAssignmentPage struct { |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 40 | pagination.LinkedPageBase |
| 41 | } |
| 42 | |
| 43 | // IsEmpty returns true if the page contains no results. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 44 | func (r RoleAssignmentPage) IsEmpty() (bool, error) { |
| 45 | roleAssignments, err := ExtractRoleAssignments(r) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 46 | return len(roleAssignments) == 0, err |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 49 | // NextPageURL uses the response's embedded link reference to navigate to the next page of results. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 50 | func (r RoleAssignmentPage) NextPageURL() (string, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 51 | var s struct { |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 52 | Links struct { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 53 | Next string `json:"next"` |
| 54 | } `json:"links"` |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 55 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 56 | err := r.ExtractInto(&s) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 57 | return s.Links.Next, err |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 58 | } |
| 59 | |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 60 | // ExtractRoleAssignments extracts a slice of RoleAssignments from a Collection acquired from List. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 61 | func ExtractRoleAssignments(r pagination.Page) ([]RoleAssignment, error) { |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 62 | var s struct { |
| 63 | RoleAssignments []RoleAssignment `json:"role_assignments"` |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 64 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 65 | err := (r.(RoleAssignmentPage)).ExtractInto(&s) |
Jon Perritt | 3c16647 | 2016-02-25 03:07:41 -0600 | [diff] [blame] | 66 | return s.RoleAssignments, err |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 67 | } |