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