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

Add support for requiring 2fa to publish specific packages. #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions doc/cli/npm-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ npm-access(1) -- Set access level on published packages
npm access public [<package>]
npm access restricted [<package>]

npm access 2fa-required [<package>]
npm access 2fa-not-required [<package>]

npm access grant <read-only|read-write> <scope:team> [<package>]
npm access revoke <scope:team> [<package>]

Expand All @@ -24,6 +27,10 @@ subcommand.
* public / restricted:
Set a package to be either publicly accessible or restricted.

* 2fa-required / 2fa-not-required:
Set a package as requiring or not requiring that the publisher have two
factor authentication enabled on their account.

* grant / revoke:
Add or remove the ability of users and teams to have read-only or read-write
access to a package.
Expand Down
30 changes: 20 additions & 10 deletions lib/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var readPackageJson = require('read-package-json')
var mapToRegistry = require('./utils/map-to-registry.js')
var npm = require('./npm.js')
var output = require('./utils/output.js')
const readUserInfo = require('./utils/read-user-info.js')
const Bluebird = require('bluebird')
const registryAccess = Bluebird.promisify(npm.registry.access.bind(npm.registry))

var whoami = require('./whoami')

Expand All @@ -17,6 +20,8 @@ access.usage =
'npm access restricted [<package>]\n' +
'npm access grant <read-only|read-write> <scope:team> [<package>]\n' +
'npm access revoke <scope:team> [<package>]\n' +
'npm access 2fa-required <package>\n' +
'npm access 2fa-not-required <package>\n' +
'npm access ls-packages [<user>|<scope>|<scope:team>]\n' +
'npm access ls-collaborators [<package> [<user>]]\n' +
'npm access edit [<package>]'
Expand Down Expand Up @@ -61,17 +66,22 @@ function access (args, cb) {

function invokeCmd (err, uri, auth, base) {
if (err) { return cb(err) }
params.auth = auth
try {
return npm.registry.access(cmd, uri, params, function (err, data) {
if (!err && data) {
output(JSON.stringify(data, undefined, 2))
}
cb(err, data)
return Bluebird.try(() => {
params.auth = auth
try {
Copy link
Contributor Author

@iarna iarna Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super weird and actually what the API for this function is... it throws if it's given a command its never heard of, but ALSO takes an errback that it uses for network errors. I suppose it's not that unreasonable... it's like an argument assertion.

Just with promises it feels much weirder.

return registryAccess(cmd, uri, params)
} catch (err) {
throw err.message + '\n\nUsage:\n' + access.usage
}
}).catch(err => {
if (err.code !== 'EOTP') throw err
return readUserInfo.otp('Enter OTP: ').then(otp => {
params.auth.otp = otp
return registryAccess(cmd, uri, params)
})
} catch (e) {
cb(e.message + '\n\nUsage:\n' + access.usage)
}
}).then(data => {
return output(data ? JSON.stringify(data, undefined, 2) : '"ok"')
}).asCallback(cb)
}
}

Expand Down
4 changes: 4 additions & 0 deletions node_modules/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions node_modules/npm-registry-client/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions node_modules/npm-registry-client/lib/access.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions node_modules/npm-registry-client/lib/request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 14 additions & 16 deletions node_modules/npm-registry-client/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"npm-packlist": "~1.1.10",
"npm-pick-manifest": "^2.1.0",
"npm-profile": "^3.0.2",
"npm-registry-client": "^8.5.1",
"npm-registry-client": "^8.6.0",
"npm-registry-fetch": "^1.1.0",
"npm-user-validate": "~1.0.0",
"npmlog": "~4.1.2",
Expand Down