From 148795918fff8c273edec5099f9a8ed21bb90fe2 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Wed, 12 Nov 2014 18:49:37 +0300 Subject: [PATCH] move config file to separate folder Make default config smaller, allow all users by default there. --- conf/README.md | 1 + conf/default.yaml | 51 +++++++++++++++++++++++++++ lib/config_def.yaml => conf/full.yaml | 2 +- lib/cli.js | 8 ++--- lib/config.js | 2 +- lib/config_gen.js | 19 ---------- 6 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 conf/README.md create mode 100644 conf/default.yaml rename lib/config_def.yaml => conf/full.yaml (98%) delete mode 100644 lib/config_gen.js diff --git a/conf/README.md b/conf/README.md new file mode 100644 index 000000000..8177adfd5 --- /dev/null +++ b/conf/README.md @@ -0,0 +1 @@ +This directory is for config examples. diff --git a/conf/default.yaml b/conf/default.yaml new file mode 100644 index 000000000..0ee8cb8eb --- /dev/null +++ b/conf/default.yaml @@ -0,0 +1,51 @@ +# +# This is the default config file. It allows all users to do anything, +# so don't use it on production systems. +# +# Look here for more config file examples: +# https://github.com/rlidwka/sinopia/tree/master/conf +# + +# path to a directory with all packages +storage: ./storage + +web: + # web interface is disabled by default in 0.x, will be enabled soon in 1.x + # when all its issues will be fixed + # + # set this to `true` if you want to experiment with web ui now; + # this has a lot of issues, e.g. no auth yet, so use at your own risk + #enable: true + +auth: + htpasswd: + file: ./htpasswd + # Maximum amount of users allowed to register, defaults to "+inf". + # You can set this to -1 to disable registration. + #max_users: 1000 + +# a list of other known repositories we can talk to +uplinks: + npmjs: + url: https://registry.npmjs.org/ + +packages: + '*': + # allow all users (including non-authenticated users) to read and + # publish all packages + # + # you can specify usernames/groupnames (depending on your auth plugin) + # and three keywords: "$all", "$anonymous", "$authenticated" + allow_access: $authenticated + + # allow 'admin' to publish packages + allow_publish: $all + + # if package is not available locally, proxy requests to 'npmjs' registry + proxy: npmjs + +# log settings +logs: + - {type: stdout, format: pretty, level: http} + #- {type: file, path: sinopia.log, level: info} + diff --git a/lib/config_def.yaml b/conf/full.yaml similarity index 98% rename from lib/config_def.yaml rename to conf/full.yaml index 53453c3ae..d6e19e417 100644 --- a/lib/config_def.yaml +++ b/conf/full.yaml @@ -7,7 +7,7 @@ storage: ./storage users: admin: # crypto.createHash('sha1').update(pass).digest('hex') - password: __PASSWORD__ + password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 web: # web interface is disabled by default in 0.x, will be enabled soon in 1.x diff --git a/lib/cli.js b/lib/cli.js index 9256f32ea..7470be1d6 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -65,10 +65,10 @@ try { if (x[0] == 'Y' || x[0] == 'y' || x === '') { rl.close() - var created_config = require('../lib/config_gen')() - config = YAML.safeLoad(created_config.yaml) + var created_config = fs.readFileSync(require.resolve('../conf/default.yaml'), 'utf8') + config = YAML.safeLoad(created_config) write_config_banner(created_config, config) - fs.writeFileSync(config_path, created_config.yaml) + fs.writeFileSync(config_path, created_config) afterConfigLoad() } else if (x[0] == 'N' || x[0] == 'n') { rl.close() @@ -137,8 +137,6 @@ function write_config_banner(def, config) { log(' $ npm set registry http://%s:%s/', hostport[0], hostport[1]) log(' $ npm set always-auth true') log(' $ npm adduser') - log(' Username: %s', def.user) - log(' Password: %s', def.pass) log('===========================================================') } diff --git a/lib/config.js b/lib/config.js index 4666b227d..fd73badd2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -26,7 +26,7 @@ function Config(config) { } // some weird shell scripts are valid yaml files parsed as string - assert.equal(typeof(config), 'object', 'CONFIG: self doesn\'t look like a valid config file') + assert.equal(typeof(config), 'object', 'CONFIG: it doesn\'t look like a valid config file') assert(self.storage, 'CONFIG: storage path not defined') self.localList = LocalList( diff --git a/lib/config_gen.js b/lib/config_gen.js deleted file mode 100644 index b01eed318..000000000 --- a/lib/config_gen.js +++ /dev/null @@ -1,19 +0,0 @@ -var Crypto = require('crypto') -var fs = require('fs') - -module.exports = function create_config() { - var pass = Crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, '') - var pass_digest = Crypto.createHash('sha1').update(pass).digest('hex') - - /*eslint no-sync:0*/ - var config = fs.readFileSync(require.resolve('./config_def.yaml'), 'utf8') - - config = config.replace('__PASSWORD__', pass_digest) - - return { - yaml: config, - user: 'admin', - pass: pass, - } -} -