-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(util-credentials): refactor the functions to own files (#3357)
- Loading branch information
1 parent
8e93b32
commit ea88f96
Showing
3 changed files
with
44 additions
and
46 deletions.
There are no files selected for viewing
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,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; |
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 |
---|---|---|
@@ -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<SharedConfigFiles>; | ||
} | ||
|
||
/** | ||
* Load profiles from credentials and config INI files and normalize them into a | ||
* single profile list. | ||
* | ||
* @internal | ||
*/ | ||
export const parseKnownFiles = async (init: SourceProfileInit): Promise<ParsedIniData> => { | ||
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"; |
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,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<SharedConfigFiles>; | ||
} | ||
|
||
/** | ||
* Load profiles from credentials and config INI files and normalize them into a | ||
* single profile list. | ||
* | ||
* @internal | ||
*/ | ||
export const parseKnownFiles = async (init: SourceProfileInit): Promise<ParsedIniData> => { | ||
const { loadedConfig = loadSharedConfigFiles(init) } = init; | ||
|
||
const parsedFiles = await loadedConfig; | ||
return { | ||
...parsedFiles.configFile, | ||
...parsedFiles.credentialsFile, | ||
}; | ||
}; |