Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

token: fix otp for create and remove #175

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const npm = require('./npm.js')
const figgyPudding = require('figgy-pudding')
const npmConfig = require('./config/figgy-config.js')
const output = require('./utils/output.js')
const otplease = require('./utils/otplease.js')
const Table = require('cli-table3')
const Bluebird = require('bluebird')
const isCidrV4 = require('is-cidr').v4
Expand Down Expand Up @@ -80,6 +81,7 @@ function generateTokenIds (tokens, minLength) {
}

const TokenConfig = figgyPudding({
auth: {},
registry: {},
otp: {},
cidr: {},
Expand Down Expand Up @@ -185,13 +187,8 @@ function rm (args) {
}
})
return Bluebird.map(toRemove, (key) => {
return profile.removeToken(key, conf).catch((ex) => {
if (ex.code !== 'EOTP') throw ex
log.info('token', 'failed because revoking this token requires OTP')
return readUserInfo.otp().then((otp) => {
conf.auth.otp = otp
return profile.removeToken(key, conf)
})
return otplease(conf, conf => {
return profile.removeToken(key, conf)
})
})
})).then(() => {
Expand All @@ -213,15 +210,9 @@ function create (args) {
const validCIDR = validateCIDRList(cidr)
return readUserInfo.password().then((password) => {
log.info('token', 'creating')
return profile.createToken(password, readonly, validCIDR, conf).catch((ex) => {
if (ex.code !== 'EOTP') throw ex
log.info('token', 'failed because it requires OTP')
return readUserInfo.otp().then((otp) => {
conf.auth.otp = otp
log.info('token', 'creating with OTP')
return pulseTillDone.withPromise(profile.createToken(password, readonly, validCIDR, conf))
})
})
return pulseTillDone.withPromise(otplease(conf, conf => {
return profile.createToken(password, readonly, validCIDR, conf)
}))
}).then((result) => {
delete result.key
delete result.updated
Expand Down