0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00

feat: remove support for allow_ prefix (#1741)

allow_access, allow_publish and proxy_access were supported as package access but this commit drop that support and ignore the properties
This commit is contained in:
Juan Picado @jotadeveloper 2020-03-08 22:30:14 +01:00 committed by Juan Picado
parent fa230117a1
commit 644d42564d
4 changed files with 35 additions and 40 deletions

View file

@ -36,14 +36,10 @@ export interface StartUpConfig {
// legacy should be removed in long term
export interface LegacyPackageList {
[key: string]: LegacyPackageAccess;
[key: string]: PackageAccessAddOn;
}
export type LegacyPackageAccess = PackageAccess & {
allow_publish?: string[];
allow_proxy?: string[];
allow_access?: string[];
proxy_access?: string[];
export type PackageAccessAddOn = PackageAccess & {
// FIXME: should be published on @verdaccio/types
unpublish?: string[];
}

View file

@ -19,26 +19,25 @@ const BLACKLIST = {
* Normalize user list.
* @return {Array}
*/
export function normalizeUserList(oldFormat: any, newFormat: any): any {
const result: any[][] = [];
/* eslint prefer-rest-params: "off" */
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] == null) {
continue;
export function normalizeUserList(groupsList: any): any {
const result: any[] = [];
if (_.isNil(groupsList)) {
return result;
}
// if it's a string, split it to array
if (_.isString(arguments[i])) {
result.push(arguments[i].split(/\s+/));
} else if (Array.isArray(arguments[i])) {
result.push(arguments[i]);
if (_.isString(groupsList)) {
const groupsArray = groupsList.split(/\s+/);
result.push(groupsArray);
} else if (Array.isArray(groupsList)) {
result.push(groupsList);
} else {
throw ErrorCode.getInternalError(
'CONFIG: bad package acl (array or string expected): ' + JSON.stringify(arguments[i])
'CONFIG: bad package acl (array or string expected): ' + JSON.stringify(groupsList)
);
}
}
return _.flatten(result);
}
@ -110,25 +109,26 @@ export function normalisePackageAccess(packages: LegacyPackageList): LegacyPacka
const normalizedPkgs: LegacyPackageList = { ...packages };
// add a default rule for all packages to make writing plugins easier
if (_.isNil(normalizedPkgs['**'])) {
normalizedPkgs['**'] = { access: [], publish: [], proxy: [] };
normalizedPkgs['**'] = {
access: [],
publish: [],
proxy: []
};
}
for (const pkg in packages) {
if (Object.prototype.hasOwnProperty.call(packages, pkg)) {
assert(
_.isObject(packages[pkg]) && _.isArray(packages[pkg]) === false,
`CONFIG: bad "'${pkg}'" package description (object expected)`
);
normalizedPkgs[pkg].access = normalizeUserList(packages[pkg].allow_access, packages[pkg].access);
delete normalizedPkgs[pkg].allow_access;
normalizedPkgs[pkg].publish = normalizeUserList(packages[pkg].allow_publish, packages[pkg].publish);
delete normalizedPkgs[pkg].allow_publish;
normalizedPkgs[pkg].proxy = normalizeUserList(packages[pkg].proxy_access, packages[pkg].proxy);
delete normalizedPkgs[pkg].proxy_access;
const packageAccess = packages[pkg];
const isInvalid = _.isObject(packageAccess) && _.isArray(packageAccess) === false;
assert(isInvalid, `CONFIG: bad "'${pkg}'" package description (object expected)`);
normalizedPkgs[pkg].access = normalizeUserList(packageAccess.access);
normalizedPkgs[pkg].publish = normalizeUserList(packageAccess.publish);
normalizedPkgs[pkg].proxy = normalizeUserList(packageAccess.proxy);
// if unpublish is not defined, we set to false to fallback in publish access
normalizedPkgs[pkg].unpublish = _.isUndefined(packages[pkg].unpublish)
normalizedPkgs[pkg].unpublish = _.isUndefined(packageAccess.unpublish)
? false
: normalizeUserList([], packages[pkg].unpublish);
: normalizeUserList(packageAccess.unpublish);
}
}

View file

@ -33,11 +33,12 @@ import {
getCode,
} from '@verdaccio/commons-api';
import { IncomingHttpHeaders } from 'http2';
import { IncomingHttpHeaders } from 'http';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-var-requires
// FIXME: this is fixed, should pick the package.json or official version
const pkgVersion = '5.0.0';
const pkgName = 'verdaccio';

View file

@ -8,7 +8,8 @@ import {parseConfigFile} from '../src/utils';
import {
getMatchedPackagesSpec,
hasProxyTo,
normalisePackageAccess, sanityCheckUplinksProps,
normalisePackageAccess,
sanityCheckUplinksProps,
uplinkSanityCheck
} from '../src/config-utils';
@ -132,6 +133,7 @@ describe('Config Utilities', () => {
const access = normalisePackageAccess(packages);
expect(access).toBeDefined();
const scoped = access[`${PACKAGE_ACCESS.SCOPE}`];
const all = access[`${PACKAGE_ACCESS.ALL}`];
const react = access['react-*'];
@ -141,13 +143,12 @@ describe('Config Utilities', () => {
// Intended checks, Typescript should catch this, we test the runtime part
// @ts-ignore
expect(react.access[0]).toBe(ROLES.$ALL);
expect(react.publish).toBeDefined();
expect(react.access).toEqual([]);
// @ts-ignore
expect(react.publish[0]).toBe('admin');
expect(react.proxy).toBeDefined();
// @ts-ignore
expect(react.proxy[0]).toBe('uplink2');
expect(react.proxy).toEqual([]);
expect(react.storage).toBeDefined();
expect(react.storage).toBe('react-storage');
@ -158,9 +159,6 @@ describe('Config Utilities', () => {
expect(all.storage).not.toBeDefined();
expect(all.publish).toBeDefined();
expect(all.proxy).toBeDefined();
expect(all.allow_access).toBeUndefined();
expect(all.allow_publish).toBeUndefined();
expect(all.proxy_access).toBeUndefined();
});
test('should check not default packages access', ()=> {