Skip to content

Commit

Permalink
refactor: look for credentials file in working dir before home dir (#46)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Users that have credential files in both the working directory and the home directory will see a change in which one is used.
  • Loading branch information
dpopp07 committed Oct 3, 2019
1 parent 135f0d8 commit c5556de
Show file tree
Hide file tree
Showing 4 changed files with 2,838 additions and 1,923 deletions.
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

0 comments on commit c5556de

Please sign in to comment.