Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heroku-cli-util

Package Overview
Dependencies
Maintainers
31
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-cli-util - npm Package Compare versions

Comparing version 6.1.9 to 6.1.10

92

lib/command.js

@@ -7,75 +7,10 @@ 'use strict'

function twoFactorWrapper (options, preauths, context) {
return function (res, buffer) {
let body
try {
body = this.parseBody(buffer)
} catch (e) {
this._handleFailure(res, buffer)
}
// safety check for if we have already seen this request for preauthing
// this prevents an infinite loop in case some preauth fails silently
// and we continue to get two_factor failures
// this might be better done with a timer in case a command takes too long
// and the preauthorization runs out, but that seemed unlikely
if (res.statusCode === 403 && body.id === 'two_factor' && !preauths.requests.includes(this)) {
let self = this
twoFactorPrompt(options, context)
.then(function (secondFactor) {
// default preauth to always happen unless explicitly disabled
if (options.preauth === false) {
self.options.headers = Object.assign({}, self.options.headers, {'Heroku-Two-Factor-Code': secondFactor})
self.request()
} else {
preauths.requests.push(self)
// if multiple requests are run in parallel for the same app, we should
// only preauth for the first so save the fact we already preauthed
if (!preauths.promises[body.app.name]) {
preauths.promises[body.app.name] = cli.preauth(body.app.name, heroku(context), secondFactor)
}
preauths.promises[body.app.name].then(function () {
self.request()
})
.catch(function (err) {
self.reject(err)
})
}
})
.catch(function (err) {
self.reject(err)
})
} else {
this._handleFailure(res, buffer)
}
}
function apiMiddleware (response, cb) {
let warning = response.headers['x-heroku-warning'] || response.headers['warning-message']
if (warning) cli.action.warn(warning)
cb()
}
function apiMiddleware (options, preauths, context) {
let twoFactor = twoFactorWrapper(options, preauths, context)
return function (response, cb) {
let warning = response.headers['x-heroku-warning'] || response.headers['warning-message']
if (warning) cli.action.warn(warning)
// override the _handleFailure for this request
if (!this._handleFailure) {
this._handleFailure = this.handleFailure
this.handleFailure = twoFactor.bind(this)
}
cb()
}
}
function heroku (context, options) {
function heroku (context) {
let host = context.apiUrl || 'https://api.heroku.com'
let preauths = {
promises: {},
requests: []
}
let opts = {

@@ -89,3 +24,3 @@ userAgent: context.version,

rejectUnauthorized: !(process.env.HEROKU_SSL_VERIFY === 'disable' || host.endsWith('herokudev.com')),
middleware: apiMiddleware(options, preauths, context)
middleware: apiMiddleware
}

@@ -128,6 +63,2 @@ if (process.env.HEROKU_HEADERS) {

return cli.prompt('Two-factor code', {mask: true})
.catch(function (err) {
cli.yubikey.disable()
throw err
})
.then(function (secondFactor) {

@@ -137,2 +68,9 @@ cli.yubikey.disable()

})
.then(function (secondFactor) {
if (options.preauth) {
return cli.preauth(context.app, heroku(context), secondFactor)
} else {
context.secondFactor = secondFactor
}
})
}

@@ -155,3 +93,3 @@

context.auth = {password: auth.token()}
let p = fn(context, heroku(context, options))
let p = fn(context, heroku(context))
if (!p.catch) return

@@ -165,2 +103,4 @@ return p.catch(function (err) {

reasonPrompt(context).then(run).catch(handleErr)
} else if (err && err.body && err.body.id === 'two_factor') {
twoFactorPrompt(options, context).then(run).catch(handleErr)
} else throw err

@@ -167,0 +107,0 @@ }).catch(handleErr)

2

package.json
{
"name": "heroku-cli-util",
"description": "Set of helpful CLI utilities",
"version": "6.1.9",
"version": "6.1.10",
"author": "Jeff Dickey (@dickeyxxx)",

@@ -6,0 +6,0 @@ "bugs": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc