1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot
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/iot/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists the policies attached to the specified principal. If you use an Cognito
16// identity, the ID must be in AmazonCognito Identity format
17// (https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html#API_GetCredentialsForIdentity_RequestSyntax).
18// Note: This action is deprecated. Please use ListAttachedPolicies instead.
19// Requires permission to access the ListPrincipalPolicies
20// (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions)
21// action.
22//
23// Deprecated: This operation has been deprecated.
24func (c *Client) ListPrincipalPolicies(ctx context.Context, params *ListPrincipalPoliciesInput, optFns ...func(*Options)) (*ListPrincipalPoliciesOutput, error) {
25	if params == nil {
26		params = &ListPrincipalPoliciesInput{}
27	}
28
29	result, metadata, err := c.invokeOperation(ctx, "ListPrincipalPolicies", params, optFns, c.addOperationListPrincipalPoliciesMiddlewares)
30	if err != nil {
31		return nil, err
32	}
33
34	out := result.(*ListPrincipalPoliciesOutput)
35	out.ResultMetadata = metadata
36	return out, nil
37}
38
39// The input for the ListPrincipalPolicies operation.
40type ListPrincipalPoliciesInput struct {
41
42	// The principal. Valid principals are CertificateArn
43	// (arn:aws:iot:region:accountId:cert/certificateId), thingGroupArn
44	// (arn:aws:iot:region:accountId:thinggroup/groupName) and CognitoId (region:id).
45	//
46	// This member is required.
47	Principal *string
48
49	// Specifies the order for results. If true, results are returned in ascending
50	// creation order.
51	AscendingOrder bool
52
53	// The marker for the next set of results.
54	Marker *string
55
56	// The result page size.
57	PageSize *int32
58
59	noSmithyDocumentSerde
60}
61
62// The output from the ListPrincipalPolicies operation.
63type ListPrincipalPoliciesOutput struct {
64
65	// The marker for the next set of results, or null if there are no additional
66	// results.
67	NextMarker *string
68
69	// The policies.
70	Policies []types.Policy
71
72	// Metadata pertaining to the operation's result.
73	ResultMetadata middleware.Metadata
74
75	noSmithyDocumentSerde
76}
77
78func (c *Client) addOperationListPrincipalPoliciesMiddlewares(stack *middleware.Stack, options Options) (err error) {
79	err = stack.Serialize.Add(&awsRestjson1_serializeOpListPrincipalPolicies{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPrincipalPolicies{}, middleware.After)
84	if err != nil {
85		return err
86	}
87	if err = addSetLoggerMiddleware(stack, options); err != nil {
88		return err
89	}
90	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
91		return err
92	}
93	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
94		return err
95	}
96	if err = addResolveEndpointMiddleware(stack, options); err != nil {
97		return err
98	}
99	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
100		return err
101	}
102	if err = addRetryMiddlewares(stack, options); err != nil {
103		return err
104	}
105	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
109		return err
110	}
111	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
112		return err
113	}
114	if err = addClientUserAgent(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
118		return err
119	}
120	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
121		return err
122	}
123	if err = addOpListPrincipalPoliciesValidationMiddleware(stack); err != nil {
124		return err
125	}
126	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPrincipalPolicies(options.Region), middleware.Before); err != nil {
127		return err
128	}
129	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addResponseErrorMiddleware(stack); err != nil {
133		return err
134	}
135	if err = addRequestResponseLogging(stack, options); err != nil {
136		return err
137	}
138	return nil
139}
140
141// ListPrincipalPoliciesAPIClient is a client that implements the
142// ListPrincipalPolicies operation.
143type ListPrincipalPoliciesAPIClient interface {
144	ListPrincipalPolicies(context.Context, *ListPrincipalPoliciesInput, ...func(*Options)) (*ListPrincipalPoliciesOutput, error)
145}
146
147var _ ListPrincipalPoliciesAPIClient = (*Client)(nil)
148
149// ListPrincipalPoliciesPaginatorOptions is the paginator options for
150// ListPrincipalPolicies
151type ListPrincipalPoliciesPaginatorOptions struct {
152	// The result page size.
153	Limit int32
154
155	// Set to true if pagination should stop if the service returns a pagination token
156	// that matches the most recent token provided to the service.
157	StopOnDuplicateToken bool
158}
159
160// ListPrincipalPoliciesPaginator is a paginator for ListPrincipalPolicies
161type ListPrincipalPoliciesPaginator struct {
162	options   ListPrincipalPoliciesPaginatorOptions
163	client    ListPrincipalPoliciesAPIClient
164	params    *ListPrincipalPoliciesInput
165	nextToken *string
166	firstPage bool
167}
168
169// NewListPrincipalPoliciesPaginator returns a new ListPrincipalPoliciesPaginator
170func NewListPrincipalPoliciesPaginator(client ListPrincipalPoliciesAPIClient, params *ListPrincipalPoliciesInput, optFns ...func(*ListPrincipalPoliciesPaginatorOptions)) *ListPrincipalPoliciesPaginator {
171	if params == nil {
172		params = &ListPrincipalPoliciesInput{}
173	}
174
175	options := ListPrincipalPoliciesPaginatorOptions{}
176	if params.PageSize != nil {
177		options.Limit = *params.PageSize
178	}
179
180	for _, fn := range optFns {
181		fn(&options)
182	}
183
184	return &ListPrincipalPoliciesPaginator{
185		options:   options,
186		client:    client,
187		params:    params,
188		firstPage: true,
189	}
190}
191
192// HasMorePages returns a boolean indicating whether more pages are available
193func (p *ListPrincipalPoliciesPaginator) HasMorePages() bool {
194	return p.firstPage || p.nextToken != nil
195}
196
197// NextPage retrieves the next ListPrincipalPolicies page.
198func (p *ListPrincipalPoliciesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPrincipalPoliciesOutput, error) {
199	if !p.HasMorePages() {
200		return nil, fmt.Errorf("no more pages available")
201	}
202
203	params := *p.params
204	params.Marker = p.nextToken
205
206	var limit *int32
207	if p.options.Limit > 0 {
208		limit = &p.options.Limit
209	}
210	params.PageSize = limit
211
212	result, err := p.client.ListPrincipalPolicies(ctx, &params, optFns...)
213	if err != nil {
214		return nil, err
215	}
216	p.firstPage = false
217
218	prevToken := p.nextToken
219	p.nextToken = result.NextMarker
220
221	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
222		p.nextToken = nil
223	}
224
225	return result, nil
226}
227
228func newServiceMetadataMiddleware_opListPrincipalPolicies(region string) *awsmiddleware.RegisterServiceMetadata {
229	return &awsmiddleware.RegisterServiceMetadata{
230		Region:        region,
231		ServiceID:     ServiceID,
232		SigningName:   "execute-api",
233		OperationName: "ListPrincipalPolicies",
234	}
235}
236