mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-03 23:09:17 -05:00
refactor: add types on auth files
This commit is contained in:
parent
66118ad008
commit
9ade39a264
2 changed files with 14 additions and 10 deletions
|
@ -1,8 +1,12 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import {ErrorCode} from './utils';
|
import {ErrorCode} from './utils';
|
||||||
import {API_ERROR} from './constants';
|
import {API_ERROR} from './constants';
|
||||||
|
|
||||||
export function allow_action(action) {
|
import type {RemoteUser, Package, Callback} from '@verdaccio/types';
|
||||||
return function(user, pkg, callback) {
|
|
||||||
|
export function allow_action(action: string) {
|
||||||
|
return function(user: RemoteUser, pkg: Package, callback: Callback) {
|
||||||
const {name, groups} = user;
|
const {name, groups} = user;
|
||||||
const hasPermission = pkg[action].some((group) => name === group || groups.includes(group));
|
const hasPermission = pkg[action].some((group) => name === group || groups.includes(group));
|
||||||
|
|
||||||
|
@ -20,11 +24,11 @@ export function allow_action(action) {
|
||||||
|
|
||||||
export function getDefaultPlugins() {
|
export function getDefaultPlugins() {
|
||||||
return {
|
return {
|
||||||
authenticate(user, password, cb) {
|
authenticate(user: string, password: string, cb: Callback) {
|
||||||
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
|
cb(ErrorCode.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||||
},
|
},
|
||||||
|
|
||||||
add_user(user, password, cb) {
|
add_user(user: string, password: string, cb: Callback) {
|
||||||
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
|
return cb(ErrorCode.getConflict(API_ERROR.BAD_USERNAME_PASSWORD));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -126,11 +126,11 @@ class Auth implements IAuth {
|
||||||
(function next() {
|
(function next() {
|
||||||
const plugin = plugins.shift();
|
const plugin = plugins.shift();
|
||||||
|
|
||||||
if (typeof(plugin.allow_access) !== 'function') {
|
if (_.isFunction(plugin.allow_access) === false) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.allow_access(user, pkg, function(err, ok) {
|
plugin.allow_access(user, pkg, function(err, ok: boolean) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
@ -155,11 +155,11 @@ class Auth implements IAuth {
|
||||||
(function next() {
|
(function next() {
|
||||||
const plugin = plugins.shift();
|
const plugin = plugins.shift();
|
||||||
|
|
||||||
if (typeof(plugin.allow_publish) !== 'function') {
|
if (_.isFunction(plugin.allow_publish) === false) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.allow_publish(user, pkg, (err, ok) => {
|
plugin.allow_publish(user, pkg, (err, ok: boolean) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,8 @@ class Auth implements IAuth {
|
||||||
return _next();
|
return _next();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.remote_user != null && req.remote_user.name !== undefined) {
|
if (_.isUndefined(req.remote_user) === false
|
||||||
|
&& _.isUndefined(req.remote_user.name) === false) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
req.remote_user = buildAnonymousUser();
|
req.remote_user = buildAnonymousUser();
|
||||||
|
@ -204,7 +205,6 @@ class Auth implements IAuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
const credentials = this._parseCredentials(parts);
|
const credentials = this._parseCredentials(parts);
|
||||||
|
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue