Socket
Socket
Sign inDemoInstall

@smithy/shared-ini-file-loader

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithy/shared-ini-file-loader - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

dist-cjs/getConfigData.js

7

dist-cjs/getSsoSessionData.js
"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, {

"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, {

@@ -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>;
{
"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 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc