Skip to content

Commit ea88f96

Browse files
authored
chore(util-credentials): refactor the functions to own files (#3357)
1 parent 8e93b32 commit ea88f96

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const ENV_PROFILE = "AWS_PROFILE";
2+
export const DEFAULT_PROFILE = "default";
3+
4+
export const getMasterProfileName = (init: { profile?: string }): string =>
5+
init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,2 @@
1-
import {
2-
loadSharedConfigFiles,
3-
ParsedIniData,
4-
SharedConfigFiles,
5-
SharedConfigInit,
6-
} from "@aws-sdk/shared-ini-file-loader";
7-
8-
export const ENV_PROFILE = "AWS_PROFILE";
9-
export const DEFAULT_PROFILE = "default";
10-
11-
export interface SourceProfileInit extends SharedConfigInit {
12-
/**
13-
* The configuration profile to use.
14-
*/
15-
profile?: string;
16-
17-
/**
18-
* A promise that will be resolved with loaded and parsed credentials files.
19-
* Used to avoid loading shared config files multiple times.
20-
*
21-
* @internal
22-
*/
23-
loadedConfig?: Promise<SharedConfigFiles>;
24-
}
25-
26-
/**
27-
* Load profiles from credentials and config INI files and normalize them into a
28-
* single profile list.
29-
*
30-
* @internal
31-
*/
32-
export const parseKnownFiles = async (init: SourceProfileInit): Promise<ParsedIniData> => {
33-
const { loadedConfig = loadSharedConfigFiles(init) } = init;
34-
35-
const parsedFiles = await loadedConfig;
36-
return {
37-
...parsedFiles.configFile,
38-
...parsedFiles.credentialsFile,
39-
};
40-
};
41-
42-
/**
43-
* @internal
44-
*/
45-
export const getMasterProfileName = (init: { profile?: string }): string =>
46-
init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
1+
export * from "./get-master-profile-name";
2+
export * from "./parse-known-profiles";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
loadSharedConfigFiles,
3+
ParsedIniData,
4+
SharedConfigFiles,
5+
SharedConfigInit,
6+
} from "@aws-sdk/shared-ini-file-loader";
7+
8+
export interface SourceProfileInit extends SharedConfigInit {
9+
/**
10+
* The configuration profile to use.
11+
*/
12+
profile?: string;
13+
14+
/**
15+
* A promise that will be resolved with loaded and parsed credentials files.
16+
* Used to avoid loading shared config files multiple times.
17+
*
18+
* @internal
19+
*/
20+
loadedConfig?: Promise<SharedConfigFiles>;
21+
}
22+
23+
/**
24+
* Load profiles from credentials and config INI files and normalize them into a
25+
* single profile list.
26+
*
27+
* @internal
28+
*/
29+
export const parseKnownFiles = async (init: SourceProfileInit): Promise<ParsedIniData> => {
30+
const { loadedConfig = loadSharedConfigFiles(init) } = init;
31+
32+
const parsedFiles = await loadedConfig;
33+
return {
34+
...parsedFiles.configFile,
35+
...parsedFiles.credentialsFile,
36+
};
37+
};

0 commit comments

Comments
 (0)