Skip to content

Commit

Permalink
chore(client-s3): id-auth sra and regionRedirect compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Aug 2, 2024
1 parent 1a273e1 commit 507cc89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,34 @@ export const regionRedirectEndpointMiddleware = (config: PreviouslyResolved): Se
async (args: SerializeHandlerArguments<any>): Promise<SerializeHandlerOutput<Output>> => {
const originalRegion = await config.region();
const regionProviderRef = config.region;
let unlock = () => {};
if (context.__s3RegionRedirect) {
config.region = async () => {
config.region = regionProviderRef;
return context.__s3RegionRedirect;
};
Object.defineProperty(config, "region", {
writable: false,
value: async () => {
return context.__s3RegionRedirect;
},
});
unlock = () =>
Object.defineProperty(config, "region", {
writable: true,
value: regionProviderRef,
});
}
const result = await next(args);
if (context.__s3RegionRedirect) {
const region = await config.region();
if (originalRegion !== region) {
throw new Error("Region was not restored following S3 region redirect.");
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: unknown) {
unlock();
throw e;
}
return result;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from
import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider";
import { NodeHttpHandler, streamCollector } from "@smithy/node-http-handler";
import { loadConfigsForDefaultMode } from "@smithy/smithy-client";
import { EndpointV2 } from "@smithy/types";
import { EndpointV2, HttpAuthSchemeProvider } from "@smithy/types";
import { parseUrl } from "@smithy/url-parser";
import { fromBase64, toBase64 } from "@smithy/util-base64";
import { calculateBodyLength } from "@smithy/util-body-length-node";
Expand Down Expand Up @@ -104,6 +104,8 @@ export const initializeWithMaximalConfiguration = () => {
streamHasher: streamHasher,
utf8Decoder: fromUtf8,
utf8Encoder: toUtf8,
httpAuthSchemes: [],
httpAuthSchemeProvider: (() => null) as unknown as HttpAuthSchemeProvider<any>,
// END internal options

// S3 specific options below
Expand Down

0 comments on commit 507cc89

Please sign in to comment.