1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package s3
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
10	"github.com/aws/aws-sdk-go-v2/service/s3/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Sets a metrics configuration (specified by the metrics configuration ID) for the
16// bucket. You can have up to 1,000 metrics configurations per bucket. If you're
17// updating an existing metrics configuration, note that this is a full replacement
18// of the existing metrics configuration. If you don't include the elements you
19// want to keep, they are erased. To use this operation, you must have permissions
20// to perform the s3:PutMetricsConfiguration action. The bucket owner has this
21// permission by default. The bucket owner can grant this permission to others. For
22// more information about permissions, see Permissions Related to Bucket
23// Subresource Operations
24// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-with-s3-actions.html#using-with-s3-actions-related-to-bucket-subresources)
25// and Managing Access Permissions to Your Amazon S3 Resources
26// (https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-access-control.html).
27// For information about CloudWatch request metrics for Amazon S3, see Monitoring
28// Metrics with Amazon CloudWatch
29// (https://docs.aws.amazon.com/AmazonS3/latest/dev/cloudwatch-monitoring.html).
30// The following operations are related to PutBucketMetricsConfiguration:
31//
32// *
33// DeleteBucketMetricsConfiguration
34// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketMetricsConfiguration.html)
35//
36// *
37// PutBucketMetricsConfiguration
38// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketMetricsConfiguration.html)
39//
40// *
41// ListBucketMetricsConfigurations
42// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBucketMetricsConfigurations.html)
43//
44// GetBucketLifecycle
45// has the following special error:
46//
47// * Error code: TooManyConfigurations
48//
49// *
50// Description: You are attempting to create a new configuration but have already
51// reached the 1,000-configuration limit.
52//
53// * HTTP Status Code: HTTP 400 Bad Request
54func (c *Client) PutBucketMetricsConfiguration(ctx context.Context, params *PutBucketMetricsConfigurationInput, optFns ...func(*Options)) (*PutBucketMetricsConfigurationOutput, error) {
55	if params == nil {
56		params = &PutBucketMetricsConfigurationInput{}
57	}
58
59	result, metadata, err := c.invokeOperation(ctx, "PutBucketMetricsConfiguration", params, optFns, addOperationPutBucketMetricsConfigurationMiddlewares)
60	if err != nil {
61		return nil, err
62	}
63
64	out := result.(*PutBucketMetricsConfigurationOutput)
65	out.ResultMetadata = metadata
66	return out, nil
67}
68
69type PutBucketMetricsConfigurationInput struct {
70
71	// The name of the bucket for which the metrics configuration is set.
72	//
73	// This member is required.
74	Bucket *string
75
76	// The ID used to identify the metrics configuration.
77	//
78	// This member is required.
79	Id *string
80
81	// Specifies the metrics configuration.
82	//
83	// This member is required.
84	MetricsConfiguration *types.MetricsConfiguration
85
86	// The account ID of the expected bucket owner. If the bucket is owned by a
87	// different account, the request will fail with an HTTP 403 (Access Denied) error.
88	ExpectedBucketOwner *string
89}
90
91type PutBucketMetricsConfigurationOutput struct {
92	// Metadata pertaining to the operation's result.
93	ResultMetadata middleware.Metadata
94}
95
96func addOperationPutBucketMetricsConfigurationMiddlewares(stack *middleware.Stack, options Options) (err error) {
97	err = stack.Serialize.Add(&awsRestxml_serializeOpPutBucketMetricsConfiguration{}, middleware.After)
98	if err != nil {
99		return err
100	}
101	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutBucketMetricsConfiguration{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	if err = addSetLoggerMiddleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addResolveEndpointMiddleware(stack, options); err != nil {
115		return err
116	}
117	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
118		return err
119	}
120	if err = addRetryMiddlewares(stack, options); err != nil {
121		return err
122	}
123	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
124		return err
125	}
126	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
127		return err
128	}
129	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
130		return err
131	}
132	if err = addClientUserAgent(stack); err != nil {
133		return err
134	}
135	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
136		return err
137	}
138	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
139		return err
140	}
141	if err = addOpPutBucketMetricsConfigurationValidationMiddleware(stack); err != nil {
142		return err
143	}
144	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutBucketMetricsConfiguration(options.Region), middleware.Before); err != nil {
145		return err
146	}
147	if err = addMetadataRetrieverMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addPutBucketMetricsConfigurationUpdateEndpoint(stack, options); err != nil {
151		return err
152	}
153	if err = addResponseErrorMiddleware(stack); err != nil {
154		return err
155	}
156	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
157		return err
158	}
159	if err = disableAcceptEncodingGzip(stack); err != nil {
160		return err
161	}
162	if err = addRequestResponseLogging(stack, options); err != nil {
163		return err
164	}
165	return nil
166}
167
168func newServiceMetadataMiddleware_opPutBucketMetricsConfiguration(region string) *awsmiddleware.RegisterServiceMetadata {
169	return &awsmiddleware.RegisterServiceMetadata{
170		Region:        region,
171		ServiceID:     ServiceID,
172		SigningName:   "s3",
173		OperationName: "PutBucketMetricsConfiguration",
174	}
175}
176
177// getPutBucketMetricsConfigurationBucketMember returns a pointer to string
178// denoting a provided bucket member valueand a boolean indicating if the input has
179// a modeled bucket name,
180func getPutBucketMetricsConfigurationBucketMember(input interface{}) (*string, bool) {
181	in := input.(*PutBucketMetricsConfigurationInput)
182	if in.Bucket == nil {
183		return nil, false
184	}
185	return in.Bucket, true
186}
187func addPutBucketMetricsConfigurationUpdateEndpoint(stack *middleware.Stack, options Options) error {
188	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
189		Accessor: s3cust.UpdateEndpointParameterAccessor{
190			GetBucketFromInput: getPutBucketMetricsConfigurationBucketMember,
191		},
192		UsePathStyle:            options.UsePathStyle,
193		UseAccelerate:           options.UseAccelerate,
194		SupportsAccelerate:      true,
195		TargetS3ObjectLambda:    false,
196		EndpointResolver:        options.EndpointResolver,
197		EndpointResolverOptions: options.EndpointOptions,
198		UseDualstack:            options.UseDualstack,
199		UseARNRegion:            options.UseARNRegion,
200	})
201}
202