From 956fd898d22b3968298a9adcac5387362caa7691 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Fri, 19 Feb 2021 10:09:55 -0800 Subject: [PATCH] fix(credential-provider): address feedbacks Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> --- packages/credential-provider-ini/src/index.ts | 18 +++++++++--------- .../credential-provider-process/src/index.ts | 6 ++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/credential-provider-ini/src/index.ts b/packages/credential-provider-ini/src/index.ts index 3ef8e9f52c8ec..3b44a106b0ca9 100755 --- a/packages/credential-provider-ini/src/index.ts +++ b/packages/credential-provider-ini/src/index.ts @@ -111,8 +111,10 @@ const isAssumeRoleProfile = (arg: any): arg is AssumeRoleProfile => * Creates a credential provider that will read from ini files and supports * role assumption and multi-factor authentication. */ -export const fromIni = (init: FromIniInit = {}): CredentialProvider => () => - parseKnownFiles(init).then((profiles) => resolveProfileData(getMasterProfileName(init), profiles, init)); +export const fromIni = (init: FromIniInit = {}): CredentialProvider => async () => { + const profiles = await parseKnownFiles(init); + return resolveProfileData(getMasterProfileName(init), profiles, init); +}; /** * Load profiles from credentials and config INI files and normalize them into a @@ -123,13 +125,11 @@ export const fromIni = (init: FromIniInit = {}): CredentialProvider => () => export const parseKnownFiles = async (init: SourceProfileInit): Promise => { const { loadedConfig = loadSharedConfigFiles(init) } = init; - return loadedConfig.then((parsedFiles) => { - const { configFile, credentialsFile } = parsedFiles; - return { - ...configFile, - ...credentialsFile, - }; - }); + const parsedFiles = await loadedConfig; + return { + ...parsedFiles.configFile, + ...parsedFiles.credentialsFile, + }; }; /** diff --git a/packages/credential-provider-process/src/index.ts b/packages/credential-provider-process/src/index.ts index 095d5bb5e9cac..927d33cb05133 100755 --- a/packages/credential-provider-process/src/index.ts +++ b/packages/credential-provider-process/src/index.ts @@ -15,8 +15,10 @@ export interface FromProcessInit extends SourceProfileInit {} * Creates a credential provider that will read from a credential_process specified * in ini files. */ -export const fromProcess = (init: FromProcessInit = {}): CredentialProvider => () => - parseKnownFiles(init).then((profiles) => resolveProcessCredentials(getMasterProfileName(init), profiles)); +export const fromProcess = (init: FromProcessInit = {}): CredentialProvider => async () => { + const profiles = await parseKnownFiles(init); + return resolveProcessCredentials(getMasterProfileName(init), profiles); +}; async function resolveProcessCredentials(profileName: string, profiles: ParsedIniData): Promise { const profile = profiles[profileName];