Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [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" |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 6 | ) |
| 7 | |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 8 | // ListAssignmentsOptsBuilder allows extensions to add additional parameters to |
| 9 | // the ListAssignments request. |
| 10 | type ListAssignmentsOptsBuilder interface { |
| 11 | ToRolesListAssignmentsQuery() (string, error) |
| 12 | } |
| 13 | |
| 14 | // ListAssignmentsOpts allows you to query the ListAssignments method. |
| 15 | // Specify one of or a combination of GroupId, RoleId, ScopeDomainId, ScopeProjectId, |
| 16 | // and/or UserId to search for roles assigned to corresponding entities. |
| 17 | // Effective lists effective assignments at the user, project, and domain level, |
| 18 | // allowing for the effects of group membership. |
| 19 | type ListAssignmentsOpts struct { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 20 | GroupID string `q:"group.id"` |
| 21 | RoleID string `q:"role.id"` |
| 22 | ScopeDomainID string `q:"scope.domain.id"` |
| 23 | ScopeProjectID string `q:"scope.project.id"` |
| 24 | UserID string `q:"user.id"` |
| 25 | Effective *bool `q:"effective"` |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 26 | } |
| 27 | |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 28 | // ToRolesListAssignmentsQuery formats a ListAssignmentsOpts into a query string. |
| 29 | func (opts ListAssignmentsOpts) ToRolesListAssignmentsQuery() (string, error) { |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 30 | q, err := gophercloud.BuildQueryString(opts) |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 31 | return q.String(), err |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // ListAssignments enumerates the roles assigned to a specified resource. |
| 35 | func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager { |
| 36 | url := listAssignmentsURL(client) |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 37 | if opts != nil { |
| 38 | query, err := opts.ToRolesListAssignmentsQuery() |
| 39 | if err != nil { |
| 40 | return pagination.Pager{Err: err} |
| 41 | } |
| 42 | url += query |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 43 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 44 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 45 | return RoleAssignmentPage{pagination.LinkedPageBase{PageResult: r}} |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 46 | }) |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 47 | } |