1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ram
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// Gets the policies for the specified resources that you own and have shared.
15func (c *Client) GetResourcePolicies(ctx context.Context, params *GetResourcePoliciesInput, optFns ...func(*Options)) (*GetResourcePoliciesOutput, error) {
16	if params == nil {
17		params = &GetResourcePoliciesInput{}
18	}
19
20	result, metadata, err := c.invokeOperation(ctx, "GetResourcePolicies", params, optFns, c.addOperationGetResourcePoliciesMiddlewares)
21	if err != nil {
22		return nil, err
23	}
24
25	out := result.(*GetResourcePoliciesOutput)
26	out.ResultMetadata = metadata
27	return out, nil
28}
29
30type GetResourcePoliciesInput struct {
31
32	// The Amazon Resource Names (ARNs) of the resources.
33	//
34	// This member is required.
35	ResourceArns []string
36
37	// The maximum number of results to return with a single call. To retrieve the
38	// remaining results, make another call with the returned nextToken value.
39	MaxResults *int32
40
41	// The token for the next page of results.
42	NextToken *string
43
44	// The principal.
45	Principal *string
46
47	noSmithyDocumentSerde
48}
49
50type GetResourcePoliciesOutput struct {
51
52	// The token to use to retrieve the next page of results. This value is null when
53	// there are no more results to return.
54	NextToken *string
55
56	// A key policy document, in JSON format.
57	Policies []string
58
59	// Metadata pertaining to the operation's result.
60	ResultMetadata middleware.Metadata
61
62	noSmithyDocumentSerde
63}
64
65func (c *Client) addOperationGetResourcePoliciesMiddlewares(stack *middleware.Stack, options Options) (err error) {
66	err = stack.Serialize.Add(&awsRestjson1_serializeOpGetResourcePolicies{}, middleware.After)
67	if err != nil {
68		return err
69	}
70	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpGetResourcePolicies{}, middleware.After)
71	if err != nil {
72		return err
73	}
74	if err = addSetLoggerMiddleware(stack, options); err != nil {
75		return err
76	}
77	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
78		return err
79	}
80	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
81		return err
82	}
83	if err = addResolveEndpointMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
87		return err
88	}
89	if err = addRetryMiddlewares(stack, options); err != nil {
90		return err
91	}
92	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
93		return err
94	}
95	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
99		return err
100	}
101	if err = addClientUserAgent(stack); err != nil {
102		return err
103	}
104	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addOpGetResourcePoliciesValidationMiddleware(stack); err != nil {
111		return err
112	}
113	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetResourcePolicies(options.Region), middleware.Before); err != nil {
114		return err
115	}
116	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addResponseErrorMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addRequestResponseLogging(stack, options); err != nil {
123		return err
124	}
125	return nil
126}
127
128// GetResourcePoliciesAPIClient is a client that implements the GetResourcePolicies
129// operation.
130type GetResourcePoliciesAPIClient interface {
131	GetResourcePolicies(context.Context, *GetResourcePoliciesInput, ...func(*Options)) (*GetResourcePoliciesOutput, error)
132}
133
134var _ GetResourcePoliciesAPIClient = (*Client)(nil)
135
136// GetResourcePoliciesPaginatorOptions is the paginator options for
137// GetResourcePolicies
138type GetResourcePoliciesPaginatorOptions struct {
139	// The maximum number of results to return with a single call. To retrieve the
140	// remaining results, make another call with the returned nextToken value.
141	Limit int32
142
143	// Set to true if pagination should stop if the service returns a pagination token
144	// that matches the most recent token provided to the service.
145	StopOnDuplicateToken bool
146}
147
148// GetResourcePoliciesPaginator is a paginator for GetResourcePolicies
149type GetResourcePoliciesPaginator struct {
150	options   GetResourcePoliciesPaginatorOptions
151	client    GetResourcePoliciesAPIClient
152	params    *GetResourcePoliciesInput
153	nextToken *string
154	firstPage bool
155}
156
157// NewGetResourcePoliciesPaginator returns a new GetResourcePoliciesPaginator
158func NewGetResourcePoliciesPaginator(client GetResourcePoliciesAPIClient, params *GetResourcePoliciesInput, optFns ...func(*GetResourcePoliciesPaginatorOptions)) *GetResourcePoliciesPaginator {
159	if params == nil {
160		params = &GetResourcePoliciesInput{}
161	}
162
163	options := GetResourcePoliciesPaginatorOptions{}
164	if params.MaxResults != nil {
165		options.Limit = *params.MaxResults
166	}
167
168	for _, fn := range optFns {
169		fn(&options)
170	}
171
172	return &GetResourcePoliciesPaginator{
173		options:   options,
174		client:    client,
175		params:    params,
176		firstPage: true,
177	}
178}
179
180// HasMorePages returns a boolean indicating whether more pages are available
181func (p *GetResourcePoliciesPaginator) HasMorePages() bool {
182	return p.firstPage || p.nextToken != nil
183}
184
185// NextPage retrieves the next GetResourcePolicies page.
186func (p *GetResourcePoliciesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetResourcePoliciesOutput, error) {
187	if !p.HasMorePages() {
188		return nil, fmt.Errorf("no more pages available")
189	}
190
191	params := *p.params
192	params.NextToken = p.nextToken
193
194	var limit *int32
195	if p.options.Limit > 0 {
196		limit = &p.options.Limit
197	}
198	params.MaxResults = limit
199
200	result, err := p.client.GetResourcePolicies(ctx, &params, optFns...)
201	if err != nil {
202		return nil, err
203	}
204	p.firstPage = false
205
206	prevToken := p.nextToken
207	p.nextToken = result.NextToken
208
209	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
210		p.nextToken = nil
211	}
212
213	return result, nil
214}
215
216func newServiceMetadataMiddleware_opGetResourcePolicies(region string) *awsmiddleware.RegisterServiceMetadata {
217	return &awsmiddleware.RegisterServiceMetadata{
218		Region:        region,
219		ServiceID:     ServiceID,
220		SigningName:   "ram",
221		OperationName: "GetResourcePolicies",
222	}
223}
224