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 the configuration of the website that is specified in the website
16// subresource. To configure a bucket as a website, you can add this subresource on
17// the bucket with website configuration information such as the file name of the
18// index document and any redirect rules. For more information, see Hosting
19// Websites on Amazon S3
20// (https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html). This PUT
21// operation requires the S3:PutBucketWebsite permission. By default, only the
22// bucket owner can configure the website attached to a bucket; however, bucket
23// owners can allow other users to set the website configuration by writing a
24// bucket policy that grants them the S3:PutBucketWebsite permission. To redirect
25// all website requests sent to the bucket's website endpoint, you add a website
26// configuration with the following elements. Because all requests are sent to
27// another website, you don't need to provide index document name for the
28// bucket.
29//
30// * WebsiteConfiguration
31//
32// * RedirectAllRequestsTo
33//
34// * HostName
35//
36// *
37// Protocol
38//
39// If you want granular control over redirects, you can use the following
40// elements to add routing rules that describe conditions for redirecting requests
41// and information about the redirect destination. In this case, the website
42// configuration must provide an index document for the bucket, because some
43// requests might not be redirected.
44//
45// * WebsiteConfiguration
46//
47// * IndexDocument
48//
49// *
50// Suffix
51//
52// * ErrorDocument
53//
54// * Key
55//
56// * RoutingRules
57//
58// * RoutingRule
59//
60// * Condition
61//
62// *
63// HttpErrorCodeReturnedEquals
64//
65// * KeyPrefixEquals
66//
67// * Redirect
68//
69// * Protocol
70//
71// *
72// HostName
73//
74// * ReplaceKeyPrefixWith
75//
76// * ReplaceKeyWith
77//
78// * HttpRedirectCode
79//
80// Amazon
81// S3 has a limitation of 50 routing rules per website configuration. If you
82// require more than 50 routing rules, you can use object redirect. For more
83// information, see Configuring an Object Redirect
84// (https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html) in
85// the Amazon Simple Storage Service Developer Guide.
86func (c *Client) PutBucketWebsite(ctx context.Context, params *PutBucketWebsiteInput, optFns ...func(*Options)) (*PutBucketWebsiteOutput, error) {
87	if params == nil {
88		params = &PutBucketWebsiteInput{}
89	}
90
91	result, metadata, err := c.invokeOperation(ctx, "PutBucketWebsite", params, optFns, addOperationPutBucketWebsiteMiddlewares)
92	if err != nil {
93		return nil, err
94	}
95
96	out := result.(*PutBucketWebsiteOutput)
97	out.ResultMetadata = metadata
98	return out, nil
99}
100
101type PutBucketWebsiteInput struct {
102
103	// The bucket name.
104	//
105	// This member is required.
106	Bucket *string
107
108	// Container for the request.
109	//
110	// This member is required.
111	WebsiteConfiguration *types.WebsiteConfiguration
112
113	// The base64-encoded 128-bit MD5 digest of the data. You must use this header as a
114	// message integrity check to verify that the request body was not corrupted in
115	// transit. For more information, see RFC 1864
116	// (http://www.ietf.org/rfc/rfc1864.txt). For requests made using the AWS Command
117	// Line Interface (CLI) or AWS SDKs, this field is calculated automatically.
118	ContentMD5 *string
119
120	// The account id of the expected bucket owner. If the bucket is owned by a
121	// different account, the request will fail with an HTTP 403 (Access Denied) error.
122	ExpectedBucketOwner *string
123}
124
125type PutBucketWebsiteOutput struct {
126	// Metadata pertaining to the operation's result.
127	ResultMetadata middleware.Metadata
128}
129
130func addOperationPutBucketWebsiteMiddlewares(stack *middleware.Stack, options Options) (err error) {
131	err = stack.Serialize.Add(&awsRestxml_serializeOpPutBucketWebsite{}, middleware.After)
132	if err != nil {
133		return err
134	}
135	err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutBucketWebsite{}, middleware.After)
136	if err != nil {
137		return err
138	}
139	if err = addSetLoggerMiddleware(stack, options); err != nil {
140		return err
141	}
142	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
143		return err
144	}
145	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
146		return err
147	}
148	if err = addResolveEndpointMiddleware(stack, options); err != nil {
149		return err
150	}
151	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
152		return err
153	}
154	if err = addRetryMiddlewares(stack, options); err != nil {
155		return err
156	}
157	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
158		return err
159	}
160	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
161		return err
162	}
163	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
164		return err
165	}
166	if err = addClientUserAgent(stack); err != nil {
167		return err
168	}
169	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
170		return err
171	}
172	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
173		return err
174	}
175	if err = addOpPutBucketWebsiteValidationMiddleware(stack); err != nil {
176		return err
177	}
178	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutBucketWebsite(options.Region), middleware.Before); err != nil {
179		return err
180	}
181	if err = addMetadataRetrieverMiddleware(stack); err != nil {
182		return err
183	}
184	if err = addPutBucketWebsiteUpdateEndpoint(stack, options); err != nil {
185		return err
186	}
187	if err = addResponseErrorMiddleware(stack); err != nil {
188		return err
189	}
190	if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil {
191		return err
192	}
193	if err = disableAcceptEncodingGzip(stack); err != nil {
194		return err
195	}
196	if err = addRequestResponseLogging(stack, options); err != nil {
197		return err
198	}
199	if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil {
200		return err
201	}
202	return nil
203}
204
205func newServiceMetadataMiddleware_opPutBucketWebsite(region string) *awsmiddleware.RegisterServiceMetadata {
206	return &awsmiddleware.RegisterServiceMetadata{
207		Region:        region,
208		ServiceID:     ServiceID,
209		SigningName:   "s3",
210		OperationName: "PutBucketWebsite",
211	}
212}
213
214// getPutBucketWebsiteBucketMember returns a pointer to string denoting a provided
215// bucket member valueand a boolean indicating if the input has a modeled bucket
216// name,
217func getPutBucketWebsiteBucketMember(input interface{}) (*string, bool) {
218	in := input.(*PutBucketWebsiteInput)
219	if in.Bucket == nil {
220		return nil, false
221	}
222	return in.Bucket, true
223}
224func addPutBucketWebsiteUpdateEndpoint(stack *middleware.Stack, options Options) error {
225	return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{
226		Accessor: s3cust.UpdateEndpointParameterAccessor{
227			GetBucketFromInput: getPutBucketWebsiteBucketMember,
228		},
229		UsePathStyle:            options.UsePathStyle,
230		UseAccelerate:           options.UseAccelerate,
231		SupportsAccelerate:      true,
232		EndpointResolver:        options.EndpointResolver,
233		EndpointResolverOptions: options.EndpointOptions,
234		UseDualstack:            options.UseDualstack,
235		UseARNRegion:            options.UseARNRegion,
236	})
237}
238