refactor: user agent on config

remove logic users prop is not longer supported
67c63892d3 (diff-574051ef1fbe43a2746c5cd241d631c7)
This commit is contained in:
Juan Picado @jotadeveloper 2018-06-30 22:39:06 +02:00
parent db6c0d5510
commit 957b71e8bb
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
5 changed files with 27 additions and 18 deletions

View File

@ -1,14 +1,14 @@
import {generateRandomHexString} from './crypto-utils';
import {normalisePackageAccess} from './config-utils';
import {getUserAgent} from './utils';
import {APP_ERROR} from './constants';
const assert = require('assert');
const _ = require('lodash');
const minimatch = require('minimatch');
const Utils = require('./utils');
const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-vars
const pkgVersion = module.exports.version;
const pkgName = module.exports.name;
const LoggerApi = require('./logger');
const strategicConfigProps = ['users', 'uplinks', 'packages'];
const allowedEnvConfig = ['http_proxy', 'https_proxy', 'no_proxy'];
@ -29,6 +29,7 @@ class Config {
*/
constructor(config) {
const self = this;
this.logger = LoggerApi.logger;
const users = {
all: true,
anonymous: true,
@ -43,16 +44,18 @@ class Config {
}
}
if (!self.user_agent) {
self.user_agent = `${pkgName}/${pkgVersion}`;
if (_.isNil(this.user_agent)) {
this.user_agent = getUserAgent();
}
// some weird shell scripts are valid yaml files parsed as string
assert.equal(typeof(config), 'object', 'CONFIG: it doesn\'t look like a valid config file');
assert(_.isObject(config), APP_ERROR.CONFIG_NOT_VALID);
// sanity check for strategic config properties
strategicConfigProps.forEach(function(x) {
if (self[x] == null) self[x] = {};
if (self[x] == null) {
self[x] = {};
}
assert(Utils.isObject(self[x]), `CONFIG: bad "${x}" value (object expected)`);
});
@ -73,13 +76,9 @@ class Config {
}
}
for (let user in self.users) {
if (Object.prototype.hasOwnProperty.call(self.users, user)) {
assert(self.users[user].password, 'CONFIG: no password for user: ' + user);
assert(typeof(self.users[user].password) === 'string' &&
self.users[user].password.match(/^[a-f0-9]{40}$/)
, 'CONFIG: wrong password format for user: ' + user + ', sha1 expected');
}
if (_.isNil(this.users) === false) {
this.logger.warn(`[users]: property on configuration file
is not longer supported, property being ignored`);
}
for (let uplink in self.uplinks) {

View File

@ -83,6 +83,10 @@ export const API_ERROR = {
WEB_DISABLED: 'Web interface is disabled in the config file',
};
export const APP_ERROR = {
CONFIG_NOT_VALID: 'CONFIG: it does not look like a valid config file',
};
export const DEFAULT_NO_README = 'ERROR: No README data found!';

View File

@ -17,9 +17,18 @@ import type {$Request} from 'express';
import type {StringValue} from '../../types';
const Logger = require('./logger');
const pkginfo = require('pkginfo')(module); // eslint-disable-line no-unused-vars
const pkgVersion = module.exports.version;
const pkgName = module.exports.name;
export const DIST_TAGS = 'dist-tags';
export function getUserAgent(): string {
assert(_.isString(pkgName));
assert(_.isString(pkgVersion));
return `${pkgName}/${pkgVersion}`;
}
/**
* Validate a package.
* @return {Boolean} whether the package is valid or not

View File

@ -1,9 +1,5 @@
storage: ./.verdaccio_test_env/test-storage
users:
test:
password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
uplinks:
npmjs:
url: https://registry.npmjs.org/

View File

@ -6,6 +6,7 @@ import {parseConfigFile} from '../../../src/lib/utils';
import {DEFAULT_REGISTRY, DEFAULT_UPLINK, ROLES, WEB_TITLE} from '../../../src/lib/constants';
const resolveConf = (conf) => path.join(__dirname, `../../../conf/${conf}.yaml`);
require('../../../src/lib/logger').setup([]);
const checkDefaultUplink = (config) => {
expect(_.isObject(config.uplinks[DEFAULT_UPLINK])).toBeTruthy();