blob: aa932c6993beca5c95387237780f1988ba85dc10 [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 +02008func List(client *gophercloud.ServiceClient) pagination.Pager {
9 url := listURL(client)
10 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Krzysztof Szukiełojć2f616852017-05-12 16:24:00 +020011 return RolePage{pagination.SinglePageBase(r)}
Krzysztof Szukiełojć94da1c02017-05-08 15:56:48 +020012 })
13}
14
Daniel Speichert1cc1c842015-09-15 23:19:13 -040015// ListAssignmentsOptsBuilder allows extensions to add additional parameters to
16// the ListAssignments request.
17type ListAssignmentsOptsBuilder interface {
18 ToRolesListAssignmentsQuery() (string, error)
19}
20
21// ListAssignmentsOpts allows you to query the ListAssignments method.
22// Specify one of or a combination of GroupId, RoleId, ScopeDomainId, ScopeProjectId,
23// and/or UserId to search for roles assigned to corresponding entities.
24// Effective lists effective assignments at the user, project, and domain level,
25// allowing for the effects of group membership.
26type ListAssignmentsOpts struct {
Jon Perrittdb0ae142016-03-13 00:33:41 -060027 GroupID string `q:"group.id"`
28 RoleID string `q:"role.id"`
29 ScopeDomainID string `q:"scope.domain.id"`
30 ScopeProjectID string `q:"scope.project.id"`
31 UserID string `q:"user.id"`
32 Effective *bool `q:"effective"`
Daniel Speichert44e3b542015-08-26 20:55:58 -040033}
34
Daniel Speichert1cc1c842015-09-15 23:19:13 -040035// ToRolesListAssignmentsQuery formats a ListAssignmentsOpts into a query string.
36func (opts ListAssignmentsOpts) ToRolesListAssignmentsQuery() (string, error) {
Daniel Speichert44e3b542015-08-26 20:55:58 -040037 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittdb0ae142016-03-13 00:33:41 -060038 return q.String(), err
Daniel Speichert1cc1c842015-09-15 23:19:13 -040039}
40
41// ListAssignments enumerates the roles assigned to a specified resource.
42func ListAssignments(client *gophercloud.ServiceClient, opts ListAssignmentsOptsBuilder) pagination.Pager {
43 url := listAssignmentsURL(client)
Jon Perrittdb0ae142016-03-13 00:33:41 -060044 if opts != nil {
45 query, err := opts.ToRolesListAssignmentsQuery()
46 if err != nil {
47 return pagination.Pager{Err: err}
48 }
49 url += query
Daniel Speichert44e3b542015-08-26 20:55:58 -040050 }
Jon Perrittdb0ae142016-03-13 00:33:41 -060051 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Jon Perritt31b66462016-02-25 22:25:30 -060052 return RoleAssignmentPage{pagination.LinkedPageBase{PageResult: r}}
Jon Perrittdb0ae142016-03-13 00:33:41 -060053 })
Daniel Speichert44e3b542015-08-26 20:55:58 -040054}