Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKat Marchán <kzm@zkat.tech>2018-08-21 05:45:49 +0300
committerKat Marchán <kzm@zkat.tech>2018-12-11 01:55:38 +0300
commitad67461dc3a73d5ae6569fdbee44c67e1daf86e7 (patch)
treefa1b0ba8fb1299c3b19bbb6900c1e222e182eb66 /lib
parent4cca9cb9042c0eeb743377e8f1ae1c07733df43f (diff)
utils: add otplease util for otp prompting
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/otplease.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/utils/otplease.js b/lib/utils/otplease.js
new file mode 100644
index 000000000..d0477a896
--- /dev/null
+++ b/lib/utils/otplease.js
@@ -0,0 +1,27 @@
+'use strict'
+
+const BB = require('bluebird')
+
+const optCheck = require('figgy-pudding')({
+ prompt: {default: 'This operation requires a one-time password.\nEnter OTP:'},
+ otp: {}
+})
+const readUserInfo = require('./read-user-info.js')
+
+module.exports = otplease
+function otplease (opts, fn) {
+ opts = opts.concat ? opts : optCheck(opts)
+ return BB.try(() => {
+ return fn(opts)
+ }).catch(err => {
+ if (err.code !== 'EOTP' && !(err.code === 'E401' && /one-time pass/.test(err.body))) {
+ throw err
+ } else if (!process.stdin.isTTY || !process.stdout.isTTY) {
+ throw err
+ } else {
+ return readUserInfo.otp(
+ optCheck(opts).prompt
+ ).then(otp => fn(opts.concat({otp})))
+ }
+ })
+}