1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package s3control
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	s3controlcust "github.com/aws/aws-sdk-go-v2/service/s3control/internal/customizations"
11	"github.com/aws/aws-sdk-go-v2/service/s3control/types"
12	smithy "github.com/aws/smithy-go"
13	"github.com/aws/smithy-go/middleware"
14	smithyhttp "github.com/aws/smithy-go/transport/http"
15	"strings"
16)
17
18// Gets a list of Amazon S3 Storage Lens configurations. For more information about
19// S3 Storage Lens, see Assessing your storage activity and usage with Amazon S3
20// Storage Lens
21// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage_lens.html) in the
22// Amazon S3 User Guide. To use this action, you must have permission to perform
23// the s3:ListStorageLensConfigurations action. For more information, see Setting
24// permissions to use Amazon S3 Storage Lens
25// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage_lens_iam_permissions.html)
26// in the Amazon S3 User Guide.
27func (c *Client) ListStorageLensConfigurations(ctx context.Context, params *ListStorageLensConfigurationsInput, optFns ...func(*Options)) (*ListStorageLensConfigurationsOutput, error) {
28	if params == nil {
29		params = &ListStorageLensConfigurationsInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "ListStorageLensConfigurations", params, optFns, c.addOperationListStorageLensConfigurationsMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*ListStorageLensConfigurationsOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42type ListStorageLensConfigurationsInput struct {
43
44	// The account ID of the requester.
45	//
46	// This member is required.
47	AccountId *string
48
49	// A pagination token to request the next page of results.
50	NextToken *string
51
52	noSmithyDocumentSerde
53}
54
55type ListStorageLensConfigurationsOutput struct {
56
57	// If the request produced more than the maximum number of S3 Storage Lens
58	// configuration results, you can pass this value into a subsequent request to
59	// retrieve the next page of results.
60	NextToken *string
61
62	// A list of S3 Storage Lens configurations.
63	StorageLensConfigurationList []types.ListStorageLensConfigurationEntry
64
65	// Metadata pertaining to the operation's result.
66	ResultMetadata middleware.Metadata
67
68	noSmithyDocumentSerde
69}
70
71func (c *Client) addOperationListStorageLensConfigurationsMiddlewares(stack *middleware.Stack, options Options) (err error) {
72	err = stack.Serialize.Add(&awsRestxml_serializeOpListStorageLensConfigurations{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	err = stack.Deserialize.Add(&awsRestxml_deserializeOpListStorageLensConfigurations{}, middleware.After)
77	if err != nil {
78		return err
79	}
80	if err = addSetLoggerMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
84		return err
85	}
86	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
87		return err
88	}
89	if err = addResolveEndpointMiddleware(stack, options); err != nil {
90		return err
91	}
92	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
93		return err
94	}
95	if err = addRetryMiddlewares(stack, options); err != nil {
96		return err
97	}
98	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
105		return err
106	}
107	if err = addClientUserAgent(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addEndpointPrefix_opListStorageLensConfigurationsMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addOpListStorageLensConfigurationsValidationMiddleware(stack); err != nil {
120		return err
121	}
122	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListStorageLensConfigurations(options.Region), middleware.Before); err != nil {
123		return err
124	}
125	if err = addMetadataRetrieverMiddleware(stack); err != nil {
126		return err
127	}
128	if err = addListStorageLensConfigurationsUpdateEndpoint(stack, options); err != nil {
129		return err
130	}
131	if err = addResponseErrorMiddleware(stack); err != nil {
132		return err
133	}
134	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
135		return err
136	}
137	if err = addRequestResponseLogging(stack, options); err != nil {
138		return err
139	}
140	return nil
141}
142
143type endpointPrefix_opListStorageLensConfigurationsMiddleware struct {
144}
145
146func (*endpointPrefix_opListStorageLensConfigurationsMiddleware) ID() string {
147	return "EndpointHostPrefix"
148}
149
150func (m *endpointPrefix_opListStorageLensConfigurationsMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
151	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
152) {
153	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
154		return next.HandleSerialize(ctx, in)
155	}
156
157	req, ok := in.Request.(*smithyhttp.Request)
158	if !ok {
159		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
160	}
161
162	input, ok := in.Parameters.(*ListStorageLensConfigurationsInput)
163	if !ok {
164		return out, metadata, fmt.Errorf("unknown input type %T", in.Parameters)
165	}
166
167	var prefix strings.Builder
168	if input.AccountId == nil {
169		return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("AccountId forms part of the endpoint host and so may not be nil")}
170	} else if !smithyhttp.ValidHostLabel(*input.AccountId) {
171		return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("AccountId forms part of the endpoint host and so must match \"[a-zA-Z0-9-]{1,63}\", but was \"%s\"", *input.AccountId)}
172	} else {
173		prefix.WriteString(*input.AccountId)
174	}
175	prefix.WriteString(".")
176	req.URL.Host = prefix.String() + req.URL.Host
177
178	return next.HandleSerialize(ctx, in)
179}
180func addEndpointPrefix_opListStorageLensConfigurationsMiddleware(stack *middleware.Stack) error {
181	return stack.Serialize.Insert(&endpointPrefix_opListStorageLensConfigurationsMiddleware{}, `OperationSerializer`, middleware.After)
182}
183
184// ListStorageLensConfigurationsAPIClient is a client that implements the
185// ListStorageLensConfigurations operation.
186type ListStorageLensConfigurationsAPIClient interface {
187	ListStorageLensConfigurations(context.Context, *ListStorageLensConfigurationsInput, ...func(*Options)) (*ListStorageLensConfigurationsOutput, error)
188}
189
190var _ ListStorageLensConfigurationsAPIClient = (*Client)(nil)
191
192// ListStorageLensConfigurationsPaginatorOptions is the paginator options for
193// ListStorageLensConfigurations
194type ListStorageLensConfigurationsPaginatorOptions struct {
195	// Set to true if pagination should stop if the service returns a pagination token
196	// that matches the most recent token provided to the service.
197	StopOnDuplicateToken bool
198}
199
200// ListStorageLensConfigurationsPaginator is a paginator for
201// ListStorageLensConfigurations
202type ListStorageLensConfigurationsPaginator struct {
203	options   ListStorageLensConfigurationsPaginatorOptions
204	client    ListStorageLensConfigurationsAPIClient
205	params    *ListStorageLensConfigurationsInput
206	nextToken *string
207	firstPage bool
208}
209
210// NewListStorageLensConfigurationsPaginator returns a new
211// ListStorageLensConfigurationsPaginator
212func NewListStorageLensConfigurationsPaginator(client ListStorageLensConfigurationsAPIClient, params *ListStorageLensConfigurationsInput, optFns ...func(*ListStorageLensConfigurationsPaginatorOptions)) *ListStorageLensConfigurationsPaginator {
213	if params == nil {
214		params = &ListStorageLensConfigurationsInput{}
215	}
216
217	options := ListStorageLensConfigurationsPaginatorOptions{}
218
219	for _, fn := range optFns {
220		fn(&options)
221	}
222
223	return &ListStorageLensConfigurationsPaginator{
224		options:   options,
225		client:    client,
226		params:    params,
227		firstPage: true,
228	}
229}
230
231// HasMorePages returns a boolean indicating whether more pages are available
232func (p *ListStorageLensConfigurationsPaginator) HasMorePages() bool {
233	return p.firstPage || p.nextToken != nil
234}
235
236// NextPage retrieves the next ListStorageLensConfigurations page.
237func (p *ListStorageLensConfigurationsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListStorageLensConfigurationsOutput, error) {
238	if !p.HasMorePages() {
239		return nil, fmt.Errorf("no more pages available")
240	}
241
242	params := *p.params
243	params.NextToken = p.nextToken
244
245	result, err := p.client.ListStorageLensConfigurations(ctx, &params, optFns...)
246	if err != nil {
247		return nil, err
248	}
249	p.firstPage = false
250
251	prevToken := p.nextToken
252	p.nextToken = result.NextToken
253
254	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
255		p.nextToken = nil
256	}
257
258	return result, nil
259}
260
261func newServiceMetadataMiddleware_opListStorageLensConfigurations(region string) *awsmiddleware.RegisterServiceMetadata {
262	return &awsmiddleware.RegisterServiceMetadata{
263		Region:        region,
264		ServiceID:     ServiceID,
265		SigningName:   "s3",
266		OperationName: "ListStorageLensConfigurations",
267	}
268}
269
270func copyListStorageLensConfigurationsInputForUpdateEndpoint(params interface{}) (interface{}, error) {
271	input, ok := params.(*ListStorageLensConfigurationsInput)
272	if !ok {
273		return nil, fmt.Errorf("expect *ListStorageLensConfigurationsInput type, got %T", params)
274	}
275	cpy := *input
276	return &cpy, nil
277}
278func backFillListStorageLensConfigurationsAccountID(input interface{}, v string) error {
279	in := input.(*ListStorageLensConfigurationsInput)
280	if in.AccountId != nil {
281		if !strings.EqualFold(*in.AccountId, v) {
282			return fmt.Errorf("error backfilling account id")
283		}
284		return nil
285	}
286	in.AccountId = &v
287	return nil
288}
289func addListStorageLensConfigurationsUpdateEndpoint(stack *middleware.Stack, options Options) error {
290	return s3controlcust.UpdateEndpoint(stack, s3controlcust.UpdateEndpointOptions{
291		Accessor: s3controlcust.UpdateEndpointParameterAccessor{GetARNInput: nopGetARNAccessor,
292			BackfillAccountID: nopBackfillAccountIDAccessor,
293			GetOutpostIDInput: nopGetOutpostIDFromInput,
294			UpdateARNField:    nopSetARNAccessor,
295			CopyInput:         copyListStorageLensConfigurationsInputForUpdateEndpoint,
296		},
297		EndpointResolver:        options.EndpointResolver,
298		EndpointResolverOptions: options.EndpointOptions,
299		UseDualstack:            options.UseDualstack,
300		UseARNRegion:            options.UseARNRegion,
301	})
302}
303