Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 1 | package roles |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | "github.com/rackspace/gophercloud/pagination" |
| 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 { |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [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"` |
| 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) |
| 31 | if err != nil { |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 32 | return "", err |
| 33 | } |
| 34 | return q.String(), nil |
| 35 | } |
| 36 | |
| 37 | // ListAssignments enumerates the roles assigned to a specified resource. |
| 38 | func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager { |
| 39 | url := listAssignmentsURL(client) |
| 40 | query, err := opts.ToRolesListAssignmentsQuery() |
| 41 | if err != nil { |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 42 | return pagination.Pager{Err: err} |
| 43 | } |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 44 | url += query |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 45 | createPage := func(r pagination.PageResult) pagination.Page { |
| 46 | return RoleAssignmentsPage{pagination.LinkedPageBase{PageResult: r}} |
| 47 | } |
| 48 | |
Daniel Speichert | 1cc1c84 | 2015-09-15 23:19:13 -0400 | [diff] [blame] | 49 | return pagination.NewPager(client, url, createPage) |
Daniel Speichert | 44e3b54 | 2015-08-26 20:55:58 -0400 | [diff] [blame] | 50 | } |