|
1 | 1 | 'use strict' |
| 2 | + |
2 | 3 | const profile = require('libnpm/profile') |
3 | 4 | const npm = require('./npm.js') |
| 5 | +const figgyPudding = require('figgy-pudding') |
| 6 | +const npmConfig = require('./config/figgy-config.js') |
4 | 7 | const output = require('./utils/output.js') |
5 | 8 | const Table = require('cli-table3') |
6 | 9 | const Bluebird = require('bluebird') |
@@ -76,22 +79,43 @@ function generateTokenIds (tokens, minLength) { |
76 | 79 | return byId |
77 | 80 | } |
78 | 81 |
|
| 82 | +const TokenConfig = figgyPudding({ |
| 83 | + registry: {}, |
| 84 | + otp: {}, |
| 85 | + cidr: {}, |
| 86 | + 'read-only': {}, |
| 87 | + json: {}, |
| 88 | + parseable: {} |
| 89 | +}) |
| 90 | + |
79 | 91 | function config () { |
80 | | - const conf = { |
81 | | - json: npm.config.get('json'), |
82 | | - parseable: npm.config.get('parseable'), |
83 | | - registry: npm.config.get('registry'), |
84 | | - otp: npm.config.get('otp') |
85 | | - } |
| 92 | + let conf = TokenConfig(npmConfig()) |
86 | 93 | const creds = npm.config.getCredentialsByURI(conf.registry) |
87 | 94 | if (creds.token) { |
88 | | - conf.auth = {token: creds.token} |
| 95 | + conf = conf.concat({ |
| 96 | + auth: { token: creds.token } |
| 97 | + }) |
89 | 98 | } else if (creds.username) { |
90 | | - conf.auth = {basic: {username: creds.username, password: creds.password}} |
| 99 | + conf = conf.concat({ |
| 100 | + auth: { |
| 101 | + basic: { |
| 102 | + username: creds.username, |
| 103 | + password: creds.password |
| 104 | + } |
| 105 | + } |
| 106 | + }) |
91 | 107 | } else if (creds.auth) { |
92 | 108 | const auth = Buffer.from(creds.auth, 'base64').toString().split(':', 2) |
93 | | - conf.auth = {basic: {username: auth[0], password: auth[1]}} |
| 109 | + conf = conf.concat({ |
| 110 | + auth: { |
| 111 | + basic: { |
| 112 | + username: auth[0], |
| 113 | + password: auth[1] |
| 114 | + } |
| 115 | + } |
| 116 | + }) |
94 | 117 | } else { |
| 118 | + conf = conf.concat({ auth: {} }) |
95 | 119 | conf.auth = {} |
96 | 120 | } |
97 | 121 | if (conf.otp) conf.auth.otp = conf.otp |
@@ -183,8 +207,8 @@ function rm (args) { |
183 | 207 |
|
184 | 208 | function create (args) { |
185 | 209 | const conf = config() |
186 | | - const cidr = npm.config.get('cidr') |
187 | | - const readonly = npm.config.get('read-only') |
| 210 | + const cidr = conf.cidr |
| 211 | + const readonly = conf['read-only'] |
188 | 212 |
|
189 | 213 | const validCIDR = validateCIDRList(cidr) |
190 | 214 | return readUserInfo.password().then((password) => { |
|
0 commit comments