@aws-sdk/middleware-sdk-s3 3.972.46 → 3.972.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.browser.js +34 -0
- package/dist-cjs/index.js +57 -53
- package/dist-cjs/submodules/s3/index.browser.js +1028 -0
- package/dist-cjs/submodules/s3/index.js +1042 -0
- package/dist-cjs/submodules/s3-control/index.js +215 -0
- package/dist-es/index.browser.js +1 -0
- package/dist-es/index.js +1 -9
- package/dist-es/submodules/s3/NodeDisableMultiregionAccessPointConfigOptions.js +8 -0
- package/dist-es/submodules/s3/NodeUseArnRegionConfigOptions.js +8 -0
- package/dist-es/submodules/s3/index.browser.js +30 -0
- package/dist-es/submodules/s3/index.js +25 -0
- package/dist-es/submodules/s3/middleware-bucket-endpoint/bucketEndpointMiddleware.js +81 -0
- package/dist-es/submodules/s3/middleware-bucket-endpoint/bucketHostname.js +106 -0
- package/dist-es/submodules/s3/middleware-bucket-endpoint/bucketHostnameUtils.js +111 -0
- package/dist-es/submodules/s3/middleware-bucket-endpoint/configurations.js +12 -0
- package/dist-es/submodules/s3/middleware-expect-continue/middleware-expect-continue.js +41 -0
- package/dist-es/submodules/s3/middleware-location-constraint/configuration.js +3 -0
- package/dist-es/submodules/s3/middleware-location-constraint/middleware-location-constraint.js +24 -0
- package/dist-es/{s3Configuration.js → submodules/s3/middleware-s3-configuration/s3Configuration.js} +1 -1
- package/dist-es/submodules/s3/middleware-ssec/middleware-ssec.js +66 -0
- package/dist-es/{throw-200-exceptions.js → submodules/s3/middleware-throw-200-exceptions/throw-200-exceptions.js} +1 -1
- package/dist-es/{validate-bucket-name.js → submodules/s3/middleware-validate-bucket-name/validate-bucket-name.js} +1 -1
- package/dist-es/submodules/s3-control/configurations.js +7 -0
- package/dist-es/submodules/s3-control/constants.js +5 -0
- package/dist-es/submodules/s3-control/index.js +7 -0
- package/dist-es/submodules/s3-control/middleware-host-prefix-deduplication/hostPrefixDeduplicationMiddleware.js +17 -0
- package/dist-es/submodules/s3-control/middleware-process-arnables/getOutpostEndpoint.js +18 -0
- package/dist-es/submodules/s3-control/middleware-process-arnables/getProcessArnablesPlugin.js +8 -0
- package/dist-es/submodules/s3-control/middleware-process-arnables/parse-outpost-arnables.js +94 -0
- package/dist-es/submodules/s3-control/middleware-process-arnables/update-arnables-request.js +31 -0
- package/dist-es/submodules/s3-control/middleware-redirect-from-postid/redirect-from-postid.js +26 -0
- package/dist-types/index.browser.d.ts +2 -0
- package/dist-types/index.d.ts +2 -9
- package/dist-types/submodules/s3/NodeDisableMultiregionAccessPointConfigOptions.d.ts +4 -0
- package/dist-types/submodules/s3/NodeUseArnRegionConfigOptions.d.ts +9 -0
- package/dist-types/submodules/s3/index.browser.d.ts +36 -0
- package/dist-types/submodules/s3/index.d.ts +32 -0
- package/dist-types/submodules/s3/middleware-bucket-endpoint/bucketEndpointMiddleware.d.ts +17 -0
- package/dist-types/submodules/s3/middleware-bucket-endpoint/bucketHostname.d.ts +16 -0
- package/dist-types/submodules/s3/middleware-bucket-endpoint/bucketHostnameUtils.d.ts +174 -0
- package/dist-types/submodules/s3/middleware-bucket-endpoint/configurations.d.ts +95 -0
- package/dist-types/submodules/s3/middleware-expect-continue/middleware-expect-continue.d.ts +12 -0
- package/dist-types/submodules/s3/middleware-location-constraint/configuration.d.ts +17 -0
- package/dist-types/submodules/s3/middleware-location-constraint/middleware-location-constraint.d.ts +10 -0
- package/dist-types/{s3Configuration.d.ts → submodules/s3/middleware-s3-configuration/s3Configuration.d.ts} +1 -1
- package/dist-types/submodules/s3/middleware-ssec/middleware-ssec.d.ts +12 -0
- package/dist-types/{validate-bucket-name.d.ts → submodules/s3/middleware-validate-bucket-name/validate-bucket-name.d.ts} +1 -1
- package/dist-types/submodules/s3-control/configurations.d.ts +47 -0
- package/dist-types/submodules/s3-control/constants.d.ts +5 -0
- package/dist-types/submodules/s3-control/index.d.ts +9 -0
- package/dist-types/submodules/s3-control/middleware-host-prefix-deduplication/hostPrefixDeduplicationMiddleware.d.ts +17 -0
- package/dist-types/submodules/s3-control/middleware-process-arnables/getOutpostEndpoint.d.ts +6 -0
- package/dist-types/submodules/s3-control/middleware-process-arnables/getProcessArnablesPlugin.d.ts +3 -0
- package/dist-types/submodules/s3-control/middleware-process-arnables/parse-outpost-arnables.d.ts +27 -0
- package/dist-types/submodules/s3-control/middleware-process-arnables/update-arnables-request.d.ts +19 -0
- package/dist-types/submodules/s3-control/middleware-redirect-from-postid/redirect-from-postid.d.ts +17 -0
- package/dist-types/ts3.4/index.browser.d.ts +39 -0
- package/dist-types/ts3.4/index.d.ts +39 -9
- package/dist-types/ts3.4/submodules/s3/NodeDisableMultiregionAccessPointConfigOptions.d.ts +6 -0
- package/dist-types/ts3.4/submodules/s3/NodeUseArnRegionConfigOptions.d.ts +6 -0
- package/dist-types/ts3.4/submodules/s3/index.browser.d.ts +103 -0
- package/dist-types/ts3.4/submodules/s3/index.d.ts +107 -0
- package/dist-types/ts3.4/submodules/s3/middleware-bucket-endpoint/bucketEndpointMiddleware.d.ts +13 -0
- package/dist-types/ts3.4/submodules/s3/middleware-bucket-endpoint/bucketHostname.d.ts +10 -0
- package/dist-types/ts3.4/submodules/s3/middleware-bucket-endpoint/bucketHostnameUtils.d.ts +80 -0
- package/dist-types/ts3.4/submodules/s3/middleware-bucket-endpoint/configurations.d.ts +31 -0
- package/dist-types/ts3.4/submodules/s3/middleware-expect-continue/middleware-expect-continue.d.ts +22 -0
- package/dist-types/ts3.4/submodules/s3/middleware-location-constraint/configuration.d.ts +12 -0
- package/dist-types/ts3.4/submodules/s3/middleware-location-constraint/middleware-location-constraint.d.ts +13 -0
- package/dist-types/ts3.4/{s3Configuration.d.ts → submodules/s3/middleware-s3-configuration/s3Configuration.d.ts} +1 -1
- package/dist-types/ts3.4/submodules/s3/middleware-ssec/middleware-ssec.d.ts +27 -0
- package/dist-types/ts3.4/{validate-bucket-name.d.ts → submodules/s3/middleware-validate-bucket-name/validate-bucket-name.d.ts} +1 -1
- package/dist-types/ts3.4/submodules/s3-control/configurations.d.ts +23 -0
- package/dist-types/ts3.4/submodules/s3-control/constants.d.ts +5 -0
- package/dist-types/ts3.4/submodules/s3-control/index.d.ts +26 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-host-prefix-deduplication/hostPrefixDeduplicationMiddleware.d.ts +13 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-process-arnables/getOutpostEndpoint.d.ts +13 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-process-arnables/getProcessArnablesPlugin.d.ts +5 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-process-arnables/parse-outpost-arnables.d.ts +12 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-process-arnables/update-arnables-request.d.ts +13 -0
- package/dist-types/ts3.4/submodules/s3-control/middleware-redirect-from-postid/redirect-from-postid.d.ts +22 -0
- package/package.json +54 -8
- package/dist-cjs/toStream.browser.js +0 -11
- package/dist-cjs/toStream.js +0 -7
- package/dist-es/s3-express/index.js +0 -7
- package/dist-types/s3-express/index.d.ts +0 -9
- package/dist-types/ts3.4/s3-express/index.d.ts +0 -17
- /package/dist-es/{check-content-length-header.js → submodules/s3/middleware-check-content-length-header/check-content-length-header.js} +0 -0
- /package/dist-es/{bucket-endpoint-middleware.js → submodules/s3/middleware-region-redirect/bucket-endpoint-middleware.js} +0 -0
- /package/dist-es/{region-redirect-endpoint-middleware.js → submodules/s3/middleware-region-redirect/region-redirect-endpoint-middleware.js} +0 -0
- /package/dist-es/{region-redirect-middleware.js → submodules/s3/middleware-region-redirect/region-redirect-middleware.js} +0 -0
- /package/dist-es/{s3-expires-middleware.js → submodules/s3/middleware-s3-expires/s3-expires-middleware.js} +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCache.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCacheEntry.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityProviderImpl.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/classes/SignatureV4S3Express.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/constants.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressHttpSigningMiddleware.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressMiddleware.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/functions/signS3Express.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentity.js +0 -0
- /package/dist-es/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentityProvider.js +0 -0
- /package/dist-es/{protocol → submodules/s3/protocol}/S3RestXmlProtocol.js +0 -0
- /package/dist-es/{toStream.browser.js → submodules/s3/to-stream/toStream.browser.js} +0 -0
- /package/dist-es/{toStream.js → submodules/s3/to-stream/toStream.js} +0 -0
- /package/dist-types/{check-content-length-header.d.ts → submodules/s3/middleware-check-content-length-header/check-content-length-header.d.ts} +0 -0
- /package/dist-types/{bucket-endpoint-middleware.d.ts → submodules/s3/middleware-region-redirect/bucket-endpoint-middleware.d.ts} +0 -0
- /package/dist-types/{region-redirect-endpoint-middleware.d.ts → submodules/s3/middleware-region-redirect/region-redirect-endpoint-middleware.d.ts} +0 -0
- /package/dist-types/{region-redirect-middleware.d.ts → submodules/s3/middleware-region-redirect/region-redirect-middleware.d.ts} +0 -0
- /package/dist-types/{s3-expires-middleware.d.ts → submodules/s3/middleware-s3-expires/s3-expires-middleware.d.ts} +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCache.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCacheEntry.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityProviderImpl.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/classes/SignatureV4S3Express.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/constants.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressHttpSigningMiddleware.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressMiddleware.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/functions/signS3Express.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentity.d.ts +0 -0
- /package/dist-types/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentityProvider.d.ts +0 -0
- /package/dist-types/{throw-200-exceptions.d.ts → submodules/s3/middleware-throw-200-exceptions/throw-200-exceptions.d.ts} +0 -0
- /package/dist-types/{protocol → submodules/s3/protocol}/S3RestXmlProtocol.d.ts +0 -0
- /package/dist-types/{toStream.browser.d.ts → submodules/s3/to-stream/toStream.browser.d.ts} +0 -0
- /package/dist-types/{toStream.d.ts → submodules/s3/to-stream/toStream.d.ts} +0 -0
- /package/dist-types/ts3.4/{check-content-length-header.d.ts → submodules/s3/middleware-check-content-length-header/check-content-length-header.d.ts} +0 -0
- /package/dist-types/ts3.4/{bucket-endpoint-middleware.d.ts → submodules/s3/middleware-region-redirect/bucket-endpoint-middleware.d.ts} +0 -0
- /package/dist-types/ts3.4/{region-redirect-endpoint-middleware.d.ts → submodules/s3/middleware-region-redirect/region-redirect-endpoint-middleware.d.ts} +0 -0
- /package/dist-types/ts3.4/{region-redirect-middleware.d.ts → submodules/s3/middleware-region-redirect/region-redirect-middleware.d.ts} +0 -0
- /package/dist-types/ts3.4/{s3-expires-middleware.d.ts → submodules/s3/middleware-s3-expires/s3-expires-middleware.d.ts} +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCache.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityCacheEntry.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/classes/S3ExpressIdentityProviderImpl.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/classes/SignatureV4S3Express.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/constants.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressHttpSigningMiddleware.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/functions/s3ExpressMiddleware.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/functions/signS3Express.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentity.d.ts +0 -0
- /package/dist-types/ts3.4/{s3-express → submodules/s3/middleware-s3-express}/interfaces/S3ExpressIdentityProvider.d.ts +0 -0
- /package/dist-types/ts3.4/{throw-200-exceptions.d.ts → submodules/s3/middleware-throw-200-exceptions/throw-200-exceptions.d.ts} +0 -0
- /package/dist-types/ts3.4/{protocol → submodules/s3/protocol}/S3RestXmlProtocol.d.ts +0 -0
- /package/dist-types/ts3.4/{toStream.browser.d.ts → submodules/s3/to-stream/toStream.browser.d.ts} +0 -0
- /package/dist-types/ts3.4/{toStream.d.ts → submodules/s3/to-stream/toStream.d.ts} +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var s3 = require('@aws-sdk/middleware-sdk-s3/s3');
|
|
4
|
+
var client = require('@aws-sdk/core/client');
|
|
5
|
+
var util = require('@aws-sdk/core/util');
|
|
6
|
+
var protocols = require('@smithy/core/protocols');
|
|
7
|
+
|
|
8
|
+
function resolveS3ControlConfig(input) {
|
|
9
|
+
const { useArnRegion } = input;
|
|
10
|
+
return Object.assign(input, {
|
|
11
|
+
useArnRegion: typeof useArnRegion === "function" ? useArnRegion : () => Promise.resolve(useArnRegion),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CONTEXT_OUTPOST_ID = "outpost_id";
|
|
16
|
+
const CONTEXT_ACCOUNT_ID = "account_id";
|
|
17
|
+
const CONTEXT_ARN_REGION = "outpost_arn_region";
|
|
18
|
+
const CONTEXT_SIGNING_SERVICE = "signing_service";
|
|
19
|
+
const CONTEXT_SIGNING_REGION = "signing_region";
|
|
20
|
+
|
|
21
|
+
const parseOutpostArnablesMiddleaware = (options) => (next, context) => async (args) => {
|
|
22
|
+
const { input } = args;
|
|
23
|
+
const parameter = input.Name && util.validate(input.Name) ? "Name" : input.Bucket && util.validate(input.Bucket) ? "Bucket" : undefined;
|
|
24
|
+
if (!parameter)
|
|
25
|
+
return next(args);
|
|
26
|
+
const clientRegion = await options.region();
|
|
27
|
+
const useArnRegion = await options.useArnRegion();
|
|
28
|
+
const useFipsEndpoint = await options.useFipsEndpoint();
|
|
29
|
+
const useDualstackEndpoint = await options.useDualstackEndpoint();
|
|
30
|
+
const baseRegion = clientRegion;
|
|
31
|
+
let clientPartition;
|
|
32
|
+
let signingRegion;
|
|
33
|
+
if (options.regionInfoProvider) {
|
|
34
|
+
({ partition: clientPartition, signingRegion = baseRegion } = (await options.regionInfoProvider(baseRegion, {
|
|
35
|
+
useFipsEndpoint,
|
|
36
|
+
useDualstackEndpoint,
|
|
37
|
+
})));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
signingRegion = context.endpointV2?.properties?.authSchemes?.[0]?.signingRegion || baseRegion;
|
|
41
|
+
clientPartition = client.partition(signingRegion).name;
|
|
42
|
+
}
|
|
43
|
+
const validatorOptions = {
|
|
44
|
+
clientPartition};
|
|
45
|
+
let arn;
|
|
46
|
+
if (parameter === "Name") {
|
|
47
|
+
arn = util.parse(input.Name);
|
|
48
|
+
validateOutpostsArn(arn, validatorOptions);
|
|
49
|
+
const { outpostId, accesspointName } = parseOutpostsAccessPointArnResource(arn.resource);
|
|
50
|
+
input.Name = accesspointName;
|
|
51
|
+
context[CONTEXT_OUTPOST_ID] = outpostId;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
arn = util.parse(input.Bucket);
|
|
55
|
+
validateOutpostsArn(arn, validatorOptions);
|
|
56
|
+
const { outpostId, bucketName } = parseOutpostBucketArnResource(arn.resource);
|
|
57
|
+
input.Bucket = bucketName;
|
|
58
|
+
context[CONTEXT_OUTPOST_ID] = outpostId;
|
|
59
|
+
}
|
|
60
|
+
context[CONTEXT_SIGNING_SERVICE] = arn.service;
|
|
61
|
+
context[CONTEXT_SIGNING_REGION] = useArnRegion ? arn.region : signingRegion;
|
|
62
|
+
if (!input.AccountId) {
|
|
63
|
+
input.AccountId = arn.accountId;
|
|
64
|
+
}
|
|
65
|
+
if (useArnRegion)
|
|
66
|
+
context[CONTEXT_ARN_REGION] = arn.region;
|
|
67
|
+
return next(args);
|
|
68
|
+
};
|
|
69
|
+
const parseOutpostArnablesMiddleawareOptions = {
|
|
70
|
+
toMiddleware: "serializerMiddleware",
|
|
71
|
+
relation: "before",
|
|
72
|
+
tags: ["CONVERT_ARN", "OUTPOST_BUCKET_ARN", "OUTPOST_ACCESS_POINT_ARN", "OUTPOST"],
|
|
73
|
+
name: "parseOutpostArnablesMiddleaware",
|
|
74
|
+
};
|
|
75
|
+
const validateOutpostsArn = (arn, { clientPartition }) => {
|
|
76
|
+
const { service, partition, accountId, region } = arn;
|
|
77
|
+
s3.validateOutpostService(service);
|
|
78
|
+
s3.validatePartition(partition, { clientPartition });
|
|
79
|
+
s3.validateAccountId(accountId);
|
|
80
|
+
};
|
|
81
|
+
const parseOutpostsAccessPointArnResource = (resource) => {
|
|
82
|
+
const { outpostId, accesspointName } = s3.getArnResources(resource);
|
|
83
|
+
if (!outpostId) {
|
|
84
|
+
throw new Error("ARN resource should begin with 'outpost'");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
outpostId,
|
|
88
|
+
accesspointName,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const parseOutpostBucketArnResource = (resource) => {
|
|
92
|
+
const delimiter = resource.includes(":") ? ":" : "/";
|
|
93
|
+
const [resourceType, ...rest] = resource.split(delimiter);
|
|
94
|
+
if (resourceType === "outpost") {
|
|
95
|
+
if (!rest[0] || rest[1] !== "bucket" || !rest[2] || rest.length !== 3) {
|
|
96
|
+
throw new Error(`Outpost Bucket ARN should have resource outpost${delimiter}{outpostId}${delimiter}bucket${delimiter}{bucketName}`);
|
|
97
|
+
}
|
|
98
|
+
const [outpostId, _, bucketName] = rest;
|
|
99
|
+
return { outpostId, bucketName };
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new Error(`ARN resource should begin with 'outpost${delimiter}'`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const REGEX_S3CONTROL_HOSTNAME = /^(.+\.)?s3-control(-fips)?[.-]([a-z0-9-]+)\./;
|
|
107
|
+
const getOutpostEndpoint = (hostname, { isCustomEndpoint, regionOverride, useFipsEndpoint }) => {
|
|
108
|
+
if (isCustomEndpoint) {
|
|
109
|
+
return hostname;
|
|
110
|
+
}
|
|
111
|
+
const match = hostname.match(REGEX_S3CONTROL_HOSTNAME);
|
|
112
|
+
if (!match) {
|
|
113
|
+
return hostname;
|
|
114
|
+
}
|
|
115
|
+
const [matched, prefix, fips, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME);
|
|
116
|
+
return [
|
|
117
|
+
`s3-outposts${useFipsEndpoint ? "-fips" : ""}`,
|
|
118
|
+
regionOverride || region,
|
|
119
|
+
hostname.replace(new RegExp(`^${matched}`), ""),
|
|
120
|
+
]
|
|
121
|
+
.filter((part) => part !== undefined)
|
|
122
|
+
.join(".");
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const ACCOUNT_ID_HEADER = "x-amz-account-id";
|
|
126
|
+
const OUTPOST_ID_HEADER = "x-amz-outpost-id";
|
|
127
|
+
const updateArnablesRequestMiddleware = (config) => (next, context) => async (args) => {
|
|
128
|
+
const { request } = args;
|
|
129
|
+
if (!protocols.HttpRequest.isInstance(request)) {
|
|
130
|
+
return next(args);
|
|
131
|
+
}
|
|
132
|
+
if (context[CONTEXT_ACCOUNT_ID]) {
|
|
133
|
+
request.headers[ACCOUNT_ID_HEADER] = context[CONTEXT_ACCOUNT_ID];
|
|
134
|
+
}
|
|
135
|
+
if (context[CONTEXT_OUTPOST_ID]) {
|
|
136
|
+
const { isCustomEndpoint } = config;
|
|
137
|
+
const useFipsEndpoint = await config.useFipsEndpoint();
|
|
138
|
+
request.headers[OUTPOST_ID_HEADER] = context[CONTEXT_OUTPOST_ID];
|
|
139
|
+
request.hostname = getOutpostEndpoint(request.hostname, {
|
|
140
|
+
isCustomEndpoint,
|
|
141
|
+
regionOverride: context[CONTEXT_ARN_REGION],
|
|
142
|
+
useFipsEndpoint,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return next(args);
|
|
146
|
+
};
|
|
147
|
+
const updateArnablesRequestMiddlewareOptions = {
|
|
148
|
+
toMiddleware: "serializerMiddleware",
|
|
149
|
+
relation: "after",
|
|
150
|
+
name: "updateArnablesRequestMiddleware",
|
|
151
|
+
tags: ["ACCOUNT_ID", "OUTPOST_ID", "OUTPOST"],
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const getProcessArnablesPlugin = (options) => ({
|
|
155
|
+
applyToStack: (clientStack) => {
|
|
156
|
+
clientStack.addRelativeTo(parseOutpostArnablesMiddleaware(options), parseOutpostArnablesMiddleawareOptions);
|
|
157
|
+
clientStack.addRelativeTo(updateArnablesRequestMiddleware(options), updateArnablesRequestMiddlewareOptions);
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const hostPrefixDeduplicationMiddleware = () => {
|
|
162
|
+
return (next, context) => (args) => {
|
|
163
|
+
return next(args);
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
const hostPrefixDeduplicationMiddlewareOptions = {
|
|
167
|
+
tags: ["HOST_PREFIX_DEDUPLICATION", "ENDPOINT_V2", "ENDPOINT"],
|
|
168
|
+
toMiddleware: "serializerMiddleware",
|
|
169
|
+
relation: "after",
|
|
170
|
+
name: "hostPrefixDeduplicationMiddleware",
|
|
171
|
+
override: true,
|
|
172
|
+
};
|
|
173
|
+
const getHostPrefixDeduplicationPlugin = (config) => ({
|
|
174
|
+
applyToStack: (clientStack) => {
|
|
175
|
+
clientStack.addRelativeTo(hostPrefixDeduplicationMiddleware(), hostPrefixDeduplicationMiddlewareOptions);
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const redirectFromPostIdMiddleware = (config) => (next, context) => async (args) => {
|
|
180
|
+
const { input, request } = args;
|
|
181
|
+
if (!protocols.HttpRequest.isInstance(request))
|
|
182
|
+
return next(args);
|
|
183
|
+
if (input.OutpostId) {
|
|
184
|
+
const { isCustomEndpoint } = config;
|
|
185
|
+
const useFipsEndpoint = await config.useFipsEndpoint();
|
|
186
|
+
request.hostname = getOutpostEndpoint(request.hostname, { isCustomEndpoint, useFipsEndpoint });
|
|
187
|
+
context[CONTEXT_SIGNING_SERVICE] = "s3-outposts";
|
|
188
|
+
}
|
|
189
|
+
return next(args);
|
|
190
|
+
};
|
|
191
|
+
const redirectFromPostIdMiddlewareOptions = {
|
|
192
|
+
step: "build",
|
|
193
|
+
name: "redirectFromPostIdMiddleware",
|
|
194
|
+
tags: ["OUTPOST"],
|
|
195
|
+
override: true,
|
|
196
|
+
};
|
|
197
|
+
const getRedirectFromPostIdPlugin = (options) => ({
|
|
198
|
+
applyToStack: (clientStack) => {
|
|
199
|
+
clientStack.add(redirectFromPostIdMiddleware(options), redirectFromPostIdMiddlewareOptions);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
exports.getHostPrefixDeduplicationPlugin = getHostPrefixDeduplicationPlugin;
|
|
204
|
+
exports.getOutpostEndpoint = getOutpostEndpoint;
|
|
205
|
+
exports.getProcessArnablesPlugin = getProcessArnablesPlugin;
|
|
206
|
+
exports.getRedirectFromPostIdPlugin = getRedirectFromPostIdPlugin;
|
|
207
|
+
exports.hostPrefixDeduplicationMiddleware = hostPrefixDeduplicationMiddleware;
|
|
208
|
+
exports.hostPrefixDeduplicationMiddlewareOptions = hostPrefixDeduplicationMiddlewareOptions;
|
|
209
|
+
exports.parseOutpostArnablesMiddleaware = parseOutpostArnablesMiddleaware;
|
|
210
|
+
exports.parseOutpostArnablesMiddleawareOptions = parseOutpostArnablesMiddleawareOptions;
|
|
211
|
+
exports.redirectFromPostIdMiddleware = redirectFromPostIdMiddleware;
|
|
212
|
+
exports.redirectFromPostIdMiddlewareOptions = redirectFromPostIdMiddlewareOptions;
|
|
213
|
+
exports.resolveS3ControlConfig = resolveS3ControlConfig;
|
|
214
|
+
exports.updateArnablesRequestMiddleware = updateArnablesRequestMiddleware;
|
|
215
|
+
exports.updateArnablesRequestMiddlewareOptions = updateArnablesRequestMiddlewareOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { checkContentLengthHeader, checkContentLengthHeaderMiddlewareOptions, getCheckContentLengthHeaderPlugin, regionRedirectEndpointMiddleware, regionRedirectEndpointMiddlewareOptions, regionRedirectMiddleware, regionRedirectMiddlewareOptions, getRegionRedirectMiddlewarePlugin, resolveS3Config, s3ExpiresMiddleware, s3ExpiresMiddlewareOptions, getS3ExpiresMiddlewarePlugin, S3ExpressIdentityCache, S3ExpressIdentityCacheEntry, S3ExpressIdentityProviderImpl, SignatureV4S3Express, NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions, getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, throw200ExceptionsMiddleware, throw200ExceptionsMiddlewareOptions, getThrow200ExceptionsPlugin, validateBucketNameMiddleware, validateBucketNameMiddlewareOptions, getValidateBucketNamePlugin, S3RestXmlProtocol, } from "./submodules/s3/index.browser";
|
package/dist-es/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./region-redirect-endpoint-middleware";
|
|
3
|
-
export * from "./region-redirect-middleware";
|
|
4
|
-
export * from "./s3-expires-middleware";
|
|
5
|
-
export * from "./s3-express/index";
|
|
6
|
-
export * from "./s3Configuration";
|
|
7
|
-
export * from "./throw-200-exceptions";
|
|
8
|
-
export * from "./validate-bucket-name";
|
|
9
|
-
export { S3RestXmlProtocol } from "./protocol/S3RestXmlProtocol";
|
|
1
|
+
export { checkContentLengthHeader, checkContentLengthHeaderMiddlewareOptions, getCheckContentLengthHeaderPlugin, regionRedirectEndpointMiddleware, regionRedirectEndpointMiddlewareOptions, regionRedirectMiddleware, regionRedirectMiddlewareOptions, getRegionRedirectMiddlewarePlugin, resolveS3Config, s3ExpiresMiddleware, s3ExpiresMiddlewareOptions, getS3ExpiresMiddlewarePlugin, S3ExpressIdentityCache, S3ExpressIdentityCacheEntry, S3ExpressIdentityProviderImpl, SignatureV4S3Express, NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions, getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, throw200ExceptionsMiddleware, throw200ExceptionsMiddlewareOptions, getThrow200ExceptionsPlugin, validateBucketNameMiddleware, validateBucketNameMiddlewareOptions, getValidateBucketNamePlugin, S3RestXmlProtocol, } from "./submodules/s3/index";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { booleanSelector, SelectorType } from "@smithy/core/config";
|
|
2
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME = "AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS";
|
|
3
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME = "s3_disable_multiregion_access_points";
|
|
4
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS = {
|
|
5
|
+
environmentVariableSelector: (env) => booleanSelector(env, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME, SelectorType.ENV),
|
|
6
|
+
configFileSelector: (profile) => booleanSelector(profile, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME, SelectorType.CONFIG),
|
|
7
|
+
default: false,
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { booleanSelector, SelectorType } from "@smithy/core/config";
|
|
2
|
+
export const NODE_USE_ARN_REGION_ENV_NAME = "AWS_S3_USE_ARN_REGION";
|
|
3
|
+
export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region";
|
|
4
|
+
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS = {
|
|
5
|
+
environmentVariableSelector: (env) => booleanSelector(env, NODE_USE_ARN_REGION_ENV_NAME, SelectorType.ENV),
|
|
6
|
+
configFileSelector: (profile) => booleanSelector(profile, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG),
|
|
7
|
+
default: undefined,
|
|
8
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const no = Symbol.for("node-only");
|
|
2
|
+
export { checkContentLengthHeader, checkContentLengthHeaderMiddlewareOptions, getCheckContentLengthHeaderPlugin, } from "./middleware-check-content-length-header/check-content-length-header";
|
|
3
|
+
export { regionRedirectEndpointMiddleware, regionRedirectEndpointMiddlewareOptions, } from "./middleware-region-redirect/region-redirect-endpoint-middleware";
|
|
4
|
+
export { regionRedirectMiddleware, regionRedirectMiddlewareOptions, getRegionRedirectMiddlewarePlugin, } from "./middleware-region-redirect/region-redirect-middleware";
|
|
5
|
+
export { resolveS3Config } from "./middleware-s3-configuration/s3Configuration";
|
|
6
|
+
export { s3ExpiresMiddleware, s3ExpiresMiddlewareOptions, getS3ExpiresMiddlewarePlugin, } from "./middleware-s3-expires/s3-expires-middleware";
|
|
7
|
+
export { S3ExpressIdentityCache } from "./middleware-s3-express/classes/S3ExpressIdentityCache";
|
|
8
|
+
export { S3ExpressIdentityCacheEntry } from "./middleware-s3-express/classes/S3ExpressIdentityCacheEntry";
|
|
9
|
+
export { S3ExpressIdentityProviderImpl } from "./middleware-s3-express/classes/S3ExpressIdentityProviderImpl";
|
|
10
|
+
export { SignatureV4S3Express } from "./middleware-s3-express/classes/SignatureV4S3Express";
|
|
11
|
+
export const NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS = no;
|
|
12
|
+
export { getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions, } from "./middleware-s3-express/functions/s3ExpressMiddleware";
|
|
13
|
+
export { getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, } from "./middleware-s3-express/functions/s3ExpressHttpSigningMiddleware";
|
|
14
|
+
export { throw200ExceptionsMiddleware, throw200ExceptionsMiddlewareOptions, getThrow200ExceptionsPlugin, } from "./middleware-throw-200-exceptions/throw-200-exceptions";
|
|
15
|
+
export { validateBucketNameMiddleware, validateBucketNameMiddlewareOptions, getValidateBucketNamePlugin, } from "./middleware-validate-bucket-name/validate-bucket-name";
|
|
16
|
+
export { S3RestXmlProtocol } from "./protocol/S3RestXmlProtocol";
|
|
17
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS = no;
|
|
18
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME = no;
|
|
19
|
+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME = no;
|
|
20
|
+
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS = no;
|
|
21
|
+
export const NODE_USE_ARN_REGION_ENV_NAME = no;
|
|
22
|
+
export const NODE_USE_ARN_REGION_INI_NAME = no;
|
|
23
|
+
export { bucketEndpointMiddleware, bucketEndpointMiddlewareOptions, getBucketEndpointPlugin, } from "./middleware-bucket-endpoint/bucketEndpointMiddleware";
|
|
24
|
+
export { bucketHostname } from "./middleware-bucket-endpoint/bucketHostname";
|
|
25
|
+
export { resolveBucketEndpointConfig } from "./middleware-bucket-endpoint/configurations";
|
|
26
|
+
export { getArnResources, getSuffixForArnEndpoint, validateOutpostService, validatePartition, validateAccountId, validateRegion, validateDNSHostLabel, validateNoDualstack, validateNoFIPS, } from "./middleware-bucket-endpoint/bucketHostnameUtils";
|
|
27
|
+
export { addExpectContinueMiddleware, addExpectContinueMiddlewareOptions, getAddExpectContinuePlugin, } from "./middleware-expect-continue/middleware-expect-continue";
|
|
28
|
+
export { locationConstraintMiddleware, locationConstraintMiddlewareOptions, getLocationConstraintPlugin, } from "./middleware-location-constraint/middleware-location-constraint";
|
|
29
|
+
export { resolveLocationConstraintConfig } from "./middleware-location-constraint/configuration";
|
|
30
|
+
export { ssecMiddleware, ssecMiddlewareOptions, getSsecPlugin, isValidBase64EncodedSSECustomerKey, } from "./middleware-ssec/middleware-ssec";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { checkContentLengthHeader, checkContentLengthHeaderMiddlewareOptions, getCheckContentLengthHeaderPlugin, } from "./middleware-check-content-length-header/check-content-length-header";
|
|
2
|
+
export { regionRedirectEndpointMiddleware, regionRedirectEndpointMiddlewareOptions, } from "./middleware-region-redirect/region-redirect-endpoint-middleware";
|
|
3
|
+
export { regionRedirectMiddleware, regionRedirectMiddlewareOptions, getRegionRedirectMiddlewarePlugin, } from "./middleware-region-redirect/region-redirect-middleware";
|
|
4
|
+
export { resolveS3Config } from "./middleware-s3-configuration/s3Configuration";
|
|
5
|
+
export { s3ExpiresMiddleware, s3ExpiresMiddlewareOptions, getS3ExpiresMiddlewarePlugin, } from "./middleware-s3-expires/s3-expires-middleware";
|
|
6
|
+
export { S3ExpressIdentityCache } from "./middleware-s3-express/classes/S3ExpressIdentityCache";
|
|
7
|
+
export { S3ExpressIdentityCacheEntry } from "./middleware-s3-express/classes/S3ExpressIdentityCacheEntry";
|
|
8
|
+
export { S3ExpressIdentityProviderImpl } from "./middleware-s3-express/classes/S3ExpressIdentityProviderImpl";
|
|
9
|
+
export { SignatureV4S3Express } from "./middleware-s3-express/classes/SignatureV4S3Express";
|
|
10
|
+
export { NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS } from "./middleware-s3-express/constants";
|
|
11
|
+
export { getS3ExpressPlugin, s3ExpressMiddleware, s3ExpressMiddlewareOptions, } from "./middleware-s3-express/functions/s3ExpressMiddleware";
|
|
12
|
+
export { getS3ExpressHttpSigningPlugin, s3ExpressHttpSigningMiddleware, s3ExpressHttpSigningMiddlewareOptions, } from "./middleware-s3-express/functions/s3ExpressHttpSigningMiddleware";
|
|
13
|
+
export { throw200ExceptionsMiddleware, throw200ExceptionsMiddlewareOptions, getThrow200ExceptionsPlugin, } from "./middleware-throw-200-exceptions/throw-200-exceptions";
|
|
14
|
+
export { validateBucketNameMiddleware, validateBucketNameMiddlewareOptions, getValidateBucketNamePlugin, } from "./middleware-validate-bucket-name/validate-bucket-name";
|
|
15
|
+
export { S3RestXmlProtocol } from "./protocol/S3RestXmlProtocol";
|
|
16
|
+
export { NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME, } from "./NodeDisableMultiregionAccessPointConfigOptions";
|
|
17
|
+
export { NODE_USE_ARN_REGION_CONFIG_OPTIONS, NODE_USE_ARN_REGION_ENV_NAME, NODE_USE_ARN_REGION_INI_NAME, } from "./NodeUseArnRegionConfigOptions";
|
|
18
|
+
export { bucketEndpointMiddleware, bucketEndpointMiddlewareOptions, getBucketEndpointPlugin, } from "./middleware-bucket-endpoint/bucketEndpointMiddleware";
|
|
19
|
+
export { bucketHostname } from "./middleware-bucket-endpoint/bucketHostname";
|
|
20
|
+
export { resolveBucketEndpointConfig } from "./middleware-bucket-endpoint/configurations";
|
|
21
|
+
export { getArnResources, getSuffixForArnEndpoint, validateOutpostService, validatePartition, validateAccountId, validateRegion, validateDNSHostLabel, validateNoDualstack, validateNoFIPS, } from "./middleware-bucket-endpoint/bucketHostnameUtils";
|
|
22
|
+
export { addExpectContinueMiddleware, addExpectContinueMiddlewareOptions, getAddExpectContinuePlugin, } from "./middleware-expect-continue/middleware-expect-continue";
|
|
23
|
+
export { locationConstraintMiddleware, locationConstraintMiddlewareOptions, getLocationConstraintPlugin, } from "./middleware-location-constraint/middleware-location-constraint";
|
|
24
|
+
export { resolveLocationConstraintConfig } from "./middleware-location-constraint/configuration";
|
|
25
|
+
export { ssecMiddleware, ssecMiddlewareOptions, getSsecPlugin, isValidBase64EncodedSSECustomerKey, } from "./middleware-ssec/middleware-ssec";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { parse as parseArn, validate as validateArn } from "@aws-sdk/core/util";
|
|
2
|
+
import { HttpRequest } from "@smithy/core/protocols";
|
|
3
|
+
import { bucketHostname } from "./bucketHostname";
|
|
4
|
+
export const bucketEndpointMiddleware = (options) => (next, context) => async (args) => {
|
|
5
|
+
const { Bucket: bucketName } = args.input;
|
|
6
|
+
let replaceBucketInPath = options.bucketEndpoint;
|
|
7
|
+
const request = args.request;
|
|
8
|
+
if (HttpRequest.isInstance(request)) {
|
|
9
|
+
if (options.bucketEndpoint) {
|
|
10
|
+
request.hostname = bucketName;
|
|
11
|
+
}
|
|
12
|
+
else if (validateArn(bucketName)) {
|
|
13
|
+
const bucketArn = parseArn(bucketName);
|
|
14
|
+
const clientRegion = await options.region();
|
|
15
|
+
const useDualstackEndpoint = await options.useDualstackEndpoint();
|
|
16
|
+
const useFipsEndpoint = await options.useFipsEndpoint();
|
|
17
|
+
const { partition, signingRegion = clientRegion } = (await options.regionInfoProvider(clientRegion, { useDualstackEndpoint, useFipsEndpoint })) || {};
|
|
18
|
+
const useArnRegion = await options.useArnRegion();
|
|
19
|
+
const { hostname, bucketEndpoint, signingRegion: modifiedSigningRegion, signingService, } = bucketHostname({
|
|
20
|
+
bucketName: bucketArn,
|
|
21
|
+
baseHostname: request.hostname,
|
|
22
|
+
accelerateEndpoint: options.useAccelerateEndpoint,
|
|
23
|
+
dualstackEndpoint: useDualstackEndpoint,
|
|
24
|
+
fipsEndpoint: useFipsEndpoint,
|
|
25
|
+
pathStyleEndpoint: options.forcePathStyle,
|
|
26
|
+
tlsCompatible: request.protocol === "https:",
|
|
27
|
+
useArnRegion,
|
|
28
|
+
clientPartition: partition,
|
|
29
|
+
clientSigningRegion: signingRegion,
|
|
30
|
+
clientRegion: clientRegion,
|
|
31
|
+
isCustomEndpoint: options.isCustomEndpoint,
|
|
32
|
+
disableMultiregionAccessPoints: await options.disableMultiregionAccessPoints(),
|
|
33
|
+
});
|
|
34
|
+
if (modifiedSigningRegion && modifiedSigningRegion !== signingRegion) {
|
|
35
|
+
context["signing_region"] = modifiedSigningRegion;
|
|
36
|
+
}
|
|
37
|
+
if (signingService && signingService !== "s3") {
|
|
38
|
+
context["signing_service"] = signingService;
|
|
39
|
+
}
|
|
40
|
+
request.hostname = hostname;
|
|
41
|
+
replaceBucketInPath = bucketEndpoint;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const clientRegion = await options.region();
|
|
45
|
+
const dualstackEndpoint = await options.useDualstackEndpoint();
|
|
46
|
+
const fipsEndpoint = await options.useFipsEndpoint();
|
|
47
|
+
const { hostname, bucketEndpoint } = bucketHostname({
|
|
48
|
+
bucketName,
|
|
49
|
+
clientRegion,
|
|
50
|
+
baseHostname: request.hostname,
|
|
51
|
+
accelerateEndpoint: options.useAccelerateEndpoint,
|
|
52
|
+
dualstackEndpoint,
|
|
53
|
+
fipsEndpoint,
|
|
54
|
+
pathStyleEndpoint: options.forcePathStyle,
|
|
55
|
+
tlsCompatible: request.protocol === "https:",
|
|
56
|
+
isCustomEndpoint: options.isCustomEndpoint,
|
|
57
|
+
});
|
|
58
|
+
request.hostname = hostname;
|
|
59
|
+
replaceBucketInPath = bucketEndpoint;
|
|
60
|
+
}
|
|
61
|
+
if (replaceBucketInPath) {
|
|
62
|
+
request.path = request.path.replace(/^(\/)?[^\/]+/, "");
|
|
63
|
+
if (request.path === "") {
|
|
64
|
+
request.path = "/";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return next({ ...args, request });
|
|
69
|
+
};
|
|
70
|
+
export const bucketEndpointMiddlewareOptions = {
|
|
71
|
+
tags: ["BUCKET_ENDPOINT"],
|
|
72
|
+
name: "bucketEndpointMiddleware",
|
|
73
|
+
relation: "before",
|
|
74
|
+
toMiddleware: "hostHeaderMiddleware",
|
|
75
|
+
override: true,
|
|
76
|
+
};
|
|
77
|
+
export const getBucketEndpointPlugin = (options) => ({
|
|
78
|
+
applyToStack: (clientStack) => {
|
|
79
|
+
clientStack.addRelativeTo(bucketEndpointMiddleware(options), bucketEndpointMiddlewareOptions);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DOT_PATTERN, getArnResources, getSuffix, getSuffixForArnEndpoint, isBucketNameOptions, isDnsCompatibleBucketName, validateAccountId, validateArnEndpointOptions, validateCustomEndpoint, validateDNSHostLabel, validateMrapAlias, validateNoFIPS, validateOutpostService, validatePartition, validateRegionalClient, validateS3Service, validateService, } from "./bucketHostnameUtils";
|
|
2
|
+
export const bucketHostname = (options) => {
|
|
3
|
+
validateCustomEndpoint(options);
|
|
4
|
+
return isBucketNameOptions(options)
|
|
5
|
+
?
|
|
6
|
+
getEndpointFromBucketName(options)
|
|
7
|
+
:
|
|
8
|
+
getEndpointFromArn(options);
|
|
9
|
+
};
|
|
10
|
+
const getEndpointFromBucketName = ({ accelerateEndpoint = false, clientRegion: region, baseHostname, bucketName, dualstackEndpoint = false, fipsEndpoint = false, pathStyleEndpoint = false, tlsCompatible = true, isCustomEndpoint = false, }) => {
|
|
11
|
+
const [clientRegion, hostnameSuffix] = isCustomEndpoint ? [region, baseHostname] : getSuffix(baseHostname);
|
|
12
|
+
if (pathStyleEndpoint || !isDnsCompatibleBucketName(bucketName) || (tlsCompatible && DOT_PATTERN.test(bucketName))) {
|
|
13
|
+
return {
|
|
14
|
+
bucketEndpoint: false,
|
|
15
|
+
hostname: dualstackEndpoint ? `s3.dualstack.${clientRegion}.${hostnameSuffix}` : baseHostname,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (accelerateEndpoint) {
|
|
19
|
+
baseHostname = `s3-accelerate${dualstackEndpoint ? ".dualstack" : ""}.${hostnameSuffix}`;
|
|
20
|
+
}
|
|
21
|
+
else if (dualstackEndpoint) {
|
|
22
|
+
baseHostname = `s3.dualstack.${clientRegion}.${hostnameSuffix}`;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
bucketEndpoint: true,
|
|
26
|
+
hostname: `${bucketName}.${baseHostname}`,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const getEndpointFromArn = (options) => {
|
|
30
|
+
const { isCustomEndpoint, baseHostname, clientRegion } = options;
|
|
31
|
+
const hostnameSuffix = isCustomEndpoint ? baseHostname : getSuffixForArnEndpoint(baseHostname)[1];
|
|
32
|
+
const { pathStyleEndpoint, accelerateEndpoint = false, fipsEndpoint = false, tlsCompatible = true, bucketName, clientPartition = "aws", } = options;
|
|
33
|
+
validateArnEndpointOptions({ pathStyleEndpoint, accelerateEndpoint, tlsCompatible });
|
|
34
|
+
const { service, partition, accountId, region, resource } = bucketName;
|
|
35
|
+
validateService(service);
|
|
36
|
+
validatePartition(partition, { clientPartition });
|
|
37
|
+
validateAccountId(accountId);
|
|
38
|
+
const { accesspointName, outpostId } = getArnResources(resource);
|
|
39
|
+
if (service === "s3-object-lambda") {
|
|
40
|
+
return getEndpointFromObjectLambdaArn({ ...options, tlsCompatible, bucketName, accesspointName, hostnameSuffix });
|
|
41
|
+
}
|
|
42
|
+
if (region === "") {
|
|
43
|
+
return getEndpointFromMRAPArn({ ...options, clientRegion, mrapAlias: accesspointName, hostnameSuffix });
|
|
44
|
+
}
|
|
45
|
+
if (outpostId) {
|
|
46
|
+
return getEndpointFromOutpostArn({ ...options, clientRegion, outpostId, accesspointName, hostnameSuffix });
|
|
47
|
+
}
|
|
48
|
+
return getEndpointFromAccessPointArn({ ...options, clientRegion, accesspointName, hostnameSuffix });
|
|
49
|
+
};
|
|
50
|
+
const getEndpointFromObjectLambdaArn = ({ dualstackEndpoint = false, fipsEndpoint = false, tlsCompatible = true, useArnRegion, clientRegion, clientSigningRegion = clientRegion, accesspointName, bucketName, hostnameSuffix, }) => {
|
|
51
|
+
const { accountId, region, service } = bucketName;
|
|
52
|
+
validateRegionalClient(clientRegion);
|
|
53
|
+
const DNSHostLabel = `${accesspointName}-${accountId}`;
|
|
54
|
+
validateDNSHostLabel(DNSHostLabel, { tlsCompatible });
|
|
55
|
+
const endpointRegion = useArnRegion ? region : clientRegion;
|
|
56
|
+
const signingRegion = useArnRegion ? region : clientSigningRegion;
|
|
57
|
+
return {
|
|
58
|
+
bucketEndpoint: true,
|
|
59
|
+
hostname: `${DNSHostLabel}.${service}${fipsEndpoint ? "-fips" : ""}.${endpointRegion}.${hostnameSuffix}`,
|
|
60
|
+
signingRegion,
|
|
61
|
+
signingService: service,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const getEndpointFromMRAPArn = ({ disableMultiregionAccessPoints, dualstackEndpoint = false, isCustomEndpoint, mrapAlias, hostnameSuffix, }) => {
|
|
65
|
+
if (disableMultiregionAccessPoints === true) {
|
|
66
|
+
throw new Error("SDK is attempting to use a MRAP ARN. Please enable to feature.");
|
|
67
|
+
}
|
|
68
|
+
validateMrapAlias(mrapAlias);
|
|
69
|
+
return {
|
|
70
|
+
bucketEndpoint: true,
|
|
71
|
+
hostname: `${mrapAlias}${isCustomEndpoint ? "" : `.accesspoint.s3-global`}.${hostnameSuffix}`,
|
|
72
|
+
signingRegion: "*",
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const getEndpointFromOutpostArn = ({ useArnRegion, clientRegion, clientSigningRegion = clientRegion, bucketName, outpostId, dualstackEndpoint = false, fipsEndpoint = false, tlsCompatible = true, accesspointName, isCustomEndpoint, hostnameSuffix, }) => {
|
|
76
|
+
validateRegionalClient(clientRegion);
|
|
77
|
+
const DNSHostLabel = `${accesspointName}-${bucketName.accountId}`;
|
|
78
|
+
validateDNSHostLabel(DNSHostLabel, { tlsCompatible });
|
|
79
|
+
const endpointRegion = useArnRegion ? bucketName.region : clientRegion;
|
|
80
|
+
const signingRegion = useArnRegion ? bucketName.region : clientSigningRegion;
|
|
81
|
+
validateOutpostService(bucketName.service);
|
|
82
|
+
validateDNSHostLabel(outpostId, { tlsCompatible });
|
|
83
|
+
validateNoFIPS(fipsEndpoint);
|
|
84
|
+
const hostnamePrefix = `${DNSHostLabel}.${outpostId}`;
|
|
85
|
+
return {
|
|
86
|
+
bucketEndpoint: true,
|
|
87
|
+
hostname: `${hostnamePrefix}${isCustomEndpoint ? "" : `.s3-outposts.${endpointRegion}`}.${hostnameSuffix}`,
|
|
88
|
+
signingRegion,
|
|
89
|
+
signingService: "s3-outposts",
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const getEndpointFromAccessPointArn = ({ useArnRegion, clientRegion, clientSigningRegion = clientRegion, bucketName, dualstackEndpoint = false, fipsEndpoint = false, tlsCompatible = true, accesspointName, isCustomEndpoint, hostnameSuffix, }) => {
|
|
93
|
+
validateRegionalClient(clientRegion);
|
|
94
|
+
const hostnamePrefix = `${accesspointName}-${bucketName.accountId}`;
|
|
95
|
+
validateDNSHostLabel(hostnamePrefix, { tlsCompatible });
|
|
96
|
+
const endpointRegion = useArnRegion ? bucketName.region : clientRegion;
|
|
97
|
+
const signingRegion = useArnRegion ? bucketName.region : clientSigningRegion;
|
|
98
|
+
validateS3Service(bucketName.service);
|
|
99
|
+
return {
|
|
100
|
+
bucketEndpoint: true,
|
|
101
|
+
hostname: `${hostnamePrefix}${isCustomEndpoint
|
|
102
|
+
? ""
|
|
103
|
+
: `.s3-accesspoint${fipsEndpoint ? "-fips" : ""}${dualstackEndpoint ? ".dualstack" : ""}.${endpointRegion}`}.${hostnameSuffix}`,
|
|
104
|
+
signingRegion,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const DOMAIN_PATTERN = /^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/;
|
|
2
|
+
const IP_ADDRESS_PATTERN = /(\d+\.){3}\d+/;
|
|
3
|
+
const DOTS_PATTERN = /\.\./;
|
|
4
|
+
export const DOT_PATTERN = /\./;
|
|
5
|
+
export const S3_HOSTNAME_PATTERN = /^(.+\.)?s3(-fips)?(\.dualstack)?[.-]([a-z0-9-]+)\./;
|
|
6
|
+
const S3_US_EAST_1_ALTNAME_PATTERN = /^s3(-external-1)?\.amazonaws\.com$/;
|
|
7
|
+
const AWS_PARTITION_SUFFIX = "amazonaws.com";
|
|
8
|
+
export const isBucketNameOptions = (options) => typeof options.bucketName === "string";
|
|
9
|
+
export const isDnsCompatibleBucketName = (bucketName) => DOMAIN_PATTERN.test(bucketName) && !IP_ADDRESS_PATTERN.test(bucketName) && !DOTS_PATTERN.test(bucketName);
|
|
10
|
+
const getRegionalSuffix = (hostname) => {
|
|
11
|
+
const parts = hostname.match(S3_HOSTNAME_PATTERN);
|
|
12
|
+
return [parts[4], hostname.replace(new RegExp(`^${parts[0]}`), "")];
|
|
13
|
+
};
|
|
14
|
+
export const getSuffix = (hostname) => S3_US_EAST_1_ALTNAME_PATTERN.test(hostname) ? ["us-east-1", AWS_PARTITION_SUFFIX] : getRegionalSuffix(hostname);
|
|
15
|
+
export const getSuffixForArnEndpoint = (hostname) => S3_US_EAST_1_ALTNAME_PATTERN.test(hostname)
|
|
16
|
+
? [hostname.replace(`.${AWS_PARTITION_SUFFIX}`, ""), AWS_PARTITION_SUFFIX]
|
|
17
|
+
: getRegionalSuffix(hostname);
|
|
18
|
+
export const validateArnEndpointOptions = (options) => {
|
|
19
|
+
if (options.pathStyleEndpoint) {
|
|
20
|
+
throw new Error("Path-style S3 endpoint is not supported when bucket is an ARN");
|
|
21
|
+
}
|
|
22
|
+
if (options.accelerateEndpoint) {
|
|
23
|
+
throw new Error("Accelerate endpoint is not supported when bucket is an ARN");
|
|
24
|
+
}
|
|
25
|
+
if (!options.tlsCompatible) {
|
|
26
|
+
throw new Error("HTTPS is required when bucket is an ARN");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const validateService = (service) => {
|
|
30
|
+
if (service !== "s3" && service !== "s3-outposts" && service !== "s3-object-lambda") {
|
|
31
|
+
throw new Error("Expect 's3' or 's3-outposts' or 's3-object-lambda' in ARN service component");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export const validateS3Service = (service) => {
|
|
35
|
+
if (service !== "s3") {
|
|
36
|
+
throw new Error("Expect 's3' in Accesspoint ARN service component");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const validateOutpostService = (service) => {
|
|
40
|
+
if (service !== "s3-outposts") {
|
|
41
|
+
throw new Error("Expect 's3-posts' in Outpost ARN service component");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export const validatePartition = (partition, options) => {
|
|
45
|
+
if (partition !== options.clientPartition) {
|
|
46
|
+
throw new Error(`Partition in ARN is incompatible, got "${partition}" but expected "${options.clientPartition}"`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const validateRegion = (region, options) => { };
|
|
50
|
+
export const validateRegionalClient = (region) => {
|
|
51
|
+
if (["s3-external-1", "aws-global"].includes(region)) {
|
|
52
|
+
throw new Error(`Client region ${region} is not regional`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export const validateAccountId = (accountId) => {
|
|
56
|
+
if (!/[0-9]{12}/.exec(accountId)) {
|
|
57
|
+
throw new Error("Access point ARN accountID does not match regex '[0-9]{12}'");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export const validateDNSHostLabel = (label, options = { tlsCompatible: true }) => {
|
|
61
|
+
if (label.length >= 64 ||
|
|
62
|
+
!/^[a-z0-9][a-z0-9.-]*[a-z0-9]$/.test(label) ||
|
|
63
|
+
/(\d+\.){3}\d+/.test(label) ||
|
|
64
|
+
/[.-]{2}/.test(label) ||
|
|
65
|
+
(options?.tlsCompatible && DOT_PATTERN.test(label))) {
|
|
66
|
+
throw new Error(`Invalid DNS label ${label}`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export const validateCustomEndpoint = (options) => {
|
|
70
|
+
if (options.isCustomEndpoint) {
|
|
71
|
+
if (options.dualstackEndpoint)
|
|
72
|
+
throw new Error("Dualstack endpoint is not supported with custom endpoint");
|
|
73
|
+
if (options.accelerateEndpoint)
|
|
74
|
+
throw new Error("Accelerate endpoint is not supported with custom endpoint");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export const getArnResources = (resource) => {
|
|
78
|
+
const delimiter = resource.includes(":") ? ":" : "/";
|
|
79
|
+
const [resourceType, ...rest] = resource.split(delimiter);
|
|
80
|
+
if (resourceType === "accesspoint") {
|
|
81
|
+
if (rest.length !== 1 || rest[0] === "") {
|
|
82
|
+
throw new Error(`Access Point ARN should have one resource accesspoint${delimiter}{accesspointname}`);
|
|
83
|
+
}
|
|
84
|
+
return { accesspointName: rest[0] };
|
|
85
|
+
}
|
|
86
|
+
else if (resourceType === "outpost") {
|
|
87
|
+
if (!rest[0] || rest[1] !== "accesspoint" || !rest[2] || rest.length !== 3) {
|
|
88
|
+
throw new Error(`Outpost ARN should have resource outpost${delimiter}{outpostId}${delimiter}accesspoint${delimiter}{accesspointName}`);
|
|
89
|
+
}
|
|
90
|
+
const [outpostId, _, accesspointName] = rest;
|
|
91
|
+
return { outpostId, accesspointName };
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error(`ARN resource should begin with 'accesspoint${delimiter}' or 'outpost${delimiter}'`);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
export const validateNoDualstack = (dualstackEndpoint) => { };
|
|
98
|
+
export const validateNoFIPS = (useFipsEndpoint) => {
|
|
99
|
+
if (useFipsEndpoint)
|
|
100
|
+
throw new Error(`FIPS region is not supported with Outpost.`);
|
|
101
|
+
};
|
|
102
|
+
export const validateMrapAlias = (name) => {
|
|
103
|
+
try {
|
|
104
|
+
name.split(".").forEach((label) => {
|
|
105
|
+
validateDNSHostLabel(label);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw new Error(`"${name}" is not a DNS compatible name.`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function resolveBucketEndpointConfig(input) {
|
|
2
|
+
const { bucketEndpoint = false, forcePathStyle = false, useAccelerateEndpoint = false, useArnRegion, disableMultiregionAccessPoints = false, } = input;
|
|
3
|
+
return Object.assign(input, {
|
|
4
|
+
bucketEndpoint,
|
|
5
|
+
forcePathStyle,
|
|
6
|
+
useAccelerateEndpoint,
|
|
7
|
+
useArnRegion: typeof useArnRegion === "function" ? useArnRegion : () => Promise.resolve(useArnRegion),
|
|
8
|
+
disableMultiregionAccessPoints: typeof disableMultiregionAccessPoints === "function"
|
|
9
|
+
? disableMultiregionAccessPoints
|
|
10
|
+
: () => Promise.resolve(disableMultiregionAccessPoints),
|
|
11
|
+
});
|
|
12
|
+
}
|