Skip to content

Commit

Permalink
fix(apikeys.js): fixing #3 - assumed unix not considering windows
Browse files Browse the repository at this point in the history
Fixed the issue where we assumed using unix ~ is not used in windows. This has now been fixed using
os.homedir

fix #3
  • Loading branch information
Simen Daehlin committed Sep 4, 2022
1 parent 394c98a commit 78388ae
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions providers/heroku/apiKey.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
const os = require(`os`);
const shell = require(`shelljs`);
const { setConfig } = require(`../../utils/config`);
const { spinner } = require(`../../utils/config`);

const getApiKey = async () => {
const apiToken = await shell
.cat(`~/.netrc `)
.grep(
`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`
)
.substring(11, 47);
setConfig({ apiToken });
try {
const apiToken = await shell
.cat(`${os.homedir()}/.netrc `)
.grep(
`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`
)
.substring(11, 47);
setConfig({ apiToken });
} catch (error) {
spinner.stopAndPersist({
symbol: `❌`,
text: `Unable to get API key from Heroku. Please make sure you are logged in to Heroku.`
});
}
};

module.exports = { getApiKey };

0 comments on commit 78388ae

Please sign in to comment.