2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
2015-04-11 16:09:19 +03:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
module.exports = Plugin;
|
2015-04-11 16:09:19 +03:00
|
|
|
|
2017-07-02 00:05:58 +02:00
|
|
|
function Plugin(config) {
|
2017-04-19 21:15:28 +02:00
|
|
|
let self = Object.create(Plugin.prototype);
|
|
|
|
self._config = config;
|
|
|
|
return self;
|
2015-04-11 16:09:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// plugin is expected to be compatible with...
|
2017-04-19 21:15:28 +02:00
|
|
|
Plugin.prototype.verdaccio_version = '1.1.0';
|
2015-04-11 16:09:19 +03:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
Plugin.prototype.allow_access = function(user, pkg, cb) {
|
|
|
|
if (!pkg.handled_by_auth_plugin) {
|
2015-04-11 16:09:19 +03:00
|
|
|
// delegate to next plugin
|
2017-04-19 21:15:28 +02:00
|
|
|
return cb(null, false);
|
2015-04-11 16:09:19 +03:00
|
|
|
}
|
2017-07-02 00:05:58 +02:00
|
|
|
if (user.name !== this._config.allow_user) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let err = Error('i don\'t know anything about you');
|
2017-04-19 21:15:28 +02:00
|
|
|
err.status = 403;
|
|
|
|
return cb(err);
|
2015-04-11 16:09:19 +03:00
|
|
|
}
|
2017-07-02 00:05:58 +02:00
|
|
|
if (pkg.name !== this._config.to_access) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let err = Error('you\'re not allowed here');
|
2017-04-19 21:15:28 +02:00
|
|
|
err.status = 403;
|
|
|
|
return cb(err);
|
2015-04-11 16:09:19 +03:00
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
return cb(null, true);
|
|
|
|
};
|