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