blob: 3d7c1792af1a9448459fed84dc4a571c8e229f5d [file] [log] [blame]
Daniel Speichert44e3b542015-08-26 20:55:58 -04001package roles
2
3import (
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02004 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02005 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
Daniel Speichert44e3b542015-08-26 20:55:58 -04006)
7
Krzysztof Szukiełojć94da1c02017-05-08 15:56:48 +02008
9func 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 Speichert1cc1c842015-09-15 23:19:13 -040016// ListAssignmentsOptsBuilder allows extensions to add additional parameters to
17// the ListAssignments request.
18type 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.
27type ListAssignmentsOpts struct {
Jon Perrittdb0ae142016-03-13 00:33:41 -060028 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 Speichert44e3b542015-08-26 20:55:58 -040034}
35
Daniel Speichert1cc1c842015-09-15 23:19:13 -040036// ToRolesListAssignmentsQuery formats a ListAssignmentsOpts into a query string.
37func (opts ListAssignmentsOpts) ToRolesListAssignmentsQuery() (string, error) {
Daniel Speichert44e3b542015-08-26 20:55:58 -040038 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittdb0ae142016-03-13 00:33:41 -060039 return q.String(), err
Daniel Speichert1cc1c842015-09-15 23:19:13 -040040}
41
42// ListAssignments enumerates the roles assigned to a specified resource.
43func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager {
44 url := listAssignmentsURL(client)
Jon Perrittdb0ae142016-03-13 00:33:41 -060045 if opts != nil {
46 query, err := opts.ToRolesListAssignmentsQuery()
47 if err != nil {
48 return pagination.Pager{Err: err}
49 }
50 url += query
Daniel Speichert44e3b542015-08-26 20:55:58 -040051 }
Jon Perrittdb0ae142016-03-13 00:33:41 -060052 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt31b66462016-02-25 22:25:30 -060053 return RoleAssignmentPage{pagination.LinkedPageBase{PageResult: r}}
Jon Perrittdb0ae142016-03-13 00:33:41 -060054 })
Daniel Speichert44e3b542015-08-26 20:55:58 -040055}