初始化环境文件
This commit is contained in:
13
node_modules/@smithy/core/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js
generated
vendored
Normal file
13
node_modules/@smithy/core/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export class DefaultIdentityProviderConfig {
|
||||
authSchemes = new Map();
|
||||
constructor(config) {
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
if (value !== undefined) {
|
||||
this.authSchemes.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
getIdentityProvider(schemeId) {
|
||||
return this.authSchemes.get(schemeId);
|
||||
}
|
||||
}
|
||||
34
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js
generated
vendored
Normal file
34
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
import { HttpApiKeyAuthLocation } from "@smithy/types";
|
||||
export class HttpApiKeyAuthSigner {
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
if (!signingProperties) {
|
||||
throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
|
||||
}
|
||||
if (!signingProperties.name) {
|
||||
throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
|
||||
}
|
||||
if (!signingProperties.in) {
|
||||
throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
|
||||
}
|
||||
if (!identity.apiKey) {
|
||||
throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
|
||||
}
|
||||
const clonedRequest = HttpRequest.clone(httpRequest);
|
||||
if (signingProperties.in === HttpApiKeyAuthLocation.QUERY) {
|
||||
clonedRequest.query[signingProperties.name] = identity.apiKey;
|
||||
}
|
||||
else if (signingProperties.in === HttpApiKeyAuthLocation.HEADER) {
|
||||
clonedRequest.headers[signingProperties.name] = signingProperties.scheme
|
||||
? `${signingProperties.scheme} ${identity.apiKey}`
|
||||
: identity.apiKey;
|
||||
}
|
||||
else {
|
||||
throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
|
||||
"but found: `" +
|
||||
signingProperties.in +
|
||||
"`");
|
||||
}
|
||||
return clonedRequest;
|
||||
}
|
||||
}
|
||||
11
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js
generated
vendored
Normal file
11
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
export class HttpBearerAuthSigner {
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
const clonedRequest = HttpRequest.clone(httpRequest);
|
||||
if (!identity.token) {
|
||||
throw new Error("request could not be signed with `token` since the `token` is not defined");
|
||||
}
|
||||
clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
|
||||
return clonedRequest;
|
||||
}
|
||||
}
|
||||
3
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/index.js
generated
vendored
Normal file
3
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./httpApiKeyAuth";
|
||||
export * from "./httpBearerAuth";
|
||||
export * from "./noAuth";
|
||||
5
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/noAuth.js
generated
vendored
Normal file
5
node_modules/@smithy/core/dist-es/util-identity-and-auth/httpAuthSchemes/noAuth.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export class NoAuthSigner {
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
return httpRequest;
|
||||
}
|
||||
}
|
||||
3
node_modules/@smithy/core/dist-es/util-identity-and-auth/index.js
generated
vendored
Normal file
3
node_modules/@smithy/core/dist-es/util-identity-and-auth/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./DefaultIdentityProviderConfig";
|
||||
export * from "./httpAuthSchemes";
|
||||
export * from "./memoizeIdentityProvider";
|
||||
55
node_modules/@smithy/core/dist-es/util-identity-and-auth/memoizeIdentityProvider.js
generated
vendored
Normal file
55
node_modules/@smithy/core/dist-es/util-identity-and-auth/memoizeIdentityProvider.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
export const createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired(identity) {
|
||||
return doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
|
||||
};
|
||||
export const EXPIRATION_MS = 300_000;
|
||||
export const isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
|
||||
export const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
|
||||
export const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
|
||||
if (provider === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
|
||||
let resolved;
|
||||
let pending;
|
||||
let hasResult;
|
||||
let isConstant = false;
|
||||
const coalesceProvider = async (options) => {
|
||||
if (!pending) {
|
||||
pending = normalizedProvider(options);
|
||||
}
|
||||
try {
|
||||
resolved = await pending;
|
||||
hasResult = true;
|
||||
isConstant = false;
|
||||
}
|
||||
finally {
|
||||
pending = undefined;
|
||||
}
|
||||
return resolved;
|
||||
};
|
||||
if (isExpired === undefined) {
|
||||
return async (options) => {
|
||||
if (!hasResult || options?.forceRefresh) {
|
||||
resolved = await coalesceProvider(options);
|
||||
}
|
||||
return resolved;
|
||||
};
|
||||
}
|
||||
return async (options) => {
|
||||
if (!hasResult || options?.forceRefresh) {
|
||||
resolved = await coalesceProvider(options);
|
||||
}
|
||||
if (isConstant) {
|
||||
return resolved;
|
||||
}
|
||||
if (!requiresRefresh(resolved)) {
|
||||
isConstant = true;
|
||||
return resolved;
|
||||
}
|
||||
if (isExpired(resolved)) {
|
||||
await coalesceProvider(options);
|
||||
return resolved;
|
||||
}
|
||||
return resolved;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user