1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iam
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/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Lists the names of the inline policies that are embedded in the specified IAM
15// role. An IAM role can also have managed policies attached to it. To list the
16// managed policies that are attached to a role, use ListAttachedRolePolicies. For
17// more information about policies, see Managed Policies and Inline Policies
18// (https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html)
19// in the IAM User Guide. You can paginate the results using the MaxItems and
20// Marker parameters. If there are no inline policies embedded with the specified
21// role, the operation returns an empty list.
22func (c *Client) ListRolePolicies(ctx context.Context, params *ListRolePoliciesInput, optFns ...func(*Options)) (*ListRolePoliciesOutput, error) {
23	if params == nil {
24		params = &ListRolePoliciesInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "ListRolePolicies", params, optFns, addOperationListRolePoliciesMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*ListRolePoliciesOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37type ListRolePoliciesInput struct {
38
39	// The name of the role to list policies for. This parameter allows (through its
40	// regex pattern (http://wikipedia.org/wiki/regex)) a string of characters
41	// consisting of upper and lowercase alphanumeric characters with no spaces. You
42	// can also include any of the following characters: _+=,.@-
43	//
44	// This member is required.
45	RoleName *string
46
47	// Use this parameter only when paginating results and only after you receive a
48	// response indicating that the results are truncated. Set it to the value of the
49	// Marker element in the response that you received to indicate where the next call
50	// should start.
51	Marker *string
52
53	// Use this only when paginating results to indicate the maximum number of items
54	// you want in the response. If additional items exist beyond the maximum you
55	// specify, the IsTruncated response element is true. If you do not include this
56	// parameter, the number of items defaults to 100. Note that IAM might return fewer
57	// results, even when there are more results available. In that case, the
58	// IsTruncated response element returns true, and Marker contains a value to
59	// include in the subsequent call that tells the service where to continue from.
60	MaxItems *int32
61}
62
63// Contains the response to a successful ListRolePolicies request.
64type ListRolePoliciesOutput struct {
65
66	// A list of policy names.
67	//
68	// This member is required.
69	PolicyNames []string
70
71	// A flag that indicates whether there are more items to return. If your results
72	// were truncated, you can make a subsequent pagination request using the Marker
73	// request parameter to retrieve more items. Note that IAM might return fewer than
74	// the MaxItems number of results even when there are more results available. We
75	// recommend that you check IsTruncated after every call to ensure that you receive
76	// all your results.
77	IsTruncated bool
78
79	// When IsTruncated is true, this element is present and contains the value to use
80	// for the Marker parameter in a subsequent pagination request.
81	Marker *string
82
83	// Metadata pertaining to the operation's result.
84	ResultMetadata middleware.Metadata
85}
86
87func addOperationListRolePoliciesMiddlewares(stack *middleware.Stack, options Options) (err error) {
88	err = stack.Serialize.Add(&awsAwsquery_serializeOpListRolePolicies{}, middleware.After)
89	if err != nil {
90		return err
91	}
92	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpListRolePolicies{}, middleware.After)
93	if err != nil {
94		return err
95	}
96	if err = addSetLoggerMiddleware(stack, options); err != nil {
97		return err
98	}
99	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
100		return err
101	}
102	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
103		return err
104	}
105	if err = addResolveEndpointMiddleware(stack, options); err != nil {
106		return err
107	}
108	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
109		return err
110	}
111	if err = addRetryMiddlewares(stack, options); err != nil {
112		return err
113	}
114	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
115		return err
116	}
117	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
118		return err
119	}
120	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
121		return err
122	}
123	if err = addClientUserAgent(stack); err != nil {
124		return err
125	}
126	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
127		return err
128	}
129	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
130		return err
131	}
132	if err = addOpListRolePoliciesValidationMiddleware(stack); err != nil {
133		return err
134	}
135	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListRolePolicies(options.Region), middleware.Before); err != nil {
136		return err
137	}
138	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
139		return err
140	}
141	if err = addResponseErrorMiddleware(stack); err != nil {
142		return err
143	}
144	if err = addRequestResponseLogging(stack, options); err != nil {
145		return err
146	}
147	return nil
148}
149
150// ListRolePoliciesAPIClient is a client that implements the ListRolePolicies
151// operation.
152type ListRolePoliciesAPIClient interface {
153	ListRolePolicies(context.Context, *ListRolePoliciesInput, ...func(*Options)) (*ListRolePoliciesOutput, error)
154}
155
156var _ ListRolePoliciesAPIClient = (*Client)(nil)
157
158// ListRolePoliciesPaginatorOptions is the paginator options for ListRolePolicies
159type ListRolePoliciesPaginatorOptions struct {
160	// Use this only when paginating results to indicate the maximum number of items
161	// you want in the response. If additional items exist beyond the maximum you
162	// specify, the IsTruncated response element is true. If you do not include this
163	// parameter, the number of items defaults to 100. Note that IAM might return fewer
164	// results, even when there are more results available. In that case, the
165	// IsTruncated response element returns true, and Marker contains a value to
166	// include in the subsequent call that tells the service where to continue from.
167	Limit int32
168
169	// Set to true if pagination should stop if the service returns a pagination token
170	// that matches the most recent token provided to the service.
171	StopOnDuplicateToken bool
172}
173
174// ListRolePoliciesPaginator is a paginator for ListRolePolicies
175type ListRolePoliciesPaginator struct {
176	options   ListRolePoliciesPaginatorOptions
177	client    ListRolePoliciesAPIClient
178	params    *ListRolePoliciesInput
179	nextToken *string
180	firstPage bool
181}
182
183// NewListRolePoliciesPaginator returns a new ListRolePoliciesPaginator
184func NewListRolePoliciesPaginator(client ListRolePoliciesAPIClient, params *ListRolePoliciesInput, optFns ...func(*ListRolePoliciesPaginatorOptions)) *ListRolePoliciesPaginator {
185	options := ListRolePoliciesPaginatorOptions{}
186	if params.MaxItems != nil {
187		options.Limit = *params.MaxItems
188	}
189
190	for _, fn := range optFns {
191		fn(&options)
192	}
193
194	if params == nil {
195		params = &ListRolePoliciesInput{}
196	}
197
198	return &ListRolePoliciesPaginator{
199		options:   options,
200		client:    client,
201		params:    params,
202		firstPage: true,
203	}
204}
205
206// HasMorePages returns a boolean indicating whether more pages are available
207func (p *ListRolePoliciesPaginator) HasMorePages() bool {
208	return p.firstPage || p.nextToken != nil
209}
210
211// NextPage retrieves the next ListRolePolicies page.
212func (p *ListRolePoliciesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListRolePoliciesOutput, error) {
213	if !p.HasMorePages() {
214		return nil, fmt.Errorf("no more pages available")
215	}
216
217	params := *p.params
218	params.Marker = p.nextToken
219
220	var limit *int32
221	if p.options.Limit > 0 {
222		limit = &p.options.Limit
223	}
224	params.MaxItems = limit
225
226	result, err := p.client.ListRolePolicies(ctx, &params, optFns...)
227	if err != nil {
228		return nil, err
229	}
230	p.firstPage = false
231
232	prevToken := p.nextToken
233	p.nextToken = result.Marker
234
235	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
236		p.nextToken = nil
237	}
238
239	return result, nil
240}
241
242func newServiceMetadataMiddleware_opListRolePolicies(region string) *awsmiddleware.RegisterServiceMetadata {
243	return &awsmiddleware.RegisterServiceMetadata{
244		Region:        region,
245		ServiceID:     ServiceID,
246		SigningName:   "iam",
247		OperationName: "ListRolePolicies",
248	}
249}
250