mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
Change how package provider plugins are configured
This commit is contained in:
parent
76a1e8df80
commit
82539add26
3 changed files with 41 additions and 28 deletions
|
@ -59,6 +59,11 @@ packages:
|
|||
# # you can override storage directory for a group of packages this way:
|
||||
# storage: 'local_storage'
|
||||
|
||||
# Delegate handling package access authorization and settings to an external
|
||||
# plugin for packages with this prefix
|
||||
#'external-*':
|
||||
# plugin: my_plugin
|
||||
|
||||
'*':
|
||||
# allow all users to read packages (including non-authenticated users)
|
||||
#
|
||||
|
|
|
@ -84,6 +84,11 @@ function Config(config) {
|
|||
|
||||
function check_userlist(i, hash, action) {
|
||||
if (hash[action] == null) hash[action] = []
|
||||
check_stringlist(i, hash, action)
|
||||
}
|
||||
|
||||
function check_stringlist(i, hash, action) {
|
||||
if (!hash[action]) return
|
||||
|
||||
// if it's a string, split it to array
|
||||
if (typeof(hash[action]) === 'string') {
|
||||
|
@ -97,6 +102,20 @@ function Config(config) {
|
|||
hash[action] = flatten(hash[action])
|
||||
}
|
||||
|
||||
// if a field in a string or array, converts into a hash with keys
|
||||
// of the string and values of empty object
|
||||
function check_objectset(i, hash, action) {
|
||||
if (!hash[action]) return
|
||||
if (Array.isArray(hash[action]) || typeof(hash[action]) === 'string') {
|
||||
check_stringlist(i, hash, action)
|
||||
var new_object = {}
|
||||
hash[action].forEach(function(string) {
|
||||
new_object[string] = {}
|
||||
})
|
||||
hash[action] = new_object
|
||||
}
|
||||
}
|
||||
|
||||
for (var i in self.packages) {
|
||||
assert(
|
||||
typeof(self.packages[i]) === 'object' &&
|
||||
|
@ -108,6 +127,8 @@ function Config(config) {
|
|||
check_userlist(i, self.packages[i], 'proxy_access')
|
||||
check_userlist(i, self.packages[i], 'proxy_publish')
|
||||
|
||||
check_objectset(i, self.packages[i], 'plugin')
|
||||
|
||||
// deprecated
|
||||
check_userlist(i, self.packages[i], 'access')
|
||||
check_userlist(i, self.packages[i], 'proxy')
|
||||
|
|
|
@ -15,17 +15,28 @@ function PackageProvider(config) {
|
|||
logger: self.logger
|
||||
}
|
||||
|
||||
self.plugins = load_plugins(config.package_provider, plugin_params, 'package_provider', ['allow_access'])
|
||||
// load all plugins referenced by any package
|
||||
for (var i in config.packages) {
|
||||
if(config.packages[i].plugin) {
|
||||
config.packages[i].loaded_plugins = load_plugins(config.packages[i].plugin, plugin_params, 'package_provider', ['allow_access'])
|
||||
}
|
||||
}
|
||||
|
||||
self.plugins.push(new ConfigPackageProvider({}, plugin_params))
|
||||
self.plugins.push(new DenyPackageProvider({}, plugin_params))
|
||||
self.default_plugin = new ConfigPackageProvider({}, plugin_params)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
function check_plugin_result(function_name, package, arg, cb) {
|
||||
var self = this
|
||||
var plugins = self.config.get_package_setting(package, 'loaded_plugins')
|
||||
if (!plugins || !plugins.length) {
|
||||
self.default_plugin[function_name](package, arg, cb)
|
||||
return
|
||||
}
|
||||
|
||||
var current_result
|
||||
async.eachSeries(this.plugins, function(plugin, next) {
|
||||
async.eachSeries(plugins, function(plugin, next) {
|
||||
if(current_result === undefined && typeof plugin[function_name] === 'function') {
|
||||
plugin[function_name](package, arg, function(error, result) {
|
||||
if(error) {
|
||||
|
@ -100,27 +111,3 @@ ConfigPackageProvider.prototype.get_package_setting = function(package, setting,
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
// package provider to deny all access, used as default after everything else falls through
|
||||
function DenyPackageProvider() {
|
||||
var self = Object.create(DenyPackageProvider.prototype)
|
||||
return self
|
||||
}
|
||||
|
||||
DenyPackageProvider.prototype.allow_access = function(package, user, cb) {
|
||||
setImmediate(function() {
|
||||
cb(null, false)
|
||||
})
|
||||
}
|
||||
|
||||
DenyPackageProvider.prototype.allow_publish = function(package, user, cb) {
|
||||
setImmediate(function() {
|
||||
cb(null, false)
|
||||
})
|
||||
}
|
||||
|
||||
DenyPackageProvider.prototype.proxy_access = function(package, uplink, cb) {
|
||||
setImmediate(function() {
|
||||
cb(null, false)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue