This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,7 @@
import { getProfileName, parseKnownFiles } from "@smithy/shared-ini-file-loader";
import { resolveProcessCredentials } from "./resolveProcessCredentials";
export const fromProcess = (init = {}) => async () => {
init.logger?.debug("@aws-sdk/credential-provider-process", "fromProcess");
const profiles = await parseKnownFiles(init);
return resolveProcessCredentials(getProfileName(init), profiles);
};

View File

@@ -0,0 +1,22 @@
export const getValidatedProcessCredentials = (profileName, data) => {
if (data.Version !== 1) {
throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
}
if (data.AccessKeyId === undefined || data.SecretAccessKey === undefined) {
throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
}
if (data.Expiration) {
const currentTime = new Date();
const expireTime = new Date(data.Expiration);
if (expireTime < currentTime) {
throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
}
}
return {
accessKeyId: data.AccessKeyId,
secretAccessKey: data.SecretAccessKey,
...(data.SessionToken && { sessionToken: data.SessionToken }),
...(data.Expiration && { expiration: new Date(data.Expiration) }),
...(data.CredentialScope && { credentialScope: data.CredentialScope }),
};
};

View File

@@ -0,0 +1 @@
export * from "./fromProcess";

View File

@@ -0,0 +1,33 @@
import { CredentialsProviderError } from "@smithy/property-provider";
import { exec } from "child_process";
import { promisify } from "util";
import { getValidatedProcessCredentials } from "./getValidatedProcessCredentials";
export const resolveProcessCredentials = async (profileName, profiles) => {
const profile = profiles[profileName];
if (profiles[profileName]) {
const credentialProcess = profile["credential_process"];
if (credentialProcess !== undefined) {
const execPromise = promisify(exec);
try {
const { stdout } = await execPromise(credentialProcess);
let data;
try {
data = JSON.parse(stdout.trim());
}
catch {
throw Error(`Profile ${profileName} credential_process returned invalid JSON.`);
}
return getValidatedProcessCredentials(profileName, data);
}
catch (error) {
throw new CredentialsProviderError(error.message);
}
}
else {
throw new CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`);
}
}
else {
throw new CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`);
}
};