@@ -5,6 +5,7 @@ const npm = require('./npm.js')
55const figgyPudding = require ( 'figgy-pudding' )
66const npmConfig = require ( './config/figgy-config.js' )
77const output = require ( './utils/output.js' )
8+ const otplease = require ( './utils/otplease.js' )
89const Table = require ( 'cli-table3' )
910const Bluebird = require ( 'bluebird' )
1011const isCidrV4 = require ( 'is-cidr' ) . v4
@@ -80,6 +81,7 @@ function generateTokenIds (tokens, minLength) {
8081}
8182
8283const TokenConfig = figgyPudding ( {
84+ auth : { } ,
8385 registry : { } ,
8486 otp : { } ,
8587 cidr : { } ,
@@ -185,13 +187,8 @@ function rm (args) {
185187 }
186188 } )
187189 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 )
195192 } )
196193 } )
197194 } ) ) . then ( ( ) => {
@@ -213,15 +210,9 @@ function create (args) {
213210 const validCIDR = validateCIDRList ( cidr )
214211 return readUserInfo . password ( ) . then ( ( password ) => {
215212 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+ } ) )
225216 } ) . then ( ( result ) => {
226217 delete result . key
227218 delete result . updated
0 commit comments