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