Skip to content

chore(util-credentials): refactor the functions to own files #3357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/util-credentials/src/get-master-profile-name.ts
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;
48 changes: 2 additions & 46 deletions packages/util-credentials/src/index.ts
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";
37 changes: 37 additions & 0 deletions packages/util-credentials/src/parse-known-profiles.ts
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,
};
};