Permalink
Browse files

[fix] simplify configs

  • Loading branch information...
1 parent 36aa1ee commit f2902da550ec340ef1f4212d6be4091242655eef @bmeck committed Mar 21, 2013
Showing with 73 additions and 52 deletions.
  1. +15 −15 integrations/checkout.js
  2. +8 −1 integrations/run.js
  3. +25 −24 integrations/security.js
  4. +13 −3 lib/nam.js
  5. +12 −9 package.json
View
@@ -49,21 +49,21 @@ exports.tasks = {
else if (proto === 'directory') {
repo.directory = path.resolve(scaffold.directories.rootdir, path.join(parts.host, parts.path));
}
- scaffold.config.set('task:checkout:repository', repo);
+ options.config.set('repository', repo);
}
async.waterfall([
- mkdirs.bind(scaffold),
- download.bind(scaffold),
- prepare.bind(scaffold)
+ mkdirs.bind(scaffold, options),
+ download.bind(scaffold, options),
+ prepare.bind(scaffold, options)
], next);
}
}
-function mkdirs(cb) {
+function mkdirs(options, cb) {
var scaffold = this;
var directories = scaffold.directories;
var tomake = Object.keys(directories);
- if (!scaffold.config.get('task:checkout:empty')) {
+ if (!options.config.get('empty')) {
tomake = tomake.filter(function (dirname) {
return dirname !== 'moduledir';
});
@@ -72,14 +72,14 @@ function mkdirs(cb) {
mkdirp(path.resolve(directories.rootdir, directories[dir]), next);
}, cb);
}
-function download(cb) {
+function download(options, cb) {
var scaffold = this;
- if (scaffold.config.get('task:checkout:empty')) {
- cb(null);
- return;
- }
- var config = scaffold.config.get('task:checkout:repository');
+ var config = options.config.get('repository');
if (!config) {
+ if (options.config.get('empty')) {
+ cb(null);
+ return;
+ }
cb(new Error('Cannot checkout unknown repository'));
return;
}
@@ -88,10 +88,10 @@ function download(cb) {
repository.destination = config.type !== 'tar-stream' ? scaffold.directories.moduledir : scaffold.directories.packagedir;
checkout(repository, cb);
}
-function prepare(cb) {
+function prepare(options, cb) {
var scaffold = this;
async.series([
- scaffold.perform.bind(scaffold, 'task.checkout.scaffold', scaffold),
- scaffold.perform.bind(scaffold, 'task.checkout.lockdown')
+ scaffold.perform.bind(scaffold, 'task.checkout.scaffold', scaffold, options),
+ scaffold.perform.bind(scaffold, 'task.checkout.lockdown', scaffold, options)
], cb);
}
View
@@ -6,6 +6,7 @@ var path = require('path');
exports.name = 'run';
exports.tasks = {
run: function (args, options, cb) {
+ console.log(arguments)
var scaffold = this;
var cmd = args.shift();
var env = options.env || {};
@@ -41,6 +42,12 @@ exports.tasks = {
env.TMP = resolveDir(scaffold.directories.tmpdir);
}
options.env = env;
- scaffold.run(cmd, args, options, cb);
+ scaffold.perform('task.run.lockdown', cmd, args, options, function (err, cmd, args, options) {
+ if (err) {
+ cb(err);
+ return;
+ }
+ scaffold.run(cmd, args, options, cb);
+ });
}
}
View
@@ -1,6 +1,7 @@
//
// Some basic security for user / group permissions (not sufficient on Windows)
//
+var uidNumber = require('uid-number');
exports.name = 'security';
exports.schema = {
properties: {
@@ -26,16 +27,16 @@ exports.actions = {
//
// When locking down, change fs attributes appropriately
//
- 'task.checkout.lockdown': function secure(scaffold, next) {
+ 'task.checkout.lockdown': function secure(scaffold, options, next) {
//
// for consistency only
//
- if (scaffold.config.get('task:security:insecure')) {
- next(null, scaffold);
+ if (options.config.get('insecure')) {
+ next(null, scaffold, options);
return;
}
- var uid = scaffold.config.get('task:security:uid') || process.getuid();
- var gid = scaffold.config.get('task:security:gid') || process.getgid();
+ var uid = options.config.get('uid') || process.getuid();
+ var gid = options.config.get('gid') || process.getgid();
uidNumber(uid, gid, function (err, uid, gid) {
if (err) {
next(err);
@@ -49,34 +50,34 @@ exports.actions = {
//
// When programs run, run as the proper user/group
//
- run: function secure(cmd, args, options, next) {
- var security = options.integrations && options.integrations.security;
- if (!security) {
- next(null, cmd, args, options);
- return;
- }
- var insecure = security.insecure || scaffold.config.get('task:security:insecure');
+ 'task.run.lockdown': function secure(cmd, args, options, next) {
+ var insecure = options.config.get('insecure');
if (insecure) {
next(null, cmd, args, options);
return;
}
- if (security.precomputed) {
- options.uid = security.uid;
- options.gid = security.gid;
- next(null, cmd, args, options);
- return;
- }
var scaffold = this;
- var uid = security.uid || scaffold.config.get('task:security:uid');
- var gid = security.gid || scaffold.config.get('task:security:gid');
- uidNumber(uid, gid, function (err, uid, gid) {
+ var uid = options.config.get('uid');
+ var gid = options.config.get('gid');
+ function setids(err, uid, gid) {
if (err) {
next(err);
return;
}
- options.uid = uid;
- options.gid = gid;
+ if (uid) options.uid = '#'+uid;
+ if (gid) options.gid = '#'+gid;
next(null, cmd, args, options);
- });
+ }
+ if (uid) {
+ if (gid) {
+ uidNumber(uid, gid, setids);
+ }
+ else {
+ uidNumber(uid, setids);
+ }
+ }
+ else {
+ setids(null, void 0, void 0);
+ }
}
}
View
@@ -42,7 +42,7 @@ NodeApplicationManager.prototype.integrate = function (spec) {
});
var actions = spec.actions;
if (actions) Object.keys(actions).forEach(function (key) {
- scaffold.before(key, spec[key]);
+ scaffold.before(key, actions[key]);
});
}
NodeApplicationManager.prototype.task = function (name, args, options, cb) {
@@ -60,10 +60,20 @@ NodeApplicationManager.prototype.task = function (name, args, options, cb) {
var handler = scaffold.tasks[name];
if (handler) {
var argv = optimist.parse(args);
+ //
+ // local options
+ //
+ options.config = new nconf.Provider().defaults(scaffold.config.get(['task',name].join(':'))).use('memory');
Object.keys(argv).forEach(function (key) {
- if (key !== '_') scaffold.config.merge(['task',name,key].join(':'), argv[key]);
+ if (key !== '_') options.config.set(key, argv[key]);
+ });
+ scaffold.perform(['task',name].join('.'), scaffold, argv._, options, function (err, scaffold, argv, options) {
+ if (err) {
+ cb(err);
+ return;
+ }
+ handler.call(scaffold, argv, options, cb);
});
- handler.call(scaffold, argv._, options, cb);
}
else {
cb(new Error('Unknown script: '+name));
View
@@ -1,10 +1,13 @@
{
- "name": "nam",
- "version": "0.0.0",
- "repository": {
- "type": "git",
- "url": "git@github.com:bmeck/nam"
- },
- "main": "lib/nam.js",
- "license": "MIT"
-}
+ "name": "nam",
+ "version": "0.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:bmeck/nam"
+ },
+ "main": "lib/nam.js",
+ "license": "MIT",
+ "dependencies": {
+ "uid-number": "0.0.3"
+ }
+}

0 comments on commit f2902da

Please sign in to comment.