UEA-Prodem

This commit is contained in:
2026-06-10 12:38:42 -03:00
parent 3f33154e16
commit c41625e542
9352 changed files with 1128292 additions and 14752 deletions
@@ -0,0 +1,7 @@
export { NODE_USE_ARN_REGION_CONFIG_OPTIONS } from "@aws-sdk/middleware-sdk-s3/s3";
export function resolveS3ControlConfig(input) {
const { useArnRegion } = input;
return Object.assign(input, {
useArnRegion: typeof useArnRegion === "function" ? useArnRegion : () => Promise.resolve(useArnRegion),
});
}
@@ -0,0 +1,5 @@
export const CONTEXT_OUTPOST_ID = "outpost_id";
export const CONTEXT_ACCOUNT_ID = "account_id";
export const CONTEXT_ARN_REGION = "outpost_arn_region";
export const CONTEXT_SIGNING_SERVICE = "signing_service";
export const CONTEXT_SIGNING_REGION = "signing_region";
@@ -0,0 +1,7 @@
export { resolveS3ControlConfig } from "./configurations";
export { getProcessArnablesPlugin } from "./middleware-process-arnables/getProcessArnablesPlugin";
export { parseOutpostArnablesMiddleaware, parseOutpostArnablesMiddleawareOptions, } from "./middleware-process-arnables/parse-outpost-arnables";
export { updateArnablesRequestMiddleware, updateArnablesRequestMiddlewareOptions, } from "./middleware-process-arnables/update-arnables-request";
export { getOutpostEndpoint } from "./middleware-process-arnables/getOutpostEndpoint";
export { hostPrefixDeduplicationMiddleware, hostPrefixDeduplicationMiddlewareOptions, getHostPrefixDeduplicationPlugin, } from "./middleware-host-prefix-deduplication/hostPrefixDeduplicationMiddleware";
export { redirectFromPostIdMiddleware, redirectFromPostIdMiddlewareOptions, getRedirectFromPostIdPlugin, } from "./middleware-redirect-from-postid/redirect-from-postid";
@@ -0,0 +1,17 @@
export const hostPrefixDeduplicationMiddleware = () => {
return (next, context) => (args) => {
return next(args);
};
};
export const hostPrefixDeduplicationMiddlewareOptions = {
tags: ["HOST_PREFIX_DEDUPLICATION", "ENDPOINT_V2", "ENDPOINT"],
toMiddleware: "serializerMiddleware",
relation: "after",
name: "hostPrefixDeduplicationMiddleware",
override: true,
};
export const getHostPrefixDeduplicationPlugin = (config) => ({
applyToStack: (clientStack) => {
clientStack.addRelativeTo(hostPrefixDeduplicationMiddleware(), hostPrefixDeduplicationMiddlewareOptions);
},
});
@@ -0,0 +1,18 @@
const REGEX_S3CONTROL_HOSTNAME = /^(.+\.)?s3-control(-fips)?[.-]([a-z0-9-]+)\./;
export 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(".");
};
@@ -0,0 +1,8 @@
import { parseOutpostArnablesMiddleaware, parseOutpostArnablesMiddleawareOptions } from "./parse-outpost-arnables";
import { updateArnablesRequestMiddleware, updateArnablesRequestMiddlewareOptions } from "./update-arnables-request";
export const getProcessArnablesPlugin = (options) => ({
applyToStack: (clientStack) => {
clientStack.addRelativeTo(parseOutpostArnablesMiddleaware(options), parseOutpostArnablesMiddleawareOptions);
clientStack.addRelativeTo(updateArnablesRequestMiddleware(options), updateArnablesRequestMiddlewareOptions);
},
});
@@ -0,0 +1,94 @@
import { partition } from "@aws-sdk/core/client";
import { parse as parseArn, validate as validateArn } from "@aws-sdk/core/util";
import { getArnResources as getS3AccesspointArnResources, validateAccountId, validateOutpostService, validatePartition, } from "@aws-sdk/middleware-sdk-s3/s3";
import { CONTEXT_ARN_REGION, CONTEXT_OUTPOST_ID, CONTEXT_SIGNING_REGION, CONTEXT_SIGNING_SERVICE } from "../constants";
export const parseOutpostArnablesMiddleaware = (options) => (next, context) => async (args) => {
const { input } = args;
const parameter = input.Name && validateArn(input.Name) ? "Name" : input.Bucket && validateArn(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 = partition(signingRegion).name;
}
const validatorOptions = {
useFipsEndpoint,
useDualstackEndpoint,
clientRegion,
clientPartition,
signingRegion,
useArnRegion,
};
let arn;
if (parameter === "Name") {
arn = parseArn(input.Name);
validateOutpostsArn(arn, validatorOptions);
const { outpostId, accesspointName } = parseOutpostsAccessPointArnResource(arn.resource);
input.Name = accesspointName;
context[CONTEXT_OUTPOST_ID] = outpostId;
}
else {
arn = parseArn(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);
};
export 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;
validateOutpostService(service);
validatePartition(partition, { clientPartition });
validateAccountId(accountId);
};
const parseOutpostsAccessPointArnResource = (resource) => {
const { outpostId, accesspointName } = getS3AccesspointArnResources(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}'`);
}
};
@@ -0,0 +1,31 @@
import { HttpRequest } from "@smithy/core/protocols";
import { CONTEXT_ACCOUNT_ID, CONTEXT_ARN_REGION, CONTEXT_OUTPOST_ID } from "../constants";
import { getOutpostEndpoint } from "./getOutpostEndpoint";
const ACCOUNT_ID_HEADER = "x-amz-account-id";
const OUTPOST_ID_HEADER = "x-amz-outpost-id";
export const updateArnablesRequestMiddleware = (config) => (next, context) => async (args) => {
const { request } = args;
if (!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);
};
export const updateArnablesRequestMiddlewareOptions = {
toMiddleware: "serializerMiddleware",
relation: "after",
name: "updateArnablesRequestMiddleware",
tags: ["ACCOUNT_ID", "OUTPOST_ID", "OUTPOST"],
};
@@ -0,0 +1,26 @@
import { HttpRequest } from "@smithy/core/protocols";
import { CONTEXT_SIGNING_SERVICE } from "../constants";
import { getOutpostEndpoint } from "../middleware-process-arnables/getOutpostEndpoint";
export const redirectFromPostIdMiddleware = (config) => (next, context) => async (args) => {
const { input, request } = args;
if (!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);
};
export const redirectFromPostIdMiddlewareOptions = {
step: "build",
name: "redirectFromPostIdMiddleware",
tags: ["OUTPOST"],
override: true,
};
export const getRedirectFromPostIdPlugin = (options) => ({
applyToStack: (clientStack) => {
clientStack.add(redirectFromPostIdMiddleware(options), redirectFromPostIdMiddlewareOptions);
},
});