UEA-Prodem
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.S3RestXmlProtocol = exports.getValidateBucketNamePlugin = exports.validateBucketNameMiddlewareOptions = exports.validateBucketNameMiddleware = exports.getThrow200ExceptionsPlugin = exports.throw200ExceptionsMiddlewareOptions = exports.throw200ExceptionsMiddleware = exports.s3ExpressHttpSigningMiddlewareOptions = exports.s3ExpressHttpSigningMiddleware = exports.getS3ExpressHttpSigningPlugin = exports.s3ExpressMiddlewareOptions = exports.s3ExpressMiddleware = exports.getS3ExpressPlugin = exports.NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS = exports.SignatureV4S3Express = exports.S3ExpressIdentityProviderImpl = exports.S3ExpressIdentityCacheEntry = exports.S3ExpressIdentityCache = exports.getS3ExpiresMiddlewarePlugin = exports.s3ExpiresMiddlewareOptions = exports.s3ExpiresMiddleware = exports.resolveS3Config = exports.getRegionRedirectMiddlewarePlugin = exports.regionRedirectMiddlewareOptions = exports.regionRedirectMiddleware = exports.regionRedirectEndpointMiddlewareOptions = exports.regionRedirectEndpointMiddleware = exports.getCheckContentLengthHeaderPlugin = exports.checkContentLengthHeaderMiddlewareOptions = exports.checkContentLengthHeader = void 0;
|
||||
var index_browser_1 = require("./submodules/s3/index.browser");
|
||||
Object.defineProperty(exports, "checkContentLengthHeader", { enumerable: true, get: function () { return index_browser_1.checkContentLengthHeader; } });
|
||||
Object.defineProperty(exports, "checkContentLengthHeaderMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.checkContentLengthHeaderMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getCheckContentLengthHeaderPlugin", { enumerable: true, get: function () { return index_browser_1.getCheckContentLengthHeaderPlugin; } });
|
||||
Object.defineProperty(exports, "regionRedirectEndpointMiddleware", { enumerable: true, get: function () { return index_browser_1.regionRedirectEndpointMiddleware; } });
|
||||
Object.defineProperty(exports, "regionRedirectEndpointMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.regionRedirectEndpointMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "regionRedirectMiddleware", { enumerable: true, get: function () { return index_browser_1.regionRedirectMiddleware; } });
|
||||
Object.defineProperty(exports, "regionRedirectMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.regionRedirectMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getRegionRedirectMiddlewarePlugin", { enumerable: true, get: function () { return index_browser_1.getRegionRedirectMiddlewarePlugin; } });
|
||||
Object.defineProperty(exports, "resolveS3Config", { enumerable: true, get: function () { return index_browser_1.resolveS3Config; } });
|
||||
Object.defineProperty(exports, "s3ExpiresMiddleware", { enumerable: true, get: function () { return index_browser_1.s3ExpiresMiddleware; } });
|
||||
Object.defineProperty(exports, "s3ExpiresMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.s3ExpiresMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getS3ExpiresMiddlewarePlugin", { enumerable: true, get: function () { return index_browser_1.getS3ExpiresMiddlewarePlugin; } });
|
||||
Object.defineProperty(exports, "S3ExpressIdentityCache", { enumerable: true, get: function () { return index_browser_1.S3ExpressIdentityCache; } });
|
||||
Object.defineProperty(exports, "S3ExpressIdentityCacheEntry", { enumerable: true, get: function () { return index_browser_1.S3ExpressIdentityCacheEntry; } });
|
||||
Object.defineProperty(exports, "S3ExpressIdentityProviderImpl", { enumerable: true, get: function () { return index_browser_1.S3ExpressIdentityProviderImpl; } });
|
||||
Object.defineProperty(exports, "SignatureV4S3Express", { enumerable: true, get: function () { return index_browser_1.SignatureV4S3Express; } });
|
||||
Object.defineProperty(exports, "NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS", { enumerable: true, get: function () { return index_browser_1.NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS; } });
|
||||
Object.defineProperty(exports, "getS3ExpressPlugin", { enumerable: true, get: function () { return index_browser_1.getS3ExpressPlugin; } });
|
||||
Object.defineProperty(exports, "s3ExpressMiddleware", { enumerable: true, get: function () { return index_browser_1.s3ExpressMiddleware; } });
|
||||
Object.defineProperty(exports, "s3ExpressMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.s3ExpressMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getS3ExpressHttpSigningPlugin", { enumerable: true, get: function () { return index_browser_1.getS3ExpressHttpSigningPlugin; } });
|
||||
Object.defineProperty(exports, "s3ExpressHttpSigningMiddleware", { enumerable: true, get: function () { return index_browser_1.s3ExpressHttpSigningMiddleware; } });
|
||||
Object.defineProperty(exports, "s3ExpressHttpSigningMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.s3ExpressHttpSigningMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "throw200ExceptionsMiddleware", { enumerable: true, get: function () { return index_browser_1.throw200ExceptionsMiddleware; } });
|
||||
Object.defineProperty(exports, "throw200ExceptionsMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.throw200ExceptionsMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getThrow200ExceptionsPlugin", { enumerable: true, get: function () { return index_browser_1.getThrow200ExceptionsPlugin; } });
|
||||
Object.defineProperty(exports, "validateBucketNameMiddleware", { enumerable: true, get: function () { return index_browser_1.validateBucketNameMiddleware; } });
|
||||
Object.defineProperty(exports, "validateBucketNameMiddlewareOptions", { enumerable: true, get: function () { return index_browser_1.validateBucketNameMiddlewareOptions; } });
|
||||
Object.defineProperty(exports, "getValidateBucketNamePlugin", { enumerable: true, get: function () { return index_browser_1.getValidateBucketNamePlugin; } });
|
||||
Object.defineProperty(exports, "S3RestXmlProtocol", { enumerable: true, get: function () { return index_browser_1.S3RestXmlProtocol; } });
|
||||
+548
@@ -0,0 +1,548 @@
|
||||
'use strict';
|
||||
|
||||
var client = require('@smithy/core/client');
|
||||
var protocols = require('@smithy/core/protocols');
|
||||
var serde = require('@smithy/core/serde');
|
||||
var signatureV4MultiRegion = require('@aws-sdk/signature-v4-multi-region');
|
||||
var config = require('@smithy/core/config');
|
||||
var client$1 = require('@aws-sdk/core/client');
|
||||
var core = require('@smithy/core');
|
||||
var node_stream = require('node:stream');
|
||||
var util = require('@aws-sdk/core/util');
|
||||
var protocols$1 = require('@aws-sdk/core/protocols');
|
||||
var schema = require('@smithy/core/schema');
|
||||
|
||||
const CONTENT_LENGTH_HEADER = "content-length";
|
||||
const DECODED_CONTENT_LENGTH_HEADER = "x-amz-decoded-content-length";
|
||||
function checkContentLengthHeader() {
|
||||
return (next, context) => async (args) => {
|
||||
const { request } = args;
|
||||
if (protocols.HttpRequest.isInstance(request)) {
|
||||
if (!(CONTENT_LENGTH_HEADER in request.headers) && !(DECODED_CONTENT_LENGTH_HEADER in request.headers)) {
|
||||
const message = `Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage.`;
|
||||
if (typeof context?.logger?.warn === "function" && !(context.logger instanceof client.NoOpLogger)) {
|
||||
context.logger.warn(message);
|
||||
}
|
||||
else {
|
||||
console.warn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return next({ ...args });
|
||||
};
|
||||
}
|
||||
const checkContentLengthHeaderMiddlewareOptions = {
|
||||
step: "finalizeRequest",
|
||||
tags: ["CHECK_CONTENT_LENGTH_HEADER"],
|
||||
name: "getCheckContentLengthHeaderPlugin",
|
||||
override: true,
|
||||
};
|
||||
const getCheckContentLengthHeaderPlugin = (unused) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add(checkContentLengthHeader(), checkContentLengthHeaderMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
const regionRedirectEndpointMiddleware = (config) => {
|
||||
return (next, context) => async (args) => {
|
||||
const originalRegion = await config.region();
|
||||
const regionProviderRef = config.region;
|
||||
let unlock = () => { };
|
||||
if (context.__s3RegionRedirect) {
|
||||
Object.defineProperty(config, "region", {
|
||||
writable: false,
|
||||
value: async () => {
|
||||
return context.__s3RegionRedirect;
|
||||
},
|
||||
});
|
||||
unlock = () => Object.defineProperty(config, "region", {
|
||||
writable: true,
|
||||
value: regionProviderRef,
|
||||
});
|
||||
}
|
||||
try {
|
||||
const result = await next(args);
|
||||
if (context.__s3RegionRedirect) {
|
||||
unlock();
|
||||
const region = await config.region();
|
||||
if (originalRegion !== region) {
|
||||
throw new Error("Region was not restored following S3 region redirect.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
unlock();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
||||
const regionRedirectEndpointMiddlewareOptions = {
|
||||
tags: ["REGION_REDIRECT", "S3"],
|
||||
name: "regionRedirectEndpointMiddleware",
|
||||
override: true,
|
||||
relation: "before",
|
||||
toMiddleware: "endpointV2Middleware",
|
||||
};
|
||||
|
||||
function regionRedirectMiddleware(clientConfig) {
|
||||
return (next, context) => async (args) => {
|
||||
try {
|
||||
return await next(args);
|
||||
}
|
||||
catch (err) {
|
||||
if (clientConfig.followRegionRedirects) {
|
||||
const statusCode = err?.$metadata?.httpStatusCode;
|
||||
const isHeadBucket = context.commandName === "HeadBucketCommand";
|
||||
const bucketRegionHeader = err?.$response?.headers?.["x-amz-bucket-region"];
|
||||
if (bucketRegionHeader) {
|
||||
if (statusCode === 301 ||
|
||||
(statusCode === 400 && (err?.name === "IllegalLocationConstraintException" || isHeadBucket))) {
|
||||
try {
|
||||
const actualRegion = bucketRegionHeader;
|
||||
context.logger?.debug(`Redirecting from ${await clientConfig.region()} to ${actualRegion}`);
|
||||
context.__s3RegionRedirect = actualRegion;
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error("Region redirect failed: " + e);
|
||||
}
|
||||
return next(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
const regionRedirectMiddlewareOptions = {
|
||||
step: "initialize",
|
||||
tags: ["REGION_REDIRECT", "S3"],
|
||||
name: "regionRedirectMiddleware",
|
||||
override: true,
|
||||
};
|
||||
const getRegionRedirectMiddlewarePlugin = (clientConfig) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add(regionRedirectMiddleware(clientConfig), regionRedirectMiddlewareOptions);
|
||||
clientStack.addRelativeTo(regionRedirectEndpointMiddleware(clientConfig), regionRedirectEndpointMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
class S3ExpressIdentityCache {
|
||||
data;
|
||||
lastPurgeTime = Date.now();
|
||||
static EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS = 30_000;
|
||||
constructor(data = {}) {
|
||||
this.data = data;
|
||||
}
|
||||
get(key) {
|
||||
const entry = this.data[key];
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
set(key, entry) {
|
||||
this.data[key] = entry;
|
||||
return entry;
|
||||
}
|
||||
delete(key) {
|
||||
delete this.data[key];
|
||||
}
|
||||
async purgeExpired() {
|
||||
const now = Date.now();
|
||||
if (this.lastPurgeTime + S3ExpressIdentityCache.EXPIRED_CREDENTIAL_PURGE_INTERVAL_MS > now) {
|
||||
return;
|
||||
}
|
||||
for (const key in this.data) {
|
||||
const entry = this.data[key];
|
||||
if (!entry.isRefreshing) {
|
||||
const credential = await entry.identity;
|
||||
if (credential.expiration) {
|
||||
if (credential.expiration.getTime() < now) {
|
||||
delete this.data[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class S3ExpressIdentityCacheEntry {
|
||||
_identity;
|
||||
isRefreshing;
|
||||
accessed;
|
||||
constructor(_identity, isRefreshing = false, accessed = Date.now()) {
|
||||
this._identity = _identity;
|
||||
this.isRefreshing = isRefreshing;
|
||||
this.accessed = accessed;
|
||||
}
|
||||
get identity() {
|
||||
this.accessed = Date.now();
|
||||
return this._identity;
|
||||
}
|
||||
}
|
||||
|
||||
class S3ExpressIdentityProviderImpl {
|
||||
createSessionFn;
|
||||
cache;
|
||||
static REFRESH_WINDOW_MS = 60_000;
|
||||
constructor(createSessionFn, cache = new S3ExpressIdentityCache()) {
|
||||
this.createSessionFn = createSessionFn;
|
||||
this.cache = cache;
|
||||
}
|
||||
async getS3ExpressIdentity(awsIdentity, identityProperties) {
|
||||
const key = identityProperties.Bucket;
|
||||
const { cache } = this;
|
||||
const entry = cache.get(key);
|
||||
if (entry) {
|
||||
return entry.identity.then((identity) => {
|
||||
const isExpired = (identity.expiration?.getTime() ?? 0) < Date.now();
|
||||
if (isExpired) {
|
||||
return cache.set(key, new S3ExpressIdentityCacheEntry(this.getIdentity(key))).identity;
|
||||
}
|
||||
const isExpiringSoon = (identity.expiration?.getTime() ?? 0) < Date.now() + S3ExpressIdentityProviderImpl.REFRESH_WINDOW_MS;
|
||||
if (isExpiringSoon && !entry.isRefreshing) {
|
||||
entry.isRefreshing = true;
|
||||
this.getIdentity(key).then((id) => {
|
||||
cache.set(key, new S3ExpressIdentityCacheEntry(Promise.resolve(id)));
|
||||
});
|
||||
}
|
||||
return identity;
|
||||
});
|
||||
}
|
||||
return cache.set(key, new S3ExpressIdentityCacheEntry(this.getIdentity(key))).identity;
|
||||
}
|
||||
async getIdentity(key) {
|
||||
await this.cache.purgeExpired().catch((error) => {
|
||||
console.warn("Error while clearing expired entries in S3ExpressIdentityCache: \n" + error);
|
||||
});
|
||||
const session = await this.createSessionFn(key);
|
||||
if (!session.Credentials?.AccessKeyId || !session.Credentials?.SecretAccessKey) {
|
||||
throw new Error("s3#createSession response credential missing AccessKeyId or SecretAccessKey.");
|
||||
}
|
||||
const identity = {
|
||||
accessKeyId: session.Credentials.AccessKeyId,
|
||||
secretAccessKey: session.Credentials.SecretAccessKey,
|
||||
sessionToken: session.Credentials.SessionToken,
|
||||
expiration: session.Credentials.Expiration ? new Date(session.Credentials.Expiration) : undefined,
|
||||
};
|
||||
return identity;
|
||||
}
|
||||
}
|
||||
|
||||
const resolveS3Config = (input, { session, }) => {
|
||||
const [s3ClientProvider, CreateSessionCommandCtor] = session;
|
||||
const { forcePathStyle, useAccelerateEndpoint, disableMultiregionAccessPoints, followRegionRedirects, s3ExpressIdentityProvider, bucketEndpoint, expectContinueHeader, } = input;
|
||||
return Object.assign(input, {
|
||||
forcePathStyle: forcePathStyle ?? false,
|
||||
useAccelerateEndpoint: useAccelerateEndpoint ?? false,
|
||||
disableMultiregionAccessPoints: disableMultiregionAccessPoints ?? false,
|
||||
followRegionRedirects: followRegionRedirects ?? false,
|
||||
s3ExpressIdentityProvider: s3ExpressIdentityProvider ??
|
||||
new S3ExpressIdentityProviderImpl(async (key) => s3ClientProvider().send(new CreateSessionCommandCtor({
|
||||
Bucket: key,
|
||||
}))),
|
||||
bucketEndpoint: bucketEndpoint ?? false,
|
||||
expectContinueHeader: expectContinueHeader ?? 2_097_152,
|
||||
});
|
||||
};
|
||||
|
||||
const s3ExpiresMiddleware = (config) => {
|
||||
return (next, context) => async (args) => {
|
||||
const result = await next(args);
|
||||
const { response } = result;
|
||||
if (protocols.HttpResponse.isInstance(response)) {
|
||||
if (response.headers.expires) {
|
||||
response.headers.expiresstring = response.headers.expires;
|
||||
try {
|
||||
serde.parseRfc7231DateTime(response.headers.expires);
|
||||
}
|
||||
catch (e) {
|
||||
context.logger?.warn(`AWS SDK Warning for ${context.clientName}::${context.commandName} response parsing (${response.headers.expires}): ${e}`);
|
||||
delete response.headers.expires;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
const s3ExpiresMiddlewareOptions = {
|
||||
tags: ["S3"],
|
||||
name: "s3ExpiresMiddleware",
|
||||
override: true,
|
||||
relation: "after",
|
||||
toMiddleware: "deserializerMiddleware",
|
||||
};
|
||||
const getS3ExpiresMiddlewarePlugin = (clientConfig) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(s3ExpiresMiddleware(), s3ExpiresMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
class SignatureV4S3Express extends signatureV4MultiRegion.SignatureV4SignWithCredentials {
|
||||
}
|
||||
|
||||
const S3_EXPRESS_BUCKET_TYPE = "Directory";
|
||||
const S3_EXPRESS_BACKEND = "S3Express";
|
||||
const S3_EXPRESS_AUTH_SCHEME = "sigv4-s3express";
|
||||
const SESSION_TOKEN_QUERY_PARAM = "X-Amz-S3session-Token";
|
||||
const SESSION_TOKEN_HEADER = SESSION_TOKEN_QUERY_PARAM.toLowerCase();
|
||||
const NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_ENV_NAME = "AWS_S3_DISABLE_EXPRESS_SESSION_AUTH";
|
||||
const NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_INI_NAME = "s3_disable_express_session_auth";
|
||||
const NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS = {
|
||||
environmentVariableSelector: (env) => config.booleanSelector(env, NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_ENV_NAME, config.SelectorType.ENV),
|
||||
configFileSelector: (profile) => config.booleanSelector(profile, NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_INI_NAME, config.SelectorType.CONFIG),
|
||||
default: false,
|
||||
};
|
||||
|
||||
const s3ExpressMiddleware = (options) => {
|
||||
return (next, context) => async (args) => {
|
||||
if (context.endpointV2) {
|
||||
const endpoint = context.endpointV2;
|
||||
const isS3ExpressAuth = endpoint.properties?.authSchemes?.[0]?.name === S3_EXPRESS_AUTH_SCHEME;
|
||||
const isS3ExpressBucket = endpoint.properties?.backend === S3_EXPRESS_BACKEND ||
|
||||
endpoint.properties?.bucketType === S3_EXPRESS_BUCKET_TYPE;
|
||||
if (isS3ExpressBucket) {
|
||||
client$1.setFeature(context, "S3_EXPRESS_BUCKET", "J");
|
||||
context.isS3ExpressBucket = true;
|
||||
}
|
||||
if (isS3ExpressAuth) {
|
||||
const requestBucket = args.input.Bucket;
|
||||
if (requestBucket) {
|
||||
const s3ExpressIdentity = await options.s3ExpressIdentityProvider.getS3ExpressIdentity(await options.credentials(), {
|
||||
Bucket: requestBucket,
|
||||
});
|
||||
context.s3ExpressIdentity = s3ExpressIdentity;
|
||||
if (protocols.HttpRequest.isInstance(args.request) && s3ExpressIdentity.sessionToken) {
|
||||
args.request.headers[SESSION_TOKEN_HEADER] = s3ExpressIdentity.sessionToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
};
|
||||
const s3ExpressMiddlewareOptions = {
|
||||
name: "s3ExpressMiddleware",
|
||||
step: "build",
|
||||
tags: ["S3", "S3_EXPRESS"],
|
||||
override: true,
|
||||
};
|
||||
const getS3ExpressPlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add(s3ExpressMiddleware(options), s3ExpressMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
const signS3Express = async (s3ExpressIdentity, signingOptions, request, sigV4MultiRegionSigner) => {
|
||||
const signedRequest = await sigV4MultiRegionSigner.signWithCredentials(request, s3ExpressIdentity, {});
|
||||
if (signedRequest.headers["X-Amz-Security-Token"] || signedRequest.headers["x-amz-security-token"]) {
|
||||
throw new Error("X-Amz-Security-Token must not be set for s3-express requests.");
|
||||
}
|
||||
return signedRequest;
|
||||
};
|
||||
|
||||
const defaultErrorHandler = (signingProperties) => (error) => {
|
||||
throw error;
|
||||
};
|
||||
const defaultSuccessHandler = (httpResponse, signingProperties) => { };
|
||||
const s3ExpressHttpSigningMiddlewareOptions = core.httpSigningMiddlewareOptions;
|
||||
const s3ExpressHttpSigningMiddleware = (config) => (next, context) => async (args) => {
|
||||
if (!protocols.HttpRequest.isInstance(args.request)) {
|
||||
return next(args);
|
||||
}
|
||||
const smithyContext = client.getSmithyContext(context);
|
||||
const scheme = smithyContext.selectedHttpAuthScheme;
|
||||
if (!scheme) {
|
||||
throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
|
||||
}
|
||||
const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
|
||||
let request;
|
||||
if (context.s3ExpressIdentity) {
|
||||
request = await signS3Express(context.s3ExpressIdentity, signingProperties, args.request, await config.signer());
|
||||
}
|
||||
else {
|
||||
request = await signer.sign(args.request, identity, signingProperties);
|
||||
}
|
||||
const output = await next({
|
||||
...args,
|
||||
request,
|
||||
}).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
|
||||
(signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
|
||||
return output;
|
||||
};
|
||||
const getS3ExpressHttpSigningPlugin = (config) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(s3ExpressHttpSigningMiddleware(config), core.httpSigningMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
function toStream(bytes) {
|
||||
return node_stream.Readable.from(Buffer.from(bytes));
|
||||
}
|
||||
|
||||
const THROW_IF_EMPTY_BODY = {
|
||||
CopyObjectCommand: true,
|
||||
UploadPartCopyCommand: true,
|
||||
CompleteMultipartUploadCommand: true,
|
||||
};
|
||||
const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => {
|
||||
const result = await next(args);
|
||||
const { response } = result;
|
||||
if (!protocols.HttpResponse.isInstance(response)) {
|
||||
return result;
|
||||
}
|
||||
const { statusCode, body } = response;
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
return result;
|
||||
}
|
||||
const bodyBytes = await collectBody(body, config);
|
||||
response.body = toStream(bodyBytes);
|
||||
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
|
||||
const err = new Error("S3 aborted request");
|
||||
err.$metadata = {
|
||||
httpStatusCode: 503,
|
||||
};
|
||||
err.name = "InternalError";
|
||||
throw err;
|
||||
}
|
||||
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
|
||||
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
|
||||
response.statusCode = 503;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const collectBody = (streamBody = new Uint8Array(), context) => {
|
||||
if (streamBody instanceof Uint8Array) {
|
||||
return Promise.resolve(streamBody);
|
||||
}
|
||||
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
|
||||
};
|
||||
const throw200ExceptionsMiddlewareOptions = {
|
||||
relation: "after",
|
||||
toMiddleware: "deserializerMiddleware",
|
||||
tags: ["THROW_200_EXCEPTIONS", "S3"],
|
||||
name: "throw200ExceptionsMiddleware",
|
||||
override: true,
|
||||
};
|
||||
const getThrow200ExceptionsPlugin = (config) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(throw200ExceptionsMiddleware(config), throw200ExceptionsMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
function bucketEndpointMiddleware(options) {
|
||||
return (next, context) => async (args) => {
|
||||
if (options.bucketEndpoint) {
|
||||
const endpoint = context.endpointV2;
|
||||
if (endpoint) {
|
||||
const bucket = args.input.Bucket;
|
||||
if (typeof bucket === "string") {
|
||||
try {
|
||||
const bucketEndpointUrl = new URL(bucket);
|
||||
context.endpointV2 = {
|
||||
...endpoint,
|
||||
url: bucketEndpointUrl,
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
const warning = `@aws-sdk/middleware-sdk-s3: bucketEndpoint=true was set but Bucket=${bucket} could not be parsed as URL.`;
|
||||
if (context.logger?.constructor?.name === "NoOpLogger") {
|
||||
console.warn(warning);
|
||||
}
|
||||
else {
|
||||
context.logger?.warn?.(warning);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
}
|
||||
const bucketEndpointMiddlewareOptions = {
|
||||
name: "bucketEndpointMiddleware",
|
||||
override: true,
|
||||
relation: "after",
|
||||
toMiddleware: "endpointV2Middleware",
|
||||
};
|
||||
|
||||
function validateBucketNameMiddleware({ bucketEndpoint }) {
|
||||
return (next) => async (args) => {
|
||||
const { input: { Bucket }, } = args;
|
||||
if (!bucketEndpoint && typeof Bucket === "string" && !util.validate(Bucket) && Bucket.indexOf("/") >= 0) {
|
||||
const err = new Error(`Bucket name shouldn't contain '/', received '${Bucket}'`);
|
||||
err.name = "InvalidBucketName";
|
||||
throw err;
|
||||
}
|
||||
return next({ ...args });
|
||||
};
|
||||
}
|
||||
const validateBucketNameMiddlewareOptions = {
|
||||
step: "initialize",
|
||||
tags: ["VALIDATE_BUCKET_NAME"],
|
||||
name: "validateBucketNameMiddleware",
|
||||
override: true,
|
||||
};
|
||||
const getValidateBucketNamePlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add(validateBucketNameMiddleware(options), validateBucketNameMiddlewareOptions);
|
||||
clientStack.addRelativeTo(bucketEndpointMiddleware(options), bucketEndpointMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
class S3RestXmlProtocol extends protocols$1.AwsRestXmlProtocol {
|
||||
async serializeRequest(operationSchema, input, context) {
|
||||
const request = await super.serializeRequest(operationSchema, input, context);
|
||||
const ns = schema.NormalizedSchema.of(operationSchema.input);
|
||||
const staticStructureSchema = ns.getSchema();
|
||||
let bucketMemberIndex = 0;
|
||||
const requiredMemberCount = staticStructureSchema[6] ?? 0;
|
||||
if (input && typeof input === "object") {
|
||||
for (const [memberName, memberNs] of ns.structIterator()) {
|
||||
if (++bucketMemberIndex > requiredMemberCount) {
|
||||
break;
|
||||
}
|
||||
if (memberName === "Bucket") {
|
||||
if (!input.Bucket && memberNs.getMergedTraits().httpLabel) {
|
||||
throw new Error(`No value provided for input HTTP label: Bucket.`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
exports.NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS = NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS;
|
||||
exports.S3ExpressIdentityCache = S3ExpressIdentityCache;
|
||||
exports.S3ExpressIdentityCacheEntry = S3ExpressIdentityCacheEntry;
|
||||
exports.S3ExpressIdentityProviderImpl = S3ExpressIdentityProviderImpl;
|
||||
exports.S3RestXmlProtocol = S3RestXmlProtocol;
|
||||
exports.SignatureV4S3Express = SignatureV4S3Express;
|
||||
exports.checkContentLengthHeader = checkContentLengthHeader;
|
||||
exports.checkContentLengthHeaderMiddlewareOptions = checkContentLengthHeaderMiddlewareOptions;
|
||||
exports.getCheckContentLengthHeaderPlugin = getCheckContentLengthHeaderPlugin;
|
||||
exports.getRegionRedirectMiddlewarePlugin = getRegionRedirectMiddlewarePlugin;
|
||||
exports.getS3ExpiresMiddlewarePlugin = getS3ExpiresMiddlewarePlugin;
|
||||
exports.getS3ExpressHttpSigningPlugin = getS3ExpressHttpSigningPlugin;
|
||||
exports.getS3ExpressPlugin = getS3ExpressPlugin;
|
||||
exports.getThrow200ExceptionsPlugin = getThrow200ExceptionsPlugin;
|
||||
exports.getValidateBucketNamePlugin = getValidateBucketNamePlugin;
|
||||
exports.regionRedirectEndpointMiddleware = regionRedirectEndpointMiddleware;
|
||||
exports.regionRedirectEndpointMiddlewareOptions = regionRedirectEndpointMiddlewareOptions;
|
||||
exports.regionRedirectMiddleware = regionRedirectMiddleware;
|
||||
exports.regionRedirectMiddlewareOptions = regionRedirectMiddlewareOptions;
|
||||
exports.resolveS3Config = resolveS3Config;
|
||||
exports.s3ExpiresMiddleware = s3ExpiresMiddleware;
|
||||
exports.s3ExpiresMiddlewareOptions = s3ExpiresMiddlewareOptions;
|
||||
exports.s3ExpressHttpSigningMiddleware = s3ExpressHttpSigningMiddleware;
|
||||
exports.s3ExpressHttpSigningMiddlewareOptions = s3ExpressHttpSigningMiddlewareOptions;
|
||||
exports.s3ExpressMiddleware = s3ExpressMiddleware;
|
||||
exports.s3ExpressMiddlewareOptions = s3ExpressMiddlewareOptions;
|
||||
exports.throw200ExceptionsMiddleware = throw200ExceptionsMiddleware;
|
||||
exports.throw200ExceptionsMiddlewareOptions = throw200ExceptionsMiddlewareOptions;
|
||||
exports.validateBucketNameMiddleware = validateBucketNameMiddleware;
|
||||
exports.validateBucketNameMiddlewareOptions = validateBucketNameMiddlewareOptions;
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
'use strict';
|
||||
|
||||
var s3 = require('@aws-sdk/middleware-sdk-s3/s3');
|
||||
var client = require('@aws-sdk/core/client');
|
||||
var util = require('@aws-sdk/core/util');
|
||||
var protocols = require('@smithy/core/protocols');
|
||||
|
||||
function resolveS3ControlConfig(input) {
|
||||
const { useArnRegion } = input;
|
||||
return Object.assign(input, {
|
||||
useArnRegion: typeof useArnRegion === "function" ? useArnRegion : () => Promise.resolve(useArnRegion),
|
||||
});
|
||||
}
|
||||
|
||||
const CONTEXT_OUTPOST_ID = "outpost_id";
|
||||
const CONTEXT_ACCOUNT_ID = "account_id";
|
||||
const CONTEXT_ARN_REGION = "outpost_arn_region";
|
||||
const CONTEXT_SIGNING_SERVICE = "signing_service";
|
||||
const CONTEXT_SIGNING_REGION = "signing_region";
|
||||
|
||||
const parseOutpostArnablesMiddleaware = (options) => (next, context) => async (args) => {
|
||||
const { input } = args;
|
||||
const parameter = input.Name && util.validate(input.Name) ? "Name" : input.Bucket && util.validate(input.Bucket) ? "Bucket" : undefined;
|
||||
if (!parameter)
|
||||
return next(args);
|
||||
const clientRegion = await options.region();
|
||||
const useArnRegion = await options.useArnRegion();
|
||||
const useFipsEndpoint = await options.useFipsEndpoint();
|
||||
const useDualstackEndpoint = await options.useDualstackEndpoint();
|
||||
const baseRegion = clientRegion;
|
||||
let clientPartition;
|
||||
let signingRegion;
|
||||
if (options.regionInfoProvider) {
|
||||
({ partition: clientPartition, signingRegion = baseRegion } = (await options.regionInfoProvider(baseRegion, {
|
||||
useFipsEndpoint,
|
||||
useDualstackEndpoint,
|
||||
})));
|
||||
}
|
||||
else {
|
||||
signingRegion = context.endpointV2?.properties?.authSchemes?.[0]?.signingRegion || baseRegion;
|
||||
clientPartition = client.partition(signingRegion).name;
|
||||
}
|
||||
const validatorOptions = {
|
||||
clientPartition};
|
||||
let arn;
|
||||
if (parameter === "Name") {
|
||||
arn = util.parse(input.Name);
|
||||
validateOutpostsArn(arn, validatorOptions);
|
||||
const { outpostId, accesspointName } = parseOutpostsAccessPointArnResource(arn.resource);
|
||||
input.Name = accesspointName;
|
||||
context[CONTEXT_OUTPOST_ID] = outpostId;
|
||||
}
|
||||
else {
|
||||
arn = util.parse(input.Bucket);
|
||||
validateOutpostsArn(arn, validatorOptions);
|
||||
const { outpostId, bucketName } = parseOutpostBucketArnResource(arn.resource);
|
||||
input.Bucket = bucketName;
|
||||
context[CONTEXT_OUTPOST_ID] = outpostId;
|
||||
}
|
||||
context[CONTEXT_SIGNING_SERVICE] = arn.service;
|
||||
context[CONTEXT_SIGNING_REGION] = useArnRegion ? arn.region : signingRegion;
|
||||
if (!input.AccountId) {
|
||||
input.AccountId = arn.accountId;
|
||||
}
|
||||
if (useArnRegion)
|
||||
context[CONTEXT_ARN_REGION] = arn.region;
|
||||
return next(args);
|
||||
};
|
||||
const parseOutpostArnablesMiddleawareOptions = {
|
||||
toMiddleware: "serializerMiddleware",
|
||||
relation: "before",
|
||||
tags: ["CONVERT_ARN", "OUTPOST_BUCKET_ARN", "OUTPOST_ACCESS_POINT_ARN", "OUTPOST"],
|
||||
name: "parseOutpostArnablesMiddleaware",
|
||||
};
|
||||
const validateOutpostsArn = (arn, { clientPartition }) => {
|
||||
const { service, partition, accountId, region } = arn;
|
||||
s3.validateOutpostService(service);
|
||||
s3.validatePartition(partition, { clientPartition });
|
||||
s3.validateAccountId(accountId);
|
||||
};
|
||||
const parseOutpostsAccessPointArnResource = (resource) => {
|
||||
const { outpostId, accesspointName } = s3.getArnResources(resource);
|
||||
if (!outpostId) {
|
||||
throw new Error("ARN resource should begin with 'outpost'");
|
||||
}
|
||||
return {
|
||||
outpostId,
|
||||
accesspointName,
|
||||
};
|
||||
};
|
||||
const parseOutpostBucketArnResource = (resource) => {
|
||||
const delimiter = resource.includes(":") ? ":" : "/";
|
||||
const [resourceType, ...rest] = resource.split(delimiter);
|
||||
if (resourceType === "outpost") {
|
||||
if (!rest[0] || rest[1] !== "bucket" || !rest[2] || rest.length !== 3) {
|
||||
throw new Error(`Outpost Bucket ARN should have resource outpost${delimiter}{outpostId}${delimiter}bucket${delimiter}{bucketName}`);
|
||||
}
|
||||
const [outpostId, _, bucketName] = rest;
|
||||
return { outpostId, bucketName };
|
||||
}
|
||||
else {
|
||||
throw new Error(`ARN resource should begin with 'outpost${delimiter}'`);
|
||||
}
|
||||
};
|
||||
|
||||
const REGEX_S3CONTROL_HOSTNAME = /^(.+\.)?s3-control(-fips)?[.-]([a-z0-9-]+)\./;
|
||||
const getOutpostEndpoint = (hostname, { isCustomEndpoint, regionOverride, useFipsEndpoint }) => {
|
||||
if (isCustomEndpoint) {
|
||||
return hostname;
|
||||
}
|
||||
const match = hostname.match(REGEX_S3CONTROL_HOSTNAME);
|
||||
if (!match) {
|
||||
return hostname;
|
||||
}
|
||||
const [matched, prefix, fips, region] = hostname.match(REGEX_S3CONTROL_HOSTNAME);
|
||||
return [
|
||||
`s3-outposts${useFipsEndpoint ? "-fips" : ""}`,
|
||||
regionOverride || region,
|
||||
hostname.replace(new RegExp(`^${matched}`), ""),
|
||||
]
|
||||
.filter((part) => part !== undefined)
|
||||
.join(".");
|
||||
};
|
||||
|
||||
const ACCOUNT_ID_HEADER = "x-amz-account-id";
|
||||
const OUTPOST_ID_HEADER = "x-amz-outpost-id";
|
||||
const updateArnablesRequestMiddleware = (config) => (next, context) => async (args) => {
|
||||
const { request } = args;
|
||||
if (!protocols.HttpRequest.isInstance(request)) {
|
||||
return next(args);
|
||||
}
|
||||
if (context[CONTEXT_ACCOUNT_ID]) {
|
||||
request.headers[ACCOUNT_ID_HEADER] = context[CONTEXT_ACCOUNT_ID];
|
||||
}
|
||||
if (context[CONTEXT_OUTPOST_ID]) {
|
||||
const { isCustomEndpoint } = config;
|
||||
const useFipsEndpoint = await config.useFipsEndpoint();
|
||||
request.headers[OUTPOST_ID_HEADER] = context[CONTEXT_OUTPOST_ID];
|
||||
request.hostname = getOutpostEndpoint(request.hostname, {
|
||||
isCustomEndpoint,
|
||||
regionOverride: context[CONTEXT_ARN_REGION],
|
||||
useFipsEndpoint,
|
||||
});
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
const updateArnablesRequestMiddlewareOptions = {
|
||||
toMiddleware: "serializerMiddleware",
|
||||
relation: "after",
|
||||
name: "updateArnablesRequestMiddleware",
|
||||
tags: ["ACCOUNT_ID", "OUTPOST_ID", "OUTPOST"],
|
||||
};
|
||||
|
||||
const getProcessArnablesPlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(parseOutpostArnablesMiddleaware(options), parseOutpostArnablesMiddleawareOptions);
|
||||
clientStack.addRelativeTo(updateArnablesRequestMiddleware(options), updateArnablesRequestMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
const hostPrefixDeduplicationMiddleware = () => {
|
||||
return (next, context) => (args) => {
|
||||
return next(args);
|
||||
};
|
||||
};
|
||||
const hostPrefixDeduplicationMiddlewareOptions = {
|
||||
tags: ["HOST_PREFIX_DEDUPLICATION", "ENDPOINT_V2", "ENDPOINT"],
|
||||
toMiddleware: "serializerMiddleware",
|
||||
relation: "after",
|
||||
name: "hostPrefixDeduplicationMiddleware",
|
||||
override: true,
|
||||
};
|
||||
const getHostPrefixDeduplicationPlugin = (config) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(hostPrefixDeduplicationMiddleware(), hostPrefixDeduplicationMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
const redirectFromPostIdMiddleware = (config) => (next, context) => async (args) => {
|
||||
const { input, request } = args;
|
||||
if (!protocols.HttpRequest.isInstance(request))
|
||||
return next(args);
|
||||
if (input.OutpostId) {
|
||||
const { isCustomEndpoint } = config;
|
||||
const useFipsEndpoint = await config.useFipsEndpoint();
|
||||
request.hostname = getOutpostEndpoint(request.hostname, { isCustomEndpoint, useFipsEndpoint });
|
||||
context[CONTEXT_SIGNING_SERVICE] = "s3-outposts";
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
const redirectFromPostIdMiddlewareOptions = {
|
||||
step: "build",
|
||||
name: "redirectFromPostIdMiddleware",
|
||||
tags: ["OUTPOST"],
|
||||
override: true,
|
||||
};
|
||||
const getRedirectFromPostIdPlugin = (options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.add(redirectFromPostIdMiddleware(options), redirectFromPostIdMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
exports.getHostPrefixDeduplicationPlugin = getHostPrefixDeduplicationPlugin;
|
||||
exports.getOutpostEndpoint = getOutpostEndpoint;
|
||||
exports.getProcessArnablesPlugin = getProcessArnablesPlugin;
|
||||
exports.getRedirectFromPostIdPlugin = getRedirectFromPostIdPlugin;
|
||||
exports.hostPrefixDeduplicationMiddleware = hostPrefixDeduplicationMiddleware;
|
||||
exports.hostPrefixDeduplicationMiddlewareOptions = hostPrefixDeduplicationMiddlewareOptions;
|
||||
exports.parseOutpostArnablesMiddleaware = parseOutpostArnablesMiddleaware;
|
||||
exports.parseOutpostArnablesMiddleawareOptions = parseOutpostArnablesMiddleawareOptions;
|
||||
exports.redirectFromPostIdMiddleware = redirectFromPostIdMiddleware;
|
||||
exports.redirectFromPostIdMiddlewareOptions = redirectFromPostIdMiddlewareOptions;
|
||||
exports.resolveS3ControlConfig = resolveS3ControlConfig;
|
||||
exports.updateArnablesRequestMiddleware = updateArnablesRequestMiddleware;
|
||||
exports.updateArnablesRequestMiddlewareOptions = updateArnablesRequestMiddlewareOptions;
|
||||
+1028
File diff suppressed because it is too large
Load Diff
+1042
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user