@heroku-cli/command
Advanced tools
Comparing version 8.1.5 to 8.1.6
@@ -0,1 +1,10 @@ | ||
<a name="8.1.6"></a> | ||
## [8.1.6](https://github.com/heroku/heroku-cli-command/compare/v8.1.5...v8.1.6) (2018-05-08) | ||
### Bug Fixes | ||
* add timeout ([6527877](https://github.com/heroku/heroku-cli-command/commit/6527877)) | ||
* unref() login timeout ([c7ea0ab](https://github.com/heroku/heroku-cli-command/commit/c7ea0ab)) | ||
<a name="8.1.5"></a> | ||
@@ -2,0 +11,0 @@ ## [8.1.5](https://github.com/heroku/heroku-cli-command/compare/v8.1.4...v8.1.5) (2018-05-08) |
@@ -18,46 +18,57 @@ "use strict"; | ||
async login(opts = {}) { | ||
if (process.env.HEROKU_API_KEY) | ||
cli_ux_1.default.error('Cannot log in with HEROKU_API_KEY set'); | ||
await netrc_parser_1.default.load(); | ||
const previousEntry = netrc_parser_1.default.machines['api.heroku.com']; | ||
let input = opts.method; | ||
const defaultMethod = (previousEntry && previousEntry.method) || 'interactive'; | ||
if (!input) { | ||
if (opts.expiresIn) { | ||
// can't use browser with --expires-in | ||
input = 'interactive'; | ||
let loggedIn = false; | ||
try { | ||
// timeout after 10 minutes | ||
setTimeout(() => { | ||
if (!loggedIn) | ||
cli_ux_1.default.error('timed out'); | ||
}, 1000 * 60 * 10).unref(); | ||
if (process.env.HEROKU_API_KEY) | ||
cli_ux_1.default.error('Cannot log in with HEROKU_API_KEY set'); | ||
await netrc_parser_1.default.load(); | ||
const previousEntry = netrc_parser_1.default.machines['api.heroku.com']; | ||
let input = opts.method; | ||
const defaultMethod = (previousEntry && previousEntry.method) || 'interactive'; | ||
if (!input) { | ||
if (opts.expiresIn) { | ||
// can't use browser with --expires-in | ||
input = 'interactive'; | ||
} | ||
else if (this.enableBrowserLogin()) { | ||
input = await cli_ux_1.default.prompt(`heroku: Login with [${color_1.default.green('b')}]rowser, [${color_1.default.green('i')}]nteractive, or [${color_1.default.green('s')}]so (enterprise-only)`, { default: defaultMethod }); | ||
} | ||
else { | ||
input = defaultMethod || 'interactive'; | ||
} | ||
} | ||
else if (this.enableBrowserLogin()) { | ||
input = await cli_ux_1.default.prompt(`heroku: Login with [${color_1.default.green('b')}]rowser, [${color_1.default.green('i')}]nteractive, or [${color_1.default.green('s')}]so (enterprise-only)`, { default: defaultMethod }); | ||
let auth; | ||
switch (input) { | ||
case 'b': | ||
case 'browser': | ||
auth = await this.browser(); | ||
break; | ||
case 'i': | ||
case 'interactive': | ||
auth = await this.interactive(previousEntry && previousEntry.login, opts.expiresIn); | ||
break; | ||
case 's': | ||
case 'sso': | ||
auth = await this.sso(previousEntry && previousEntry.org); | ||
break; | ||
default: | ||
return this.login(opts); | ||
} | ||
else { | ||
input = defaultMethod || 'interactive'; | ||
await this.saveToken(auth); | ||
if (previousEntry) { | ||
try { | ||
await this.logout(previousEntry.password); | ||
} | ||
catch (err) { | ||
cli_ux_1.default.warn(err); | ||
} | ||
} | ||
} | ||
let auth; | ||
switch (input) { | ||
case 'b': | ||
case 'browser': | ||
auth = await this.browser(); | ||
break; | ||
case 'i': | ||
case 'interactive': | ||
auth = await this.interactive(previousEntry && previousEntry.login, opts.expiresIn); | ||
break; | ||
case 's': | ||
case 'sso': | ||
auth = await this.sso(previousEntry && previousEntry.org); | ||
break; | ||
default: | ||
return this.login(opts); | ||
finally { | ||
loggedIn = true; | ||
} | ||
await this.saveToken(auth); | ||
if (previousEntry) { | ||
try { | ||
await this.logout(previousEntry.password); | ||
} | ||
catch (err) { | ||
cli_ux_1.default.warn(err); | ||
} | ||
} | ||
} | ||
@@ -64,0 +75,0 @@ async logout(token = this.heroku.auth) { |
{ | ||
"name": "@heroku-cli/command", | ||
"description": "base class for Heroku CLI commands", | ||
"version": "8.1.5", | ||
"version": "8.1.6", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/heroku-cli-command/issues", |
48323
1143