From b473a6b9ac768215f2ba4957b517abe0847d47a0 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 | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/credential-provider-ini/src/index.ts b/packages/credential-provider-ini/src/index.ts index 3ef8e9f52c8e..3b44a106b0ca 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 095d5bb5e9ca..52c16e6db3c2 100755 --- a/packages/credential-provider-process/src/index.ts +++ b/packages/credential-provider-process/src/index.ts @@ -15,10 +15,12 @@ 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 resolveProcessCredentials = async (profileName: string, profiles: ParsedIniData): Promise => { const profile = profiles[profileName]; if (profiles[profileName]) { @@ -80,7 +82,7 @@ async function resolveProcessCredentials(profileName: string, profiles: ParsedIn // a parameter, anenvironment variable, or another profile's `source_profile` key). throw new ProviderError(`Profile ${profileName} could not be found in shared credentials file.`); } -} +}; const execPromise = (command: string) => new Promise(function (resolve, reject) {