Skip to content

Commit 4cf850d

Browse files
zkataeschright
authored andcommitted
token: use figgy-config to make sure extra opts are there (#149)
PR-URL: #149 Credit: @zkat Reviewed-By: @aeschright
1 parent aa32239 commit 4cf850d

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

lib/token.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict'
2+
23
const profile = require('libnpm/profile')
34
const npm = require('./npm.js')
5+
const figgyPudding = require('figgy-pudding')
6+
const npmConfig = require('./config/figgy-config.js')
47
const output = require('./utils/output.js')
58
const Table = require('cli-table3')
69
const Bluebird = require('bluebird')
@@ -76,22 +79,43 @@ function generateTokenIds (tokens, minLength) {
7679
return byId
7780
}
7881

82+
const TokenConfig = figgyPudding({
83+
registry: {},
84+
otp: {},
85+
cidr: {},
86+
'read-only': {},
87+
json: {},
88+
parseable: {}
89+
})
90+
7991
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())
8693
const creds = npm.config.getCredentialsByURI(conf.registry)
8794
if (creds.token) {
88-
conf.auth = {token: creds.token}
95+
conf = conf.concat({
96+
auth: { token: creds.token }
97+
})
8998
} 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+
})
91107
} else if (creds.auth) {
92108
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+
})
94117
} else {
118+
conf = conf.concat({ auth: {} })
95119
conf.auth = {}
96120
}
97121
if (conf.otp) conf.auth.otp = conf.otp
@@ -183,8 +207,8 @@ function rm (args) {
183207

184208
function create (args) {
185209
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']
188212

189213
const validCIDR = validateCIDRList(cidr)
190214
return readUserInfo.password().then((password) => {

test/tap/unit-token-validate-cidr.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22
const test = require('tap').test
3-
const requireInject = require('require-inject')
4-
const validateCIDRList = requireInject('../../lib/token.js', {'../../lib/npm.js': {}})._validateCIDRList
3+
const validateCIDRList = require('../../lib/token.js')._validateCIDRList
54

65
test('validateCIDRList', (t) => {
76
t.plan(10)

0 commit comments

Comments
 (0)