blob: d95c1e52f6f84a52676b460d77e3e23fc3abaee4 [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
3import (
4 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
6)
7
Daniel Speichert1cc1c842015-09-15 23:19:13 -04008// ListAssignmentsOptsBuilder allows extensions to add additional parameters to
9// the ListAssignments request.
10type 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.
19type ListAssignmentsOpts struct {
Daniel Speichert44e3b542015-08-26 20:55:58 -040020 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 Speichert1cc1c842015-09-15 23:19:13 -040028// ToRolesListAssignmentsQuery formats a ListAssignmentsOpts into a query string.
29func (opts ListAssignmentsOpts) ToRolesListAssignmentsQuery() (string, error) {
Daniel Speichert44e3b542015-08-26 20:55:58 -040030 q, err := gophercloud.BuildQueryString(opts)
31 if err != nil {
Daniel Speichert1cc1c842015-09-15 23:19:13 -040032 return "", err
33 }
34 return q.String(), nil
35}
36
37// ListAssignments enumerates the roles assigned to a specified resource.
38func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager {
39 url := listAssignmentsURL(client)
40 query, err := opts.ToRolesListAssignmentsQuery()
41 if err != nil {
Daniel Speichert44e3b542015-08-26 20:55:58 -040042 return pagination.Pager{Err: err}
43 }
Daniel Speichert1cc1c842015-09-15 23:19:13 -040044 url += query
Daniel Speichert44e3b542015-08-26 20:55:58 -040045 createPage := func(r pagination.PageResult) pagination.Page {
46 return RoleAssignmentsPage{pagination.LinkedPageBase{PageResult: r}}
47 }
48
Daniel Speichert1cc1c842015-09-15 23:19:13 -040049 return pagination.NewPager(client, url, createPage)
Daniel Speichert44e3b542015-08-26 20:55:58 -040050}