1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package lakeformation
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/lakeformation/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of the principal permissions on the resource, filtered by the
16// permissions of the caller. For example, if you are granted an ALTER permission,
17// you are able to see only the principal permissions for ALTER. This operation
18// returns only those permissions that have been explicitly granted. For
19// information about permissions, see Security and Access Control to Metadata and
20// Data
21// (https://docs-aws.amazon.com/lake-formation/latest/dg/security-data-access.html).
22func (c *Client) ListPermissions(ctx context.Context, params *ListPermissionsInput, optFns ...func(*Options)) (*ListPermissionsOutput, error) {
23	if params == nil {
24		params = &ListPermissionsInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "ListPermissions", params, optFns, c.addOperationListPermissionsMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*ListPermissionsOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37type ListPermissionsInput struct {
38
39	// The identifier for the Data Catalog. By default, the account ID. The Data
40	// Catalog is the persistent metadata store. It contains database definitions,
41	// table definitions, and other control information to manage your AWS Lake
42	// Formation environment.
43	CatalogId *string
44
45	// The maximum number of results to return.
46	MaxResults *int32
47
48	// A continuation token, if this is not the first call to retrieve this list.
49	NextToken *string
50
51	// Specifies a principal to filter the permissions returned.
52	Principal *types.DataLakePrincipal
53
54	// A resource where you will get a list of the principal permissions. This
55	// operation does not support getting privileges on a table with columns. Instead,
56	// call this operation on the table, and the operation returns the table and the
57	// table w columns.
58	Resource *types.Resource
59
60	// Specifies a resource type to filter the permissions returned.
61	ResourceType types.DataLakeResourceType
62
63	noSmithyDocumentSerde
64}
65
66type ListPermissionsOutput struct {
67
68	// A continuation token, if this is not the first call to retrieve this list.
69	NextToken *string
70
71	// A list of principals and their permissions on the resource for the specified
72	// principal and resource types.
73	PrincipalResourcePermissions []types.PrincipalResourcePermissions
74
75	// Metadata pertaining to the operation's result.
76	ResultMetadata middleware.Metadata
77
78	noSmithyDocumentSerde
79}
80
81func (c *Client) addOperationListPermissionsMiddlewares(stack *middleware.Stack, options Options) (err error) {
82	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPermissions{}, middleware.After)
83	if err != nil {
84		return err
85	}
86	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPermissions{}, middleware.After)
87	if err != nil {
88		return err
89	}
90	if err = addSetLoggerMiddleware(stack, options); err != nil {
91		return err
92	}
93	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
94		return err
95	}
96	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
97		return err
98	}
99	if err = addResolveEndpointMiddleware(stack, options); err != nil {
100		return err
101	}
102	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
103		return err
104	}
105	if err = addRetryMiddlewares(stack, options); err != nil {
106		return err
107	}
108	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
115		return err
116	}
117	if err = addClientUserAgent(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
124		return err
125	}
126	if err = addOpListPermissionsValidationMiddleware(stack); err != nil {
127		return err
128	}
129	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPermissions(options.Region), middleware.Before); err != nil {
130		return err
131	}
132	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addResponseErrorMiddleware(stack); err != nil {
136		return err
137	}
138	if err = addRequestResponseLogging(stack, options); err != nil {
139		return err
140	}
141	return nil
142}
143
144// ListPermissionsAPIClient is a client that implements the ListPermissions
145// operation.
146type ListPermissionsAPIClient interface {
147	ListPermissions(context.Context, *ListPermissionsInput, ...func(*Options)) (*ListPermissionsOutput, error)
148}
149
150var _ ListPermissionsAPIClient = (*Client)(nil)
151
152// ListPermissionsPaginatorOptions is the paginator options for ListPermissions
153type ListPermissionsPaginatorOptions struct {
154	// The maximum number of results to return.
155	Limit int32
156
157	// Set to true if pagination should stop if the service returns a pagination token
158	// that matches the most recent token provided to the service.
159	StopOnDuplicateToken bool
160}
161
162// ListPermissionsPaginator is a paginator for ListPermissions
163type ListPermissionsPaginator struct {
164	options   ListPermissionsPaginatorOptions
165	client    ListPermissionsAPIClient
166	params    *ListPermissionsInput
167	nextToken *string
168	firstPage bool
169}
170
171// NewListPermissionsPaginator returns a new ListPermissionsPaginator
172func NewListPermissionsPaginator(client ListPermissionsAPIClient, params *ListPermissionsInput, optFns ...func(*ListPermissionsPaginatorOptions)) *ListPermissionsPaginator {
173	if params == nil {
174		params = &ListPermissionsInput{}
175	}
176
177	options := ListPermissionsPaginatorOptions{}
178	if params.MaxResults != nil {
179		options.Limit = *params.MaxResults
180	}
181
182	for _, fn := range optFns {
183		fn(&options)
184	}
185
186	return &ListPermissionsPaginator{
187		options:   options,
188		client:    client,
189		params:    params,
190		firstPage: true,
191	}
192}
193
194// HasMorePages returns a boolean indicating whether more pages are available
195func (p *ListPermissionsPaginator) HasMorePages() bool {
196	return p.firstPage || p.nextToken != nil
197}
198
199// NextPage retrieves the next ListPermissions page.
200func (p *ListPermissionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPermissionsOutput, error) {
201	if !p.HasMorePages() {
202		return nil, fmt.Errorf("no more pages available")
203	}
204
205	params := *p.params
206	params.NextToken = p.nextToken
207
208	var limit *int32
209	if p.options.Limit > 0 {
210		limit = &p.options.Limit
211	}
212	params.MaxResults = limit
213
214	result, err := p.client.ListPermissions(ctx, &params, optFns...)
215	if err != nil {
216		return nil, err
217	}
218	p.firstPage = false
219
220	prevToken := p.nextToken
221	p.nextToken = result.NextToken
222
223	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
224		p.nextToken = nil
225	}
226
227	return result, nil
228}
229
230func newServiceMetadataMiddleware_opListPermissions(region string) *awsmiddleware.RegisterServiceMetadata {
231	return &awsmiddleware.RegisterServiceMetadata{
232		Region:        region,
233		ServiceID:     ServiceID,
234		SigningName:   "lakeformation",
235		OperationName: "ListPermissions",
236	}
237}
238