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	smithy "github.com/aws/smithy-go"
12	"github.com/aws/smithy-go/middleware"
13	smithyhttp "github.com/aws/smithy-go/transport/http"
14	"strings"
15)
16
17// Deletes the access point policy for the specified access point. All Amazon S3 on
18// Outposts REST API requests for this action require an additional parameter of
19// x-amz-outpost-id to be passed with the request and an S3 on Outposts endpoint
20// hostname prefix instead of s3-control. For an example of the request syntax for
21// Amazon S3 on Outposts that uses the S3 on Outposts endpoint hostname prefix and
22// the x-amz-outpost-id derived using the access point ARN, see the Examples
23// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_DeleteAccessPointPolicy.html#API_control_DeleteAccessPointPolicy_Examples)
24// section. The following actions are related to DeleteAccessPointPolicy:
25//
26// *
27// PutAccessPointPolicy
28// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_PutAccessPointPolicy.html)
29//
30// *
31// GetAccessPointPolicy
32// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_GetAccessPointPolicy.html)
33func (c *Client) DeleteAccessPointPolicy(ctx context.Context, params *DeleteAccessPointPolicyInput, optFns ...func(*Options)) (*DeleteAccessPointPolicyOutput, error) {
34	if params == nil {
35		params = &DeleteAccessPointPolicyInput{}
36	}
37
38	result, metadata, err := c.invokeOperation(ctx, "DeleteAccessPointPolicy", params, optFns, addOperationDeleteAccessPointPolicyMiddlewares)
39	if err != nil {
40		return nil, err
41	}
42
43	out := result.(*DeleteAccessPointPolicyOutput)
44	out.ResultMetadata = metadata
45	return out, nil
46}
47
48type DeleteAccessPointPolicyInput struct {
49
50	// The account ID for the account that owns the specified access point.
51	//
52	// This member is required.
53	AccountId *string
54
55	// The name of the access point whose policy you want to delete. For using this
56	// parameter with Amazon S3 on Outposts with the REST API, you must specify the
57	// name and the x-amz-outpost-id as well. For using this parameter with S3 on
58	// Outposts with the AWS SDK and CLI, you must specify the ARN of the access point
59	// accessed in the format arn:aws:s3-outposts:::outpost//accesspoint/. For example,
60	// to access the access point reports-ap through outpost my-outpost owned by
61	// account 123456789012 in Region us-west-2, use the URL encoding of
62	// arn:aws:s3-outposts:us-west-2:123456789012:outpost/my-outpost/accesspoint/reports-ap.
63	// The value must be URL encoded.
64	//
65	// This member is required.
66	Name *string
67}
68
69type DeleteAccessPointPolicyOutput struct {
70	// Metadata pertaining to the operation's result.
71	ResultMetadata middleware.Metadata
72}
73
74func addOperationDeleteAccessPointPolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
75	err = stack.Serialize.Add(&awsRestxml_serializeOpDeleteAccessPointPolicy{}, middleware.After)
76	if err != nil {
77		return err
78	}
79	err = stack.Deserialize.Add(&awsRestxml_deserializeOpDeleteAccessPointPolicy{}, middleware.After)
80	if err != nil {
81		return err
82	}
83	if err = addSetLoggerMiddleware(stack, options); err != nil {
84		return err
85	}
86	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
87		return err
88	}
89	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
90		return err
91	}
92	if err = addResolveEndpointMiddleware(stack, options); err != nil {
93		return err
94	}
95	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
96		return err
97	}
98	if err = addRetryMiddlewares(stack, options); err != nil {
99		return err
100	}
101	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
105		return err
106	}
107	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
108		return err
109	}
110	if err = addClientUserAgent(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
117		return err
118	}
119	if err = addEndpointPrefix_opDeleteAccessPointPolicyMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addOpDeleteAccessPointPolicyValidationMiddleware(stack); err != nil {
123		return err
124	}
125	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDeleteAccessPointPolicy(options.Region), middleware.Before); err != nil {
126		return err
127	}
128	if err = addMetadataRetrieverMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addDeleteAccessPointPolicyUpdateEndpoint(stack, options); err != nil {
132		return err
133	}
134	if err = addResponseErrorMiddleware(stack); err != nil {
135		return err
136	}
137	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
138		return err
139	}
140	if err = addRequestResponseLogging(stack, options); err != nil {
141		return err
142	}
143	return nil
144}
145
146type endpointPrefix_opDeleteAccessPointPolicyMiddleware struct {
147}
148
149func (*endpointPrefix_opDeleteAccessPointPolicyMiddleware) ID() string {
150	return "EndpointHostPrefix"
151}
152
153func (m *endpointPrefix_opDeleteAccessPointPolicyMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
154	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
155) {
156	if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) {
157		return next.HandleSerialize(ctx, in)
158	}
159
160	req, ok := in.Request.(*smithyhttp.Request)
161	if !ok {
162		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
163	}
164
165	input, ok := in.Parameters.(*DeleteAccessPointPolicyInput)
166	if !ok {
167		return out, metadata, fmt.Errorf("unknown input type %T", in.Parameters)
168	}
169
170	var prefix strings.Builder
171	if input.AccountId == nil {
172		return out, metadata, &smithy.SerializationError{Err: fmt.Errorf("AccountId forms part of the endpoint host and so may not be nil")}
173	} else if !smithyhttp.ValidHostLabel(*input.AccountId) {
174		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)}
175	} else {
176		prefix.WriteString(*input.AccountId)
177	}
178	prefix.WriteString(".")
179	req.URL.Host = prefix.String() + req.URL.Host
180
181	return next.HandleSerialize(ctx, in)
182}
183func addEndpointPrefix_opDeleteAccessPointPolicyMiddleware(stack *middleware.Stack) error {
184	return stack.Serialize.Insert(&endpointPrefix_opDeleteAccessPointPolicyMiddleware{}, `OperationSerializer`, middleware.After)
185}
186
187func newServiceMetadataMiddleware_opDeleteAccessPointPolicy(region string) *awsmiddleware.RegisterServiceMetadata {
188	return &awsmiddleware.RegisterServiceMetadata{
189		Region:        region,
190		ServiceID:     ServiceID,
191		SigningName:   "s3",
192		OperationName: "DeleteAccessPointPolicy",
193	}
194}
195
196func copyDeleteAccessPointPolicyInputForUpdateEndpoint(params interface{}) (interface{}, error) {
197	input, ok := params.(*DeleteAccessPointPolicyInput)
198	if !ok {
199		return nil, fmt.Errorf("expect *DeleteAccessPointPolicyInput type, got %T", params)
200	}
201	cpy := *input
202	return &cpy, nil
203}
204func getDeleteAccessPointPolicyARNMember(input interface{}) (*string, bool) {
205	in := input.(*DeleteAccessPointPolicyInput)
206	if in.Name == nil {
207		return nil, false
208	}
209	return in.Name, true
210}
211func setDeleteAccessPointPolicyARNMember(input interface{}, v string) error {
212	in := input.(*DeleteAccessPointPolicyInput)
213	in.Name = &v
214	return nil
215}
216func backFillDeleteAccessPointPolicyAccountID(input interface{}, v string) error {
217	in := input.(*DeleteAccessPointPolicyInput)
218	if in.AccountId != nil {
219		if !strings.EqualFold(*in.AccountId, v) {
220			return fmt.Errorf("error backfilling account id")
221		}
222		return nil
223	}
224	in.AccountId = &v
225	return nil
226}
227func addDeleteAccessPointPolicyUpdateEndpoint(stack *middleware.Stack, options Options) error {
228	return s3controlcust.UpdateEndpoint(stack, s3controlcust.UpdateEndpointOptions{
229		Accessor: s3controlcust.UpdateEndpointParameterAccessor{GetARNInput: getDeleteAccessPointPolicyARNMember,
230			BackfillAccountID: backFillDeleteAccessPointPolicyAccountID,
231			GetOutpostIDInput: nopGetOutpostIDFromInput,
232			UpdateARNField:    setDeleteAccessPointPolicyARNMember,
233			CopyInput:         copyDeleteAccessPointPolicyInputForUpdateEndpoint,
234		},
235		EndpointResolver:        options.EndpointResolver,
236		EndpointResolverOptions: options.EndpointOptions,
237		UseDualstack:            options.UseDualstack,
238		UseARNRegion:            options.UseARNRegion,
239	})
240}
241