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// Creates or modifies the PublicAccessBlock configuration for an Amazon S3 bucket.
16// To use this operation, you must have the s3:PutBucketPublicAccessBlock
17// permission. For more information about Amazon S3 permissions, see Specifying
18// Permissions in a Policy
19// (https://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html).
20// When Amazon S3 evaluates the PublicAccessBlock configuration for a bucket or an
21// object, it checks the PublicAccessBlock configuration for both the bucket (or
22// the bucket that contains the object) and the bucket owner's account. If the
23// PublicAccessBlock configurations are different between the bucket and the
24// account, Amazon S3 uses the most restrictive combination of the bucket-level and
25// account-level settings. For more information about when Amazon S3 considers a
26// bucket or an object public, see The Meaning of "Public"
27// (https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html#access-control-block-public-access-policy-status).
28// Related Resources
29//
30// * GetPublicAccessBlock
31// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetPublicAccessBlock.html)
32//
33// *
34// DeletePublicAccessBlock
35// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeletePublicAccessBlock.html)
36//
37// *
38// GetBucketPolicyStatus
39// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketPolicyStatus.html)
40//
41// *
42// Using Amazon S3 Block Public Access
43// (https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html)
44func (c *Client) PutPublicAccessBlock(ctx context.Context, params *PutPublicAccessBlockInput, optFns ...func(*Options)) (*PutPublicAccessBlockOutput, error) {
45	if params == nil {
46		params = &PutPublicAccessBlockInput{}
47	}
48
49	result, metadata, err := c.invokeOperation(ctx, "PutPublicAccessBlock", params, optFns, addOperationPutPublicAccessBlockMiddlewares)
50	if err != nil {
51		return nil, err
52	}
53
54	out := result.(*PutPublicAccessBlockOutput)
55	out.ResultMetadata = metadata
56	return out, nil
57}
58
59type PutPublicAccessBlockInput struct {
60
61	// The name of the Amazon S3 bucket whose PublicAccessBlock configuration you want
62	// to set.
63	//
64	// This member is required.
65	Bucket *string
66
67	// The PublicAccessBlock configuration that you want to apply to this Amazon S3
68	// bucket. You can enable the configuration options in any combination. For more
69	// information about when Amazon S3 considers a bucket or object public, see The
70	// Meaning of "Public"
71	// (https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html#access-control-block-public-access-policy-status)
72	// in the Amazon Simple Storage Service Developer Guide.
73	//
74	// This member is required.
75	PublicAccessBlockConfiguration *types.PublicAccessBlockConfiguration
76
77	// The MD5 hash of the PutPublicAccessBlock request body. For requests made using
78	// the AWS Command Line Interface (CLI) or AWS SDKs, this field is calculated
79	// automatically.
80	ContentMD5 *string
81
82	// The account id of the expected bucket owner. If the bucket is owned by a
83	// different account, the request will fail with an HTTP 403 (Access Denied) error.
84	ExpectedBucketOwner *string
85}
86
87type PutPublicAccessBlockOutput struct {
88	// Metadata pertaining to the operation's result.
89	ResultMetadata middleware.Metadata
90}
91
92func addOperationPutPublicAccessBlockMiddlewares(stack *middleware.Stack, options Options) (err error) {
93	err = stack.Serialize.Add(&awsRestxml_serializeOpPutPublicAccessBlock{}, middleware.After)
94	if err != nil {
95		return err
96	}
97	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutPublicAccessBlock{}, middleware.After)
98	if err != nil {
99		return err
100	}
101	if err = addSetLoggerMiddleware(stack, options); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
105		return err
106	}
107	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addResolveEndpointMiddleware(stack, options); err != nil {
111		return err
112	}
113	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
114		return err
115	}
116	if err = addRetryMiddlewares(stack, options); err != nil {
117		return err
118	}
119	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
120		return err
121	}
122	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
123		return err
124	}
125	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
126		return err
127	}
128	if err = addClientUserAgent(stack); err != nil {
129		return err
130	}
131	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
132		return err
133	}
134	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
135		return err
136	}
137	if err = addOpPutPublicAccessBlockValidationMiddleware(stack); err != nil {
138		return err
139	}
140	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutPublicAccessBlock(options.Region), middleware.Before); err != nil {
141		return err
142	}
143	if err = addMetadataRetrieverMiddleware(stack); err != nil {
144		return err
145	}
146	if err = addPutPublicAccessBlockUpdateEndpoint(stack, options); err != nil {
147		return err
148	}
149	if err = addResponseErrorMiddleware(stack); err != nil {
150		return err
151	}
152	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
153		return err
154	}
155	if err = disableAcceptEncodingGzip(stack); err != nil {
156		return err
157	}
158	if err = addRequestResponseLogging(stack, options); err != nil {
159		return err
160	}
161	if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil {
162		return err
163	}
164	return nil
165}
166
167func newServiceMetadataMiddleware_opPutPublicAccessBlock(region string) *awsmiddleware.RegisterServiceMetadata {
168	return &awsmiddleware.RegisterServiceMetadata{
169		Region:        region,
170		ServiceID:     ServiceID,
171		SigningName:   "s3",
172		OperationName: "PutPublicAccessBlock",
173	}
174}
175
176// getPutPublicAccessBlockBucketMember returns a pointer to string denoting a
177// provided bucket member valueand a boolean indicating if the input has a modeled
178// bucket name,
179func getPutPublicAccessBlockBucketMember(input interface{}) (*string, bool) {
180	in := input.(*PutPublicAccessBlockInput)
181	if in.Bucket == nil {
182		return nil, false
183	}
184	return in.Bucket, true
185}
186func addPutPublicAccessBlockUpdateEndpoint(stack *middleware.Stack, options Options) error {
187	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
188		Accessor: s3cust.UpdateEndpointParameterAccessor{
189			GetBucketFromInput: getPutPublicAccessBlockBucketMember,
190		},
191		UsePathStyle:            options.UsePathStyle,
192		UseAccelerate:           options.UseAccelerate,
193		SupportsAccelerate:      true,
194		EndpointResolver:        options.EndpointResolver,
195		EndpointResolverOptions: options.EndpointOptions,
196		UseDualstack:            options.UseDualstack,
197		UseARNRegion:            options.UseARNRegion,
198	})
199}
200