Skip to content

Commit c5556de

Browse files
committed
refactor: look for credentials file in working dir before home dir (#46)
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.
1 parent 135f0d8 commit c5556de

File tree

4 files changed

+2838
-1923
lines changed

4 files changed

+2838
-1923
lines changed

auth/utils/read-credentials-file.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ export function readCredentialsFile() {
1313
// first look for an env variable called IBM_CREDENTIALS_FILE
1414
// it should be the path to the file
1515

16+
// then look at the current working directory
17+
// then at the os-dependent home directory
18+
1619
const givenFilepath: string = process.env['IBM_CREDENTIALS_FILE'] || '';
17-
const homeDir: string = constructFilepath(os.homedir());
1820
const workingDir: string = constructFilepath(process.cwd());
21+
const homeDir: string = constructFilepath(os.homedir());
1922

2023
let filepathToUse: string;
2124

@@ -27,10 +30,10 @@ export function readCredentialsFile() {
2730
// see if user gave a path to the directory where file is located
2831
filepathToUse = constructFilepath(givenFilepath);
2932
}
30-
} else if (fileExistsAtPath(homeDir)) {
31-
filepathToUse = homeDir;
3233
} else if (fileExistsAtPath(workingDir)) {
3334
filepathToUse = workingDir;
35+
} else if (fileExistsAtPath(homeDir)) {
36+
filepathToUse = homeDir;
3437
} else {
3538
// file does not exist anywhere, will not be used
3639
return {};

migration-guide.md

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ const service = new MyService({
3434

3535
#### URL parameter name changed
3636
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.
37+
38+
#### Reading Credentials File
39+
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.

0 commit comments

Comments
 (0)