From 231237609289c7f25c1c4be503d5425d5c5d8c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 28 Jan 2019 15:31:54 -0800 Subject: [PATCH] token: use figgy-config to make sure extra opts are there --- lib/token.js | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/token.js b/lib/token.js index cccbba2f9ad75..326f98ec7ef87 100644 --- a/lib/token.js +++ b/lib/token.js @@ -1,6 +1,9 @@ 'use strict' + const profile = require('libnpm/profile') const npm = require('./npm.js') +const figgyPudding = require('figgy-pudding') +const npmConfig = require('./config/figgy-config.js') const output = require('./utils/output.js') const Table = require('cli-table3') const Bluebird = require('bluebird') @@ -76,22 +79,43 @@ function generateTokenIds (tokens, minLength) { return byId } +const TokenConfig = figgyPudding({ + registry: {}, + otp: {}, + cidr: {}, + 'read-only': {}, + json: {}, + parseable: {} +}) + function config () { - const conf = { - json: npm.config.get('json'), - parseable: npm.config.get('parseable'), - registry: npm.config.get('registry'), - otp: npm.config.get('otp') - } + let conf = TokenConfig(npmConfig()) const creds = npm.config.getCredentialsByURI(conf.registry) if (creds.token) { - conf.auth = {token: creds.token} + conf = conf.concat({ + auth: { token: creds.token } + }) } else if (creds.username) { - conf.auth = {basic: {username: creds.username, password: creds.password}} + conf = conf.concat({ + auth: { + basic: { + username: creds.username, + password: creds.password + } + } + }) } else if (creds.auth) { const auth = Buffer.from(creds.auth, 'base64').toString().split(':', 2) - conf.auth = {basic: {username: auth[0], password: auth[1]}} + conf = conf.concat({ + auth: { + basic: { + username: auth[0], + password: auth[1] + } + } + }) } else { + conf = conf.concat({ auth: {} }) conf.auth = {} } if (conf.otp) conf.auth.otp = conf.otp @@ -183,8 +207,8 @@ function rm (args) { function create (args) { const conf = config() - const cidr = npm.config.get('cidr') - const readonly = npm.config.get('read-only') + const cidr = conf.cidr + const readonly = conf['read-only'] const validCIDR = validateCIDRList(cidr) return readUserInfo.password().then((password) => {