@@ -5,6 +5,7 @@ const npm = require('./npm.js')
5
5
const figgyPudding = require ( 'figgy-pudding' )
6
6
const npmConfig = require ( './config/figgy-config.js' )
7
7
const output = require ( './utils/output.js' )
8
+ const otplease = require ( './utils/otplease.js' )
8
9
const Table = require ( 'cli-table3' )
9
10
const Bluebird = require ( 'bluebird' )
10
11
const isCidrV4 = require ( 'is-cidr' ) . v4
@@ -80,6 +81,7 @@ function generateTokenIds (tokens, minLength) {
80
81
}
81
82
82
83
const TokenConfig = figgyPudding ( {
84
+ auth : { } ,
83
85
registry : { } ,
84
86
otp : { } ,
85
87
cidr : { } ,
@@ -185,13 +187,8 @@ function rm (args) {
185
187
}
186
188
} )
187
189
return Bluebird . map ( toRemove , ( key ) => {
188
- return profile . removeToken ( key , conf ) . catch ( ( ex ) => {
189
- if ( ex . code !== 'EOTP' ) throw ex
190
- log . info ( 'token' , 'failed because revoking this token requires OTP' )
191
- return readUserInfo . otp ( ) . then ( ( otp ) => {
192
- conf . auth . otp = otp
193
- return profile . removeToken ( key , conf )
194
- } )
190
+ return otplease ( conf , conf => {
191
+ return profile . removeToken ( key , conf )
195
192
} )
196
193
} )
197
194
} ) ) . then ( ( ) => {
@@ -213,15 +210,9 @@ function create (args) {
213
210
const validCIDR = validateCIDRList ( cidr )
214
211
return readUserInfo . password ( ) . then ( ( password ) => {
215
212
log . info ( 'token' , 'creating' )
216
- return profile . createToken ( password , readonly , validCIDR , conf ) . catch ( ( ex ) => {
217
- if ( ex . code !== 'EOTP' ) throw ex
218
- log . info ( 'token' , 'failed because it requires OTP' )
219
- return readUserInfo . otp ( ) . then ( ( otp ) => {
220
- conf . auth . otp = otp
221
- log . info ( 'token' , 'creating with OTP' )
222
- return pulseTillDone . withPromise ( profile . createToken ( password , readonly , validCIDR , conf ) )
223
- } )
224
- } )
213
+ return pulseTillDone . withPromise ( otplease ( conf , conf => {
214
+ return profile . createToken ( password , readonly , validCIDR , conf )
215
+ } ) )
225
216
} ) . then ( ( result ) => {
226
217
delete result . key
227
218
delete result . updated
0 commit comments