Skip to content
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

refactor: look for credentials file in working dir before home dir #46

Merged
merged 1 commit into from
Sep 18, 2019
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
9 changes: 6 additions & 3 deletions auth/utils/read-credentials-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export function readCredentialsFile() {
// first look for an env variable called IBM_CREDENTIALS_FILE
// it should be the path to the file

// then look at the current working directory
// then at the os-dependent home directory

const givenFilepath: string = process.env['IBM_CREDENTIALS_FILE'] || '';
const homeDir: string = constructFilepath(os.homedir());
const workingDir: string = constructFilepath(process.cwd());
const homeDir: string = constructFilepath(os.homedir());

let filepathToUse: string;

Expand All @@ -27,10 +30,10 @@ export function readCredentialsFile() {
// see if user gave a path to the directory where file is located
filepathToUse = constructFilepath(givenFilepath);
}
} else if (fileExistsAtPath(homeDir)) {
filepathToUse = homeDir;
} else if (fileExistsAtPath(workingDir)) {
filepathToUse = workingDir;
} else if (fileExistsAtPath(homeDir)) {
filepathToUse = homeDir;
} else {
// file does not exist anywhere, will not be used
return {};
Expand Down
3 changes: 3 additions & 0 deletions migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ const service = new MyService({

#### URL parameter name changed
The variable name for the stored, URL parameter has been changed from `url` to `serviceUrl`. Note that `url` can still be compatibility passed into the constructor as an alias for `serviceUrl`. However, if you try to access the `url` property directly in your code, this is a breaking change.

#### Reading Credentials File
The order of priority has changed to give a file in the current working directory higher priority than one in the home directory. This will only impact your code if you have different files in each location.
Loading