@smithy/shared-ini-file-loader
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getConfigData = void 0; | ||
| const types_1 = require("@smithy/types"); | ||
| const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles"); | ||
| const getConfigData = (data) => Object.entries(data) | ||
| .filter(([key]) => { | ||
| const sections = key.split(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR); | ||
| if (sections.length === 2 && Object.values(types_1.IniSectionType).includes(sections[0])) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }) | ||
| .reduce((acc, [key, value]) => { | ||
| const updatedKey = key.startsWith(types_1.IniSectionType.PROFILE) ? key.split(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR)[1] : key; | ||
| acc[updatedKey] = value; | ||
| return acc; | ||
| }, { | ||
| ...(data.default && { default: data.default }), | ||
| }); | ||
| exports.getConfigData = getConfigData; |
| import { IniSectionType } from "@smithy/types"; | ||
| import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; | ||
| export const getConfigData = (data) => Object.entries(data) | ||
| .filter(([key]) => { | ||
| const sections = key.split(CONFIG_PREFIX_SEPARATOR); | ||
| if (sections.length === 2 && Object.values(IniSectionType).includes(sections[0])) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }) | ||
| .reduce((acc, [key, value]) => { | ||
| const updatedKey = key.startsWith(IniSectionType.PROFILE) ? key.split(CONFIG_PREFIX_SEPARATOR)[1] : key; | ||
| acc[updatedKey] = value; | ||
| return acc; | ||
| }, { | ||
| ...(data.default && { default: data.default }), | ||
| }); |
| import { ParsedIniData } from "@smithy/types"; | ||
| /** | ||
| * Returns the config data from parsed ini data. | ||
| * * Returns data for `default` | ||
| * * Returns profile name without prefix. | ||
| * * Returns non-profiles as is. | ||
| */ | ||
| export declare const getConfigData: (data: ParsedIniData) => ParsedIniData; |
| import { ParsedIniData } from "@smithy/types"; | ||
| /** | ||
| * Returns the config data from parsed ini data. | ||
| * * Returns data for `default` | ||
| * * Returns profile name without prefix. | ||
| * * Returns non-profiles as is. | ||
| */ | ||
| export declare const getConfigData: (data: ParsedIniData) => ParsedIniData; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getSsoSessionData = void 0; | ||
| const ssoSessionKeyRegex = /^sso-session\s(["'])?([^\1]+)\1$/; | ||
| const types_1 = require("@smithy/types"); | ||
| const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles"); | ||
| const getSsoSessionData = (data) => Object.entries(data) | ||
| .filter(([key]) => ssoSessionKeyRegex.test(key)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [ssoSessionKeyRegex.exec(key)[2]]: value }), {}); | ||
| .filter(([key]) => key.startsWith(types_1.IniSectionType.SSO_SESSION + loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [key.split(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR)[1]]: value }), {}); | ||
| exports.getSsoSessionData = getSsoSessionData; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.loadSharedConfigFiles = void 0; | ||
| exports.loadSharedConfigFiles = exports.CONFIG_PREFIX_SEPARATOR = void 0; | ||
| const getConfigData_1 = require("./getConfigData"); | ||
| const getConfigFilepath_1 = require("./getConfigFilepath"); | ||
| const getCredentialsFilepath_1 = require("./getCredentialsFilepath"); | ||
| const getProfileData_1 = require("./getProfileData"); | ||
| const parseIni_1 = require("./parseIni"); | ||
| const slurpFile_1 = require("./slurpFile"); | ||
| const swallowError = () => ({}); | ||
| exports.CONFIG_PREFIX_SEPARATOR = "."; | ||
| const loadSharedConfigFiles = async (init = {}) => { | ||
@@ -17,3 +18,3 @@ const { filepath = (0, getCredentialsFilepath_1.getCredentialsFilepath)(), configFilepath = (0, getConfigFilepath_1.getConfigFilepath)() } = init; | ||
| .then(parseIni_1.parseIni) | ||
| .then(getProfileData_1.getProfileData) | ||
| .then(getConfigData_1.getConfigData) | ||
| .catch(swallowError), | ||
@@ -20,0 +21,0 @@ (0, slurpFile_1.slurpFile)(filepath, { |
+18
-4
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.parseIni = void 0; | ||
| const types_1 = require("@smithy/types"); | ||
| const loadSharedConfigFiles_1 = require("./loadSharedConfigFiles"); | ||
| const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-]+)\2$/; | ||
| const profileNameBlockList = ["__proto__", "profile __proto__"]; | ||
@@ -13,7 +16,18 @@ const parseIni = (iniData) => { | ||
| if (isSection) { | ||
| currentSection = undefined; | ||
| currentSubSection = undefined; | ||
| currentSection = line.substring(1, line.length - 1); | ||
| if (profileNameBlockList.includes(currentSection)) { | ||
| throw new Error(`Found invalid profile name "${currentSection}"`); | ||
| const sectionName = line.substring(1, line.length - 1); | ||
| const matches = prefixKeyRegex.exec(sectionName); | ||
| if (matches) { | ||
| const [, prefix, , name] = matches; | ||
| if (Object.values(types_1.IniSectionType).includes(prefix)) { | ||
| currentSection = [prefix, name].join(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR); | ||
| } | ||
| } | ||
| else { | ||
| currentSection = sectionName; | ||
| } | ||
| if (profileNameBlockList.includes(sectionName)) { | ||
| throw new Error(`Found invalid profile name "${sectionName}"`); | ||
| } | ||
| } | ||
@@ -32,3 +46,3 @@ else if (currentSection) { | ||
| map[currentSection] = map[currentSection] || {}; | ||
| const key = currentSubSection ? `${currentSubSection}.${name}` : name; | ||
| const key = currentSubSection ? [currentSubSection, name].join(loadSharedConfigFiles_1.CONFIG_PREFIX_SEPARATOR) : name; | ||
| map[currentSection][key] = value; | ||
@@ -35,0 +49,0 @@ } |
@@ -1,4 +0,5 @@ | ||
| const ssoSessionKeyRegex = /^sso-session\s(["'])?([^\1]+)\1$/; | ||
| import { IniSectionType } from "@smithy/types"; | ||
| import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; | ||
| export const getSsoSessionData = (data) => Object.entries(data) | ||
| .filter(([key]) => ssoSessionKeyRegex.test(key)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [ssoSessionKeyRegex.exec(key)[2]]: value }), {}); | ||
| .filter(([key]) => key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [key.split(CONFIG_PREFIX_SEPARATOR)[1]]: value }), {}); |
@@ -0,7 +1,8 @@ | ||
| import { getConfigData } from "./getConfigData"; | ||
| import { getConfigFilepath } from "./getConfigFilepath"; | ||
| import { getCredentialsFilepath } from "./getCredentialsFilepath"; | ||
| import { getProfileData } from "./getProfileData"; | ||
| import { parseIni } from "./parseIni"; | ||
| import { slurpFile } from "./slurpFile"; | ||
| const swallowError = () => ({}); | ||
| export const CONFIG_PREFIX_SEPARATOR = "."; | ||
| export const loadSharedConfigFiles = async (init = {}) => { | ||
@@ -14,3 +15,3 @@ const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init; | ||
| .then(parseIni) | ||
| .then(getProfileData) | ||
| .then(getConfigData) | ||
| .catch(swallowError), | ||
@@ -17,0 +18,0 @@ slurpFile(filepath, { |
+18
-4
@@ -0,1 +1,4 @@ | ||
| import { IniSectionType } from "@smithy/types"; | ||
| import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; | ||
| const prefixKeyRegex = /^([\w-]+)\s(["'])?([\w-]+)\2$/; | ||
| const profileNameBlockList = ["__proto__", "profile __proto__"]; | ||
@@ -10,7 +13,18 @@ export const parseIni = (iniData) => { | ||
| if (isSection) { | ||
| currentSection = undefined; | ||
| currentSubSection = undefined; | ||
| currentSection = line.substring(1, line.length - 1); | ||
| if (profileNameBlockList.includes(currentSection)) { | ||
| throw new Error(`Found invalid profile name "${currentSection}"`); | ||
| const sectionName = line.substring(1, line.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}"`); | ||
| } | ||
| } | ||
@@ -29,3 +43,3 @@ else if (currentSection) { | ||
| map[currentSection] = map[currentSection] || {}; | ||
| const key = currentSubSection ? `${currentSubSection}.${name}` : name; | ||
| const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name; | ||
| map[currentSection][key] = value; | ||
@@ -32,0 +46,0 @@ } |
@@ -21,2 +21,3 @@ import { SharedConfigFiles } from "@smithy/types"; | ||
| } | ||
| export declare const CONFIG_PREFIX_SEPARATOR = "."; | ||
| export declare const loadSharedConfigFiles: (init?: SharedConfigInit) => Promise<SharedConfigFiles>; |
@@ -21,2 +21,3 @@ import { SharedConfigFiles } from "@smithy/types"; | ||
| } | ||
| export declare const CONFIG_PREFIX_SEPARATOR = "."; | ||
| export declare const loadSharedConfigFiles: (init?: SharedConfigInit) => Promise<SharedConfigFiles>; |
+2
-2
| { | ||
| "name": "@smithy/shared-ini-file-loader", | ||
| "version": "2.1.0", | ||
| "version": "2.2.0", | ||
| "dependencies": { | ||
| "@smithy/types": "^2.3.4", | ||
| "@smithy/types": "^2.3.5", | ||
| "tslib": "^2.5.0" | ||
@@ -7,0 +7,0 @@ }, |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getProfileData = void 0; | ||
| const profileKeyRegex = /^profile\s(["'])?([^\1]+)\1$/; | ||
| const getProfileData = (data) => Object.entries(data) | ||
| .filter(([key]) => profileKeyRegex.test(key)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [profileKeyRegex.exec(key)[2]]: value }), { | ||
| ...(data.default && { default: data.default }), | ||
| }); | ||
| exports.getProfileData = getProfileData; |
| const profileKeyRegex = /^profile\s(["'])?([^\1]+)\1$/; | ||
| export const getProfileData = (data) => Object.entries(data) | ||
| .filter(([key]) => profileKeyRegex.test(key)) | ||
| .reduce((acc, [key, value]) => ({ ...acc, [profileKeyRegex.exec(key)[2]]: value }), { | ||
| ...(data.default && { default: data.default }), | ||
| }); |
| import { ParsedIniData } from "@smithy/types"; | ||
| /** | ||
| * Returns the profile data from parsed ini data. | ||
| * * Returns data for `default` | ||
| * * Reads profileName after profile prefix including/excluding quotes | ||
| */ | ||
| export declare const getProfileData: (data: ParsedIniData) => ParsedIniData; |
| import { ParsedIniData } from "@smithy/types"; | ||
| /** | ||
| * Returns the profile data from parsed ini data. | ||
| * * Returns data for `default` | ||
| * * Reads profileName after profile prefix including/excluding quotes | ||
| */ | ||
| export declare const getProfileData: (data: ParsedIniData) => ParsedIniData; |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
46845
5.67%769
8.16%Updated