UEA-Prodem
This commit is contained in:
Generated
Vendored
+18
@@ -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(".");
|
||||
};
|
||||
Generated
Vendored
+8
@@ -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);
|
||||
},
|
||||
});
|
||||
Generated
Vendored
+94
@@ -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}'`);
|
||||
}
|
||||
};
|
||||
Generated
Vendored
+31
@@ -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"],
|
||||
};
|
||||
Reference in New Issue
Block a user