Initial
This commit is contained in:
18
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigData.js
generated
vendored
Normal file
18
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigData.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IniSectionType } from "@smithy/types";
|
||||
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
|
||||
export const getConfigData = (data) => Object.entries(data)
|
||||
.filter(([key]) => {
|
||||
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
|
||||
if (indexOfSeparator === -1) {
|
||||
return false;
|
||||
}
|
||||
return Object.values(IniSectionType).includes(key.substring(0, indexOfSeparator));
|
||||
})
|
||||
.reduce((acc, [key, value]) => {
|
||||
const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR);
|
||||
const updatedKey = key.substring(0, indexOfSeparator) === IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key;
|
||||
acc[updatedKey] = value;
|
||||
return acc;
|
||||
}, {
|
||||
...(data.default && { default: data.default }),
|
||||
});
|
||||
4
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
generated
vendored
Normal file
4
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getConfigFilepath.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { join } from "path";
|
||||
import { getHomeDir } from "./getHomeDir";
|
||||
export const ENV_CONFIG_PATH = "AWS_CONFIG_FILE";
|
||||
export const getConfigFilepath = () => process.env[ENV_CONFIG_PATH] || join(getHomeDir(), ".aws", "config");
|
||||
4
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getCredentialsFilepath.js
generated
vendored
Normal file
4
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getCredentialsFilepath.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { join } from "path";
|
||||
import { getHomeDir } from "./getHomeDir";
|
||||
export const ENV_CREDENTIALS_PATH = "AWS_SHARED_CREDENTIALS_FILE";
|
||||
export const getCredentialsFilepath = () => process.env[ENV_CREDENTIALS_PATH] || join(getHomeDir(), ".aws", "credentials");
|
||||
22
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js
generated
vendored
Normal file
22
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getHomeDir.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { homedir } from "os";
|
||||
import { sep } from "path";
|
||||
const homeDirCache = {};
|
||||
const getHomeDirCacheKey = () => {
|
||||
if (process && process.geteuid) {
|
||||
return `${process.geteuid()}`;
|
||||
}
|
||||
return "DEFAULT";
|
||||
};
|
||||
export const getHomeDir = () => {
|
||||
const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${sep}` } = process.env;
|
||||
if (HOME)
|
||||
return HOME;
|
||||
if (USERPROFILE)
|
||||
return USERPROFILE;
|
||||
if (HOMEPATH)
|
||||
return `${HOMEDRIVE}${HOMEPATH}`;
|
||||
const homeDirCacheKey = getHomeDirCacheKey();
|
||||
if (!homeDirCache[homeDirCacheKey])
|
||||
homeDirCache[homeDirCacheKey] = homedir();
|
||||
return homeDirCache[homeDirCacheKey];
|
||||
};
|
||||
3
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getProfileName.js
generated
vendored
Normal file
3
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getProfileName.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export const ENV_PROFILE = "AWS_PROFILE";
|
||||
export const DEFAULT_PROFILE = "default";
|
||||
export const getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
|
||||
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFilepath.js
generated
vendored
Normal file
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFilepath.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createHash } from "crypto";
|
||||
import { join } from "path";
|
||||
import { getHomeDir } from "./getHomeDir";
|
||||
export const getSSOTokenFilepath = (id) => {
|
||||
const hasher = createHash("sha1");
|
||||
const cacheName = hasher.update(id).digest("hex");
|
||||
return join(getHomeDir(), ".aws", "sso", "cache", `${cacheName}.json`);
|
||||
};
|
||||
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFromFile.js
generated
vendored
Normal file
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSSOTokenFromFile.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { promises as fsPromises } from "fs";
|
||||
import { getSSOTokenFilepath } from "./getSSOTokenFilepath";
|
||||
const { readFile } = fsPromises;
|
||||
export const getSSOTokenFromFile = async (id) => {
|
||||
const ssoTokenFilepath = getSSOTokenFilepath(id);
|
||||
const ssoTokenText = await readFile(ssoTokenFilepath, "utf8");
|
||||
return JSON.parse(ssoTokenText);
|
||||
};
|
||||
5
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSsoSessionData.js
generated
vendored
Normal file
5
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/getSsoSessionData.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { IniSectionType } from "@smithy/types";
|
||||
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
|
||||
export const getSsoSessionData = (data) => Object.entries(data)
|
||||
.filter(([key]) => key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR))
|
||||
.reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});
|
||||
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/index.js
generated
vendored
Normal file
8
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/index.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export * from "./getHomeDir";
|
||||
export * from "./getProfileName";
|
||||
export * from "./getSSOTokenFilepath";
|
||||
export * from "./getSSOTokenFromFile";
|
||||
export * from "./loadSharedConfigFiles";
|
||||
export * from "./loadSsoSessionData";
|
||||
export * from "./parseKnownFiles";
|
||||
export * from "./types";
|
||||
27
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
generated
vendored
Normal file
27
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSharedConfigFiles.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { getConfigData } from "./getConfigData";
|
||||
import { getConfigFilepath } from "./getConfigFilepath";
|
||||
import { getCredentialsFilepath } from "./getCredentialsFilepath";
|
||||
import { parseIni } from "./parseIni";
|
||||
import { slurpFile } from "./slurpFile";
|
||||
const swallowError = () => ({});
|
||||
export const CONFIG_PREFIX_SEPARATOR = ".";
|
||||
export const loadSharedConfigFiles = async (init = {}) => {
|
||||
const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;
|
||||
const parsedFiles = await Promise.all([
|
||||
slurpFile(configFilepath, {
|
||||
ignoreCache: init.ignoreCache,
|
||||
})
|
||||
.then(parseIni)
|
||||
.then(getConfigData)
|
||||
.catch(swallowError),
|
||||
slurpFile(filepath, {
|
||||
ignoreCache: init.ignoreCache,
|
||||
})
|
||||
.then(parseIni)
|
||||
.catch(swallowError),
|
||||
]);
|
||||
return {
|
||||
configFile: parsedFiles[0],
|
||||
credentialsFile: parsedFiles[1],
|
||||
};
|
||||
};
|
||||
9
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSsoSessionData.js
generated
vendored
Normal file
9
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/loadSsoSessionData.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { getConfigFilepath } from "./getConfigFilepath";
|
||||
import { getSsoSessionData } from "./getSsoSessionData";
|
||||
import { parseIni } from "./parseIni";
|
||||
import { slurpFile } from "./slurpFile";
|
||||
const swallowError = () => ({});
|
||||
export const loadSsoSessionData = async (init = {}) => slurpFile(init.configFilepath ?? getConfigFilepath())
|
||||
.then(parseIni)
|
||||
.then(getSsoSessionData)
|
||||
.catch(swallowError);
|
||||
14
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/mergeConfigFiles.js
generated
vendored
Normal file
14
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/mergeConfigFiles.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export const mergeConfigFiles = (...files) => {
|
||||
const merged = {};
|
||||
for (const file of files) {
|
||||
for (const [key, values] of Object.entries(file)) {
|
||||
if (merged[key] !== undefined) {
|
||||
Object.assign(merged[key], values);
|
||||
}
|
||||
else {
|
||||
merged[key] = values;
|
||||
}
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
};
|
||||
52
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/parseIni.js
generated
vendored
Normal file
52
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/parseIni.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { IniSectionType } from "@smithy/types";
|
||||
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
|
||||
const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-@\+\.%:/]+)\2$/;
|
||||
const profileNameBlockList = ["__proto__", "profile __proto__"];
|
||||
export const parseIni = (iniData) => {
|
||||
const map = {};
|
||||
let currentSection;
|
||||
let currentSubSection;
|
||||
for (const iniLine of iniData.split(/\r?\n/)) {
|
||||
const trimmedLine = iniLine.split(/(^|\s)[;#]/)[0].trim();
|
||||
const isSection = trimmedLine[0] === "[" && trimmedLine[trimmedLine.length - 1] === "]";
|
||||
if (isSection) {
|
||||
currentSection = undefined;
|
||||
currentSubSection = undefined;
|
||||
const sectionName = trimmedLine.substring(1, trimmedLine.length - 1);
|
||||
const matches = prefixKeyRegex.exec(sectionName);
|
||||
if (matches) {
|
||||
const [, prefix, , name] = matches;
|
||||
if (Object.values(IniSectionType).includes(prefix)) {
|
||||
currentSection = [prefix, name].join(CONFIG_PREFIX_SEPARATOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentSection = sectionName;
|
||||
}
|
||||
if (profileNameBlockList.includes(sectionName)) {
|
||||
throw new Error(`Found invalid profile name "${sectionName}"`);
|
||||
}
|
||||
}
|
||||
else if (currentSection) {
|
||||
const indexOfEqualsSign = trimmedLine.indexOf("=");
|
||||
if (![0, -1].includes(indexOfEqualsSign)) {
|
||||
const [name, value] = [
|
||||
trimmedLine.substring(0, indexOfEqualsSign).trim(),
|
||||
trimmedLine.substring(indexOfEqualsSign + 1).trim(),
|
||||
];
|
||||
if (value === "") {
|
||||
currentSubSection = name;
|
||||
}
|
||||
else {
|
||||
if (currentSubSection && iniLine.trimStart() === iniLine) {
|
||||
currentSubSection = undefined;
|
||||
}
|
||||
map[currentSection] = map[currentSection] || {};
|
||||
const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
|
||||
map[currentSection][key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
};
|
||||
6
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/parseKnownFiles.js
generated
vendored
Normal file
6
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/parseKnownFiles.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { loadSharedConfigFiles } from "./loadSharedConfigFiles";
|
||||
import { mergeConfigFiles } from "./mergeConfigFiles";
|
||||
export const parseKnownFiles = async (init) => {
|
||||
const parsedFiles = await loadSharedConfigFiles(init);
|
||||
return mergeConfigFiles(parsedFiles.configFile, parsedFiles.credentialsFile);
|
||||
};
|
||||
9
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/slurpFile.js
generated
vendored
Normal file
9
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/slurpFile.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { promises as fsPromises } from "fs";
|
||||
const { readFile } = fsPromises;
|
||||
const filePromisesHash = {};
|
||||
export const slurpFile = (path, options) => {
|
||||
if (!filePromisesHash[path] || options?.ignoreCache) {
|
||||
filePromisesHash[path] = readFile(path, "utf8");
|
||||
}
|
||||
return filePromisesHash[path];
|
||||
};
|
||||
1
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/types.js
generated
vendored
Normal file
1
resources/app/node_modules/@smithy/shared-ini-file-loader/dist-es/types.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user