From 719777c70d8e0810f9c943b74284830e44e56c7f Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:19:47 -0700 Subject: [PATCH] Export CONFIG_PREFIX_SEPARATOR from loadSharedConfigFiles (#992) --- .changeset/funny-hornets-dress.md | 5 +++++ .../shared-ini-file-loader/src/loadSharedConfigFiles.ts | 2 ++ packages/shared-ini-file-loader/src/parseIni.spec.ts | 7 ++++--- packages/shared-ini-file-loader/src/parseIni.ts | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changeset/funny-hornets-dress.md diff --git a/.changeset/funny-hornets-dress.md b/.changeset/funny-hornets-dress.md new file mode 100644 index 00000000000..990996fa435 --- /dev/null +++ b/.changeset/funny-hornets-dress.md @@ -0,0 +1,5 @@ +--- +"@smithy/shared-ini-file-loader": patch +--- + +Export CONFIG_PREFIX_SEPARATOR from loadSharedConfigFiles diff --git a/packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts b/packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts index dbac941f1a8..bba7d6ce8f3 100644 --- a/packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts +++ b/packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts @@ -30,6 +30,8 @@ export interface SharedConfigInit { const swallowError = () => ({}); +export const CONFIG_PREFIX_SEPARATOR = "."; + export const loadSharedConfigFiles = async (init: SharedConfigInit = {}): Promise => { const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init; diff --git a/packages/shared-ini-file-loader/src/parseIni.spec.ts b/packages/shared-ini-file-loader/src/parseIni.spec.ts index ed5db623ea2..4be76887793 100644 --- a/packages/shared-ini-file-loader/src/parseIni.spec.ts +++ b/packages/shared-ini-file-loader/src/parseIni.spec.ts @@ -1,3 +1,4 @@ +import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; import { parseIni } from "./parseIni"; describe(parseIni.name, () => { @@ -99,7 +100,7 @@ describe(parseIni.name, () => { expect(parseIni(mockInput)).toStrictEqual({ [mockProfileName]: { key: "value", - "subSection.subKey": "subValue", + [["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue", }, }); @@ -112,11 +113,11 @@ describe(parseIni.name, () => { expect(parseIni(`${mockInput}${mockInput2}`)).toStrictEqual({ [mockProfileName]: { key: "value", - "subSection.subKey": "subValue", + [["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue", }, [mockProfileName2]: { key: "value2", - "subSection.subKey": "subValue2", + [["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue2", }, }); }); diff --git a/packages/shared-ini-file-loader/src/parseIni.ts b/packages/shared-ini-file-loader/src/parseIni.ts index f578307320e..35ecce9e2cb 100644 --- a/packages/shared-ini-file-loader/src/parseIni.ts +++ b/packages/shared-ini-file-loader/src/parseIni.ts @@ -1,5 +1,7 @@ import { ParsedIniData } from "@smithy/types"; +import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; + const profileNameBlockList = ["__proto__", "profile __proto__"]; export const parseIni = (iniData: string): ParsedIniData => { @@ -28,7 +30,7 @@ export const parseIni = (iniData: string): ParsedIniData => { currentSubSection = name; } else { map[currentSection] = map[currentSection] || {}; - const key = currentSubSection ? `${currentSubSection}.${name}` : name; + const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name; map[currentSection][key] = value; } }