Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 115 lines (110 sloc) 3.043 kB
#!/usr/bin/env node
var util = require('util'),
argv = require('optimist').argv,
cliff = require('cliff'),
gpgstore = require('../lib/gpgstore');
var help = [
'usage: gpgstore [command] [options]',
'',
'commands:',
' new [master file] - splits up a master JSON file into encrypted tiers.',
' add [new tier file] - encrypts the provided file and adds it as the lowest tier.',
' list - list all locally available tiers.',
' list keys - list GnuPG keys currently available.',
' view [file] - decrypts the provided file and prints it for the user.',
' use [tier] - opens a tier for viewing and editing.',
' rm [tier] - deletes the given tier.',
' rm all - deletes all tiers.',
' help - show this help and exit.',
''
].join('\n');
gpgstore.start();
if (argv.h || argv.help) {
return util.puts(help);
}
switch (argv._[0]) {
case 'new':
gpgstore.newMaster(argv._[1], function (err, master) {
if (err) {
console.log(err.stack.red);
process.exit(1);
}
gpgstore.makeTiers(master, function (err) {
if (err) { console.log(err.stack.red); }
});
});
break;
case 'add':
if (!argv._[1]) {
console.log('Missing argument: which file?');
process.exit(1);
}
gpgstore.add(argv._[1], function (err) {
if (err) { console.log(err.stack.red); }
});
break;
case 'view':
gpgstore.view(argv._[1], function (err, result) {
if (err) {
console.log(err.stack.red);
process.exit(1);
}
console.log(cliff.inspect(result));
});
break;
case 'list':
if (argv._[1] === 'keys') {
gpgstore.listKeys();
}
else {
gpgstore.listTiers( function (err, tiers) {
if (err) {
util.puts(err);
process.exit(1);
}
util.puts(tiers.sort().join('\n').replace(/\.gpg/g, ''));
});
}
break;
case 'rm':
if (!argv._[1]) {
console.log('Missing argument: which tier?');
process.exit(1);
}
else if (argv._[1] === 'all') {
gpgstore.removeAll(function (err) {
if (err) { console.log(err.stack.red); }
});
}
else {
gpgstore.removeTier(argv._[1], function (err, result) {
if (err) {
console.log(err.stack.red);
process.exit(1);
}
console.log(argv._[1], 'has been successfully removed, and all tiers regenerated.'.cyan);
});
}
break;
case 'use':
if (!argv._[1]) {
console.log('Missing argument: which tier?');
process.exit(1);
}
(/^\w+\.gpg$/).test(argv._[1]) ? argv._[1] : argv._[1] += '.gpg';
gpgstore.view(argv._[1], function (err, result) {
if (err) {
console.log(err.stack.red);
process.exit(1);
}
gpgstore.use(result, 0, function (err) {
if (err) {
console.log(err.stack.red);
process.exit(1);
}
});
});
break;
default:
return util.puts(help);
}
Jump to Line
Something went wrong with that request. Please try again.