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// Puts an Amazon S3 Storage Lens configuration. For more information about S3
19// Storage Lens, see Working with Amazon S3 Storage Lens
20// (https://docs.aws.amazon.com/https:/docs.aws.amazon.com/AmazonS3/latest/dev/storage_lens.html)
21// in the Amazon Simple Storage Service Developer Guide. To use this action, you
22// must have permission to perform the s3:PutStorageLensConfiguration action. For
23// more information, see Setting permissions to use Amazon S3 Storage Lens
24// (https://docs.aws.amazon.com/AmazonS3/latest/dev/storage_lens.html#storage_lens_IAM)
25// in the Amazon Simple Storage Service Developer Guide.
26func (c *Client) PutStorageLensConfiguration(ctx context.Context, params *PutStorageLensConfigurationInput, optFns ...func(*Options)) (*PutStorageLensConfigurationOutput, error) {
27	if params == nil {
28		params = &PutStorageLensConfigurationInput{}
29	}
30
31	result, metadata, err := c.invokeOperation(ctx, "PutStorageLensConfiguration", params, optFns, addOperationPutStorageLensConfigurationMiddlewares)
32	if err != nil {
33		return nil, err
34	}
35
36	out := result.(*PutStorageLensConfigurationOutput)
37	out.ResultMetadata = metadata
38	return out, nil
39}
40
41type PutStorageLensConfigurationInput struct {
42
43	// The account ID of the requester.
44	//
45	// This member is required.
46	AccountId *string
47
48	// The ID of the S3 Storage Lens configuration.
49	//
50	// This member is required.
51	ConfigId *string
52
53	// The S3 Storage Lens configuration.
54	//
55	// This member is required.
56	StorageLensConfiguration *types.StorageLensConfiguration
57
58	// The tag set of the S3 Storage Lens configuration. You can set up to a maximum of
59	// 50 tags.
60	Tags []types.StorageLensTag
61}
62
63type PutStorageLensConfigurationOutput struct {
64	// Metadata pertaining to the operation's result.
65	ResultMetadata middleware.Metadata
66}
67
68func addOperationPutStorageLensConfigurationMiddlewares(stack *middleware.Stack, options Options) (err error) {
69	err = stack.Serialize.Add(&awsRestxml_serializeOpPutStorageLensConfiguration{}, middleware.After)
70	if err != nil {
71		return err
72	}
73	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutStorageLensConfiguration{}, middleware.After)
74	if err != nil {
75		return err
76	}
77	if err = addSetLoggerMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
81		return err
82	}
83	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
84		return err
85	}
86	if err = addResolveEndpointMiddleware(stack, options); err != nil {
87		return err
88	}
89	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
90		return err
91	}
92	if err = addRetryMiddlewares(stack, options); err != nil {
93		return err
94	}
95	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
102		return err
103	}
104	if err = addClientUserAgent(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = addEndpointPrefix_opPutStorageLensConfigurationMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addOpPutStorageLensConfigurationValidationMiddleware(stack); err != nil {
117		return err
118	}
119	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutStorageLensConfiguration(options.Region), middleware.Before); err != nil {
120		return err
121	}
122	if err = addMetadataRetrieverMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addPutStorageLensConfigurationUpdateEndpoint(stack, options); err != nil {
126		return err
127	}
128	if err = addResponseErrorMiddleware(stack); err != nil {
129		return err
130	}
131	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
132		return err
133	}
134	if err = addRequestResponseLogging(stack, options); err != nil {
135		return err
136	}
137	return nil
138}
139
140type endpointPrefix_opPutStorageLensConfigurationMiddleware struct {
141}
142
143func (*endpointPrefix_opPutStorageLensConfigurationMiddleware) ID() string {
144	return "EndpointHostPrefix"
145}
146
147func (m *endpointPrefix_opPutStorageLensConfigurationMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
148	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
149) {
150	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
151		return next.HandleSerialize(ctx, in)
152	}
153
154	req, ok := in.Request.(*smithyhttp.Request)
155	if !ok {
156		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
157	}
158
159	input, ok := in.Parameters.(*PutStorageLensConfigurationInput)
160	if !ok {
161		return out, metadata, fmt.Errorf("unknown input type %T", in.Parameters)
162	}
163
164	var prefix strings.Builder
165	if input.AccountId == nil {
166		return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("AccountId forms part of the endpoint host and so may not be nil")}
167	} else if !smithyhttp.ValidHostLabel(*input.AccountId) {
168		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)}
169	} else {
170		prefix.WriteString(*input.AccountId)
171	}
172	prefix.WriteString(".")
173	req.URL.Host = prefix.String() + req.URL.Host
174
175	return next.HandleSerialize(ctx, in)
176}
177func addEndpointPrefix_opPutStorageLensConfigurationMiddleware(stack *middleware.Stack) error {
178	return stack.Serialize.Insert(&endpointPrefix_opPutStorageLensConfigurationMiddleware{}, `OperationSerializer`, middleware.After)
179}
180
181func newServiceMetadataMiddleware_opPutStorageLensConfiguration(region string) *awsmiddleware.RegisterServiceMetadata {
182	return &awsmiddleware.RegisterServiceMetadata{
183		Region:        region,
184		ServiceID:     ServiceID,
185		SigningName:   "s3",
186		OperationName: "PutStorageLensConfiguration",
187	}
188}
189
190func copyPutStorageLensConfigurationInputForUpdateEndpoint(params interface{}) (interface{}, error) {
191	input, ok := params.(*PutStorageLensConfigurationInput)
192	if !ok {
193		return nil, fmt.Errorf("expect *PutStorageLensConfigurationInput type, got %T", params)
194	}
195	cpy := *input
196	return &cpy, nil
197}
198func backFillPutStorageLensConfigurationAccountID(input interface{}, v string) error {
199	in := input.(*PutStorageLensConfigurationInput)
200	if in.AccountId != nil {
201		if !strings.EqualFold(*in.AccountId, v) {
202			return fmt.Errorf("error backfilling account id")
203		}
204		return nil
205	}
206	in.AccountId = &v
207	return nil
208}
209func addPutStorageLensConfigurationUpdateEndpoint(stack *middleware.Stack, options Options) error {
210	return s3controlcust.UpdateEndpoint(stack, s3controlcust.UpdateEndpointOptions{
211		Accessor: s3controlcust.UpdateEndpointParameterAccessor{GetARNInput: nopGetARNAccessor,
212			BackfillAccountID: nopBackfillAccountIDAccessor,
213			GetOutpostIDInput: nopGetOutpostIDFromInput,
214			UpdateARNField:    nopSetARNAccessor,
215			CopyInput:         copyPutStorageLensConfigurationInputForUpdateEndpoint,
216		},
217		EndpointResolver:        options.EndpointResolver,
218		EndpointResolverOptions: options.EndpointOptions,
219		UseDualstack:            options.UseDualstack,
220		UseARNRegion:            options.UseARNRegion,
221	})
222}
223