From c705152966a97fa91833f3d772381cd5194b92af Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sat, 8 Jun 2013 05:16:28 +0400 Subject: [PATCH] name change + a lot of work... --- bin/{npmrepod => sinopia} | 31 +++++++- config.example.yaml | 20 +++++ lib/config.js | 121 +++++++++++++++++++++++++++++++ lib/drivers/mongodb.js | 0 lib/index.js | 121 +++++++++++++++++-------------- lib/middleware.js | 78 ++++++++++++++++++++ lib/proxy.js | 2 +- lib/st-local.js | 107 +++++++++++++++++++++++++++ lib/st-proxy.js | 31 ++++++++ lib/storage.js | 149 ++++++++++++++++++-------------------- package.yaml | 6 +- 11 files changed, 529 insertions(+), 137 deletions(-) rename bin/{npmrepod => sinopia} (56%) create mode 100644 config.example.yaml create mode 100644 lib/config.js delete mode 100644 lib/drivers/mongodb.js create mode 100644 lib/middleware.js create mode 100644 lib/st-local.js create mode 100644 lib/st-proxy.js diff --git a/bin/npmrepod b/bin/sinopia similarity index 56% rename from bin/npmrepod rename to bin/sinopia index ee2abdcd3..43eb764c0 100755 --- a/bin/npmrepod +++ b/bin/sinopia @@ -5,6 +5,7 @@ var yaml = require('js-yaml'); var commander = require('commander'); var pkg = yaml.safeLoad(fs.readFileSync('../package.yaml', 'utf8')); var server = require('../lib/index'); +var crypto = require('crypto'); commander .option('-l, --listen <[host:]port>', 'host:port number to listen on (default: localhost:4873)', '4873') @@ -15,10 +16,38 @@ commander .version(pkg.version) .parse(process.argv); +if (commander.config) { + var config = yaml.safeLoad(fs.readFileSync(commander.config, 'utf8')); +} else { + var pass = crypto.randomBytes(8).toString('base64').replace(/[=+\/]/g, ''); + var config = { + users: { + admin: { + password: crypto.createHash('sha1').update(pass).digest('hex') + }, + }, + uplinks: { + npmjs: { + url: 'https://registry.npmjs.org/' + }, + }, + packages: { + '/.*/': { + publish: ['admin'], + access: ['all'], + proxy: ['npmjs'], + } + } + } + console.log('starting with default config, use user: "admin", pass: "%s" to authenticate', pass); +} + +if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version; + var hostport = commander.listen.split(':'); if (hostport.length < 2) { hostport = [undefined, hostport[0]]; } -server({}).listen(hostport[1], hostport[0]); +server(config).listen(hostport[1], hostport[0]); console.log('Server is listening on http://%s:%s/', hostport[0] || 'localhost', hostport[1]); diff --git a/config.example.yaml b/config.example.yaml new file mode 100644 index 000000000..2a76cf190 --- /dev/null +++ b/config.example.yaml @@ -0,0 +1,20 @@ + +users: + user1: + # require('crypto').createHash('sha1').update('test').digest('hex') + password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 + +uplinks: + npmjs: + url: https://registry.npmjs.org/ + +GGusers: &GG user1 user2 + +packages: + /^local-/: + #wg1: read write + #npmjs: read + access: *GG + publish: *GG + proxy: npmjs owner all + diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 000000000..9a961b308 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,121 @@ +var assert = require('assert'); +var crypto = require('crypto'); + +// [[a, [b, c]], d] -> [a, b, c, d] +function flatten(array) { + var result = []; + for (var i=0; i= 3.2.5' commander: '>= 1.1.1' js-yaml: '>= 2.0.5' cookies: '>= 0.3.6' + async: '*' + semver: '*' preferGlobal: true license: BSD