-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct merging of config files so that keys from each file are …
…kept (#4388)
- Loading branch information
Showing
4 changed files
with
63 additions
and
12 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/shared-ini-file-loader/src/mergeConfigFiles.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { mergeConfigFiles } from "./mergeConfigFiles"; | ||
|
||
describe(mergeConfigFiles.name, () => { | ||
it("merges profiles that are in multiple files", () => { | ||
const mockConfigFile = { | ||
profileName1: { configKey: "configValue1" }, | ||
}; | ||
const mockCredentialsFile = { | ||
profileName1: { credsKey: "configValue1" }, | ||
profileName2: { credsKey: "credsValue1" }, | ||
}; | ||
|
||
expect(mergeConfigFiles(mockConfigFile, mockCredentialsFile)).toMatchInlineSnapshot(` | ||
Object { | ||
"profileName1": Object { | ||
"configKey": "configValue1", | ||
"credsKey": "configValue1", | ||
}, | ||
"profileName2": Object { | ||
"credsKey": "credsValue1", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ParsedIniData } from "@aws-sdk/types"; | ||
|
||
/** | ||
* Merge multiple profile config files such that settings each file are kept together | ||
* | ||
* @internal | ||
*/ | ||
export const mergeConfigFiles = (...files: ParsedIniData[]): ParsedIniData => { | ||
const merged: ParsedIniData = {}; | ||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters