File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const BB = require ( 'bluebird' )
4
+
5
+ const optCheck = require ( 'figgy-pudding' ) ( {
6
+ prompt : { default : 'This operation requires a one-time password.\nEnter OTP:' } ,
7
+ otp : { }
8
+ } )
9
+ const readUserInfo = require ( './read-user-info.js' )
10
+
11
+ module . exports = otplease
12
+ function otplease ( opts , fn ) {
13
+ opts = opts . concat ? opts : optCheck ( opts )
14
+ return BB . try ( ( ) => {
15
+ return fn ( opts )
16
+ } ) . catch ( err => {
17
+ if ( err . code !== 'EOTP' && ! ( err . code === 'E401' && / o n e - t i m e p a s s / . test ( err . body ) ) ) {
18
+ throw err
19
+ } else if ( ! process . stdin . isTTY || ! process . stdout . isTTY ) {
20
+ throw err
21
+ } else {
22
+ return readUserInfo . otp (
23
+ optCheck ( opts ) . prompt
24
+ ) . then ( otp => fn ( opts . concat ( { otp} ) ) )
25
+ }
26
+ } )
27
+ }
You can’t perform that action at this time.
0 commit comments