blob: de65c51a78dd8b4e487e75f3972b10d6fccaf1a7 [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Daniel Speichert44e3b542015-08-26 20:55:58 -04006)
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 {
Jon Perrittdb0ae142016-03-13 00:33:41 -060020 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 Speichert44e3b542015-08-26 20:55:58 -040026}
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)
Jon Perrittdb0ae142016-03-13 00:33:41 -060031 return q.String(), err
Daniel Speichert1cc1c842015-09-15 23:19:13 -040032}
33
34// ListAssignments enumerates the roles assigned to a specified resource.
35func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager {
36 url := listAssignmentsURL(client)
Jon Perrittdb0ae142016-03-13 00:33:41 -060037 if opts != nil {
38 query, err := opts.ToRolesListAssignmentsQuery()
39 if err != nil {
40 return pagination.Pager{Err: err}
41 }
42 url += query
Daniel Speichert44e3b542015-08-26 20:55:58 -040043 }
Jon Perrittdb0ae142016-03-13 00:33:41 -060044 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt31b66462016-02-25 22:25:30 -060045 return RoleAssignmentPage{pagination.LinkedPageBase{PageResult: r}}
Jon Perrittdb0ae142016-03-13 00:33:41 -060046 })
Daniel Speichert44e3b542015-08-26 20:55:58 -040047}