/
PutBucketCorsCommand.ts
162 lines (152 loc) · 7.07 KB
/
PutBucketCorsCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// smithy-typescript generated code
import { getBucketEndpointPlugin } from "@aws-sdk/middleware-bucket-endpoint";
import { getFlexibleChecksumsPlugin } from "@aws-sdk/middleware-flexible-checksums";
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";
import { PutBucketCorsRequest } from "../models/models_0";
import {
deserializeAws_restXmlPutBucketCorsCommand,
serializeAws_restXmlPutBucketCorsCommand,
} from "../protocols/Aws_restXml";
import { S3ClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../S3Client";
export interface PutBucketCorsCommandInput extends PutBucketCorsRequest {}
export interface PutBucketCorsCommandOutput extends __MetadataBearer {}
/**
* <p>Sets the <code>cors</code> configuration for your bucket. If the configuration exists,
* Amazon S3 replaces it.</p>
* <p>To use this operation, you must be allowed to perform the <code>s3:PutBucketCORS</code>
* action. By default, the bucket owner has this permission and can grant it to others.</p>
* <p>You set this configuration on a bucket so that the bucket can service cross-origin
* requests. For example, you might want to enable a request whose origin is
* <code>http://www.example.com</code> to access your Amazon S3 bucket at
* <code>my.example.bucket.com</code> by using the browser's <code>XMLHttpRequest</code>
* capability.</p>
* <p>To enable cross-origin resource sharing (CORS) on a bucket, you add the
* <code>cors</code> subresource to the bucket. The <code>cors</code> subresource is an XML
* document in which you configure rules that identify origins and the HTTP methods that can
* be executed on your bucket. The document is limited to 64 KB in size. </p>
* <p>When Amazon S3 receives a cross-origin request (or a pre-flight OPTIONS request) against a
* bucket, it evaluates the <code>cors</code> configuration on the bucket and uses the first
* <code>CORSRule</code> rule that matches the incoming browser request to enable a
* cross-origin request. For a rule to match, the following conditions must be met:</p>
* <ul>
* <li>
* <p>The request's <code>Origin</code> header must match <code>AllowedOrigin</code>
* elements.</p>
* </li>
* <li>
* <p>The request method (for example, GET, PUT, HEAD, and so on) or the
* <code>Access-Control-Request-Method</code> header in case of a pre-flight
* <code>OPTIONS</code> request must be one of the <code>AllowedMethod</code>
* elements. </p>
* </li>
* <li>
* <p>Every header specified in the <code>Access-Control-Request-Headers</code> request
* header of a pre-flight request must match an <code>AllowedHeader</code> element.
* </p>
* </li>
* </ul>
* <p> For more information about CORS, go to <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html">Enabling
* Cross-Origin Resource Sharing</a> in the <i>Amazon S3 User Guide</i>.</p>
*
* <p class="title">
* <b>Related Resources</b>
* </p>
* <ul>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketCors.html">GetBucketCors</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketCors.html">DeleteBucketCors</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html">RESTOPTIONSobject</a>
* </p>
* </li>
* </ul>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { S3Client, PutBucketCorsCommand } from "@aws-sdk/client-s3"; // ES Modules import
* // const { S3Client, PutBucketCorsCommand } = require("@aws-sdk/client-s3"); // CommonJS import
* const client = new S3Client(config);
* const command = new PutBucketCorsCommand(input);
* const response = await client.send(command);
* ```
*
* @see {@link PutBucketCorsCommandInput} for command's `input` shape.
* @see {@link PutBucketCorsCommandOutput} for command's `response` shape.
* @see {@link S3ClientResolvedConfig | config} for S3Client's `config` shape.
*
*/
export class PutBucketCorsCommand extends $Command<
PutBucketCorsCommandInput,
PutBucketCorsCommandOutput,
S3ClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties
constructor(readonly input: PutBucketCorsCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}
/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: S3ClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<PutBucketCorsCommandInput, PutBucketCorsCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
this.middlewareStack.use(getBucketEndpointPlugin(configuration));
this.middlewareStack.use(
getFlexibleChecksumsPlugin(configuration, {
input: this.input,
requestAlgorithmMember: "ChecksumAlgorithm",
requestChecksumRequired: true,
})
);
const stack = clientStack.concat(this.middlewareStack);
const { logger } = configuration;
const clientName = "S3Client";
const commandName = "PutBucketCorsCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: PutBucketCorsRequest.filterSensitiveLog,
outputFilterSensitiveLog: (output: any) => output,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}
private serialize(input: PutBucketCorsCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_restXmlPutBucketCorsCommand(input, context);
}
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<PutBucketCorsCommandOutput> {
return deserializeAws_restXmlPutBucketCorsCommand(output, context);
}
// Start section: command_body_extra
// End section: command_body_extra
}