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