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 cors configuration for your bucket. If the configuration exists, Amazon 16// S3 replaces it. To use this operation, you must be allowed to perform the 17// s3:PutBucketCORS action. By default, the bucket owner has this permission and 18// can grant it to others. You set this configuration on a bucket so that the 19// bucket can service cross-origin requests. For example, you might want to enable 20// a request whose origin is http://www.example.com to access your Amazon S3 bucket 21// at my.example.bucket.com by using the browser's XMLHttpRequest capability. To 22// enable cross-origin resource sharing (CORS) on a bucket, you add the cors 23// subresource to the bucket. The cors subresource is an XML document in which you 24// configure rules that identify origins and the HTTP methods that can be executed 25// on your bucket. The document is limited to 64 KB in size. When Amazon S3 26// receives a cross-origin request (or a pre-flight OPTIONS request) against a 27// bucket, it evaluates the cors configuration on the bucket and uses the first 28// CORSRule rule that matches the incoming browser request to enable a cross-origin 29// request. For a rule to match, the following conditions must be met: 30// 31// * The 32// request's Origin header must match AllowedOrigin elements. 33// 34// * The request method 35// (for example, GET, PUT, HEAD, and so on) or the Access-Control-Request-Method 36// header in case of a pre-flight OPTIONS request must be one of the AllowedMethod 37// elements. 38// 39// * Every header specified in the Access-Control-Request-Headers 40// request header of a pre-flight request must match an AllowedHeader element. 41// 42// For 43// more information about CORS, go to Enabling Cross-Origin Resource Sharing 44// (https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html) in the Amazon S3 45// User Guide. Related Resources 46// 47// * GetBucketCors 48// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketCors.html) 49// 50// * 51// DeleteBucketCors 52// (https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketCors.html) 53// 54// * 55// RESTOPTIONSobject 56// (https://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html) 57func (c *Client) PutBucketCors(ctx context.Context, params *PutBucketCorsInput, optFns ...func(*Options)) (*PutBucketCorsOutput, error) { 58 if params == nil { 59 params = &PutBucketCorsInput{} 60 } 61 62 result, metadata, err := c.invokeOperation(ctx, "PutBucketCors", params, optFns, c.addOperationPutBucketCorsMiddlewares) 63 if err != nil { 64 return nil, err 65 } 66 67 out := result.(*PutBucketCorsOutput) 68 out.ResultMetadata = metadata 69 return out, nil 70} 71 72type PutBucketCorsInput struct { 73 74 // Specifies the bucket impacted by the corsconfiguration. 75 // 76 // This member is required. 77 Bucket *string 78 79 // Describes the cross-origin access configuration for objects in an Amazon S3 80 // bucket. For more information, see Enabling Cross-Origin Resource Sharing 81 // (https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html) in the Amazon S3 82 // User Guide. 83 // 84 // This member is required. 85 CORSConfiguration *types.CORSConfiguration 86 87 // The base64-encoded 128-bit MD5 digest of the data. This header must be used as a 88 // message integrity check to verify that the request body was not corrupted in 89 // transit. For more information, go to RFC 1864. 90 // (http://www.ietf.org/rfc/rfc1864.txt) For requests made using the Amazon Web 91 // Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is 92 // calculated automatically. 93 ContentMD5 *string 94 95 // The account ID of the expected bucket owner. If the bucket is owned by a 96 // different account, the request will fail with an HTTP 403 (Access Denied) error. 97 ExpectedBucketOwner *string 98 99 noSmithyDocumentSerde 100} 101 102type PutBucketCorsOutput struct { 103 // Metadata pertaining to the operation's result. 104 ResultMetadata middleware.Metadata 105 106 noSmithyDocumentSerde 107} 108 109func (c *Client) addOperationPutBucketCorsMiddlewares(stack *middleware.Stack, options Options) (err error) { 110 err = stack.Serialize.Add(&awsRestxml_serializeOpPutBucketCors{}, middleware.After) 111 if err != nil { 112 return err 113 } 114 err = stack.Deserialize.Add(&awsRestxml_deserializeOpPutBucketCors{}, middleware.After) 115 if err != nil { 116 return err 117 } 118 if err = addSetLoggerMiddleware(stack, options); err != nil { 119 return err 120 } 121 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 122 return err 123 } 124 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 125 return err 126 } 127 if err = addResolveEndpointMiddleware(stack, options); err != nil { 128 return err 129 } 130 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 131 return err 132 } 133 if err = addRetryMiddlewares(stack, options); err != nil { 134 return err 135 } 136 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 137 return err 138 } 139 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 140 return err 141 } 142 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 143 return err 144 } 145 if err = addClientUserAgent(stack); err != nil { 146 return err 147 } 148 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 149 return err 150 } 151 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 152 return err 153 } 154 if err = swapWithCustomHTTPSignerMiddleware(stack, options); err != nil { 155 return err 156 } 157 if err = addOpPutBucketCorsValidationMiddleware(stack); err != nil { 158 return err 159 } 160 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutBucketCors(options.Region), middleware.Before); err != nil { 161 return err 162 } 163 if err = addMetadataRetrieverMiddleware(stack); err != nil { 164 return err 165 } 166 if err = addPutBucketCorsUpdateEndpoint(stack, options); err != nil { 167 return err 168 } 169 if err = addResponseErrorMiddleware(stack); err != nil { 170 return err 171 } 172 if err = v4.AddContentSHA256HeaderMiddleware(stack); err != nil { 173 return err 174 } 175 if err = disableAcceptEncodingGzip(stack); err != nil { 176 return err 177 } 178 if err = addRequestResponseLogging(stack, options); err != nil { 179 return err 180 } 181 if err = smithyhttp.AddContentChecksumMiddleware(stack); err != nil { 182 return err 183 } 184 return nil 185} 186 187func newServiceMetadataMiddleware_opPutBucketCors(region string) *awsmiddleware.RegisterServiceMetadata { 188 return &awsmiddleware.RegisterServiceMetadata{ 189 Region: region, 190 ServiceID: ServiceID, 191 SigningName: "s3", 192 OperationName: "PutBucketCors", 193 } 194} 195 196// getPutBucketCorsBucketMember returns a pointer to string denoting a provided 197// bucket member valueand a boolean indicating if the input has a modeled bucket 198// name, 199func getPutBucketCorsBucketMember(input interface{}) (*string, bool) { 200 in := input.(*PutBucketCorsInput) 201 if in.Bucket == nil { 202 return nil, false 203 } 204 return in.Bucket, true 205} 206func addPutBucketCorsUpdateEndpoint(stack *middleware.Stack, options Options) error { 207 return s3cust.UpdateEndpoint(stack, s3cust.UpdateEndpointOptions{ 208 Accessor: s3cust.UpdateEndpointParameterAccessor{ 209 GetBucketFromInput: getPutBucketCorsBucketMember, 210 }, 211 UsePathStyle: options.UsePathStyle, 212 UseAccelerate: options.UseAccelerate, 213 SupportsAccelerate: true, 214 TargetS3ObjectLambda: false, 215 EndpointResolver: options.EndpointResolver, 216 EndpointResolverOptions: options.EndpointOptions, 217 UseDualstack: options.UseDualstack, 218 UseARNRegion: options.UseARNRegion, 219 DisableMultiRegionAccessPoints: options.DisableMultiRegionAccessPoints, 220 }) 221} 222