From 1173fae4bee68248cb165debd845d53ffadf20d3 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Fri, 18 Feb 2022 20:10:03 +0000 Subject: [PATCH] chore(util-credentials): refactor the functions to own files --- .../src/get-master-profile-name.ts | 5 ++ packages/util-credentials/src/index.ts | 48 +------------------ .../src/parse-known-profiles.ts | 37 ++++++++++++++ 3 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 packages/util-credentials/src/get-master-profile-name.ts create mode 100644 packages/util-credentials/src/parse-known-profiles.ts diff --git a/packages/util-credentials/src/get-master-profile-name.ts b/packages/util-credentials/src/get-master-profile-name.ts new file mode 100644 index 000000000000..7779c55165dc --- /dev/null +++ b/packages/util-credentials/src/get-master-profile-name.ts @@ -0,0 +1,5 @@ +export const ENV_PROFILE = "AWS_PROFILE"; +export const DEFAULT_PROFILE = "default"; + +export const getMasterProfileName = (init: { profile?: string }): string => + init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE; diff --git a/packages/util-credentials/src/index.ts b/packages/util-credentials/src/index.ts index a734ab1bb058..183968fb3aa7 100644 --- a/packages/util-credentials/src/index.ts +++ b/packages/util-credentials/src/index.ts @@ -1,46 +1,2 @@ -import { - loadSharedConfigFiles, - ParsedIniData, - SharedConfigFiles, - SharedConfigInit, -} from "@aws-sdk/shared-ini-file-loader"; - -export const ENV_PROFILE = "AWS_PROFILE"; -export const DEFAULT_PROFILE = "default"; - -export interface SourceProfileInit extends SharedConfigInit { - /** - * The configuration profile to use. - */ - profile?: string; - - /** - * A promise that will be resolved with loaded and parsed credentials files. - * Used to avoid loading shared config files multiple times. - * - * @internal - */ - loadedConfig?: Promise; -} - -/** - * Load profiles from credentials and config INI files and normalize them into a - * single profile list. - * - * @internal - */ -export const parseKnownFiles = async (init: SourceProfileInit): Promise => { - const { loadedConfig = loadSharedConfigFiles(init) } = init; - - const parsedFiles = await loadedConfig; - return { - ...parsedFiles.configFile, - ...parsedFiles.credentialsFile, - }; -}; - -/** - * @internal - */ -export const getMasterProfileName = (init: { profile?: string }): string => - init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE; +export * from "./get-master-profile-name"; +export * from "./parse-known-profiles"; diff --git a/packages/util-credentials/src/parse-known-profiles.ts b/packages/util-credentials/src/parse-known-profiles.ts new file mode 100644 index 000000000000..b3d9280c5e58 --- /dev/null +++ b/packages/util-credentials/src/parse-known-profiles.ts @@ -0,0 +1,37 @@ +import { + loadSharedConfigFiles, + ParsedIniData, + SharedConfigFiles, + SharedConfigInit, +} from "@aws-sdk/shared-ini-file-loader"; + +export interface SourceProfileInit extends SharedConfigInit { + /** + * The configuration profile to use. + */ + profile?: string; + + /** + * A promise that will be resolved with loaded and parsed credentials files. + * Used to avoid loading shared config files multiple times. + * + * @internal + */ + loadedConfig?: Promise; +} + +/** + * Load profiles from credentials and config INI files and normalize them into a + * single profile list. + * + * @internal + */ +export const parseKnownFiles = async (init: SourceProfileInit): Promise => { + const { loadedConfig = loadSharedConfigFiles(init) } = init; + + const parsedFiles = await loadedConfig; + return { + ...parsedFiles.configFile, + ...parsedFiles.credentialsFile, + }; +};