|
|
@ -1,8 +1,9 @@ |
|
|
|
#!/usr/bin/env node |
|
|
|
import chalk from 'chalk'; |
|
|
|
import table from 'text-table'; |
|
|
|
import minimist from 'minimist'; |
|
|
|
import * as cfg from '../lib/cfg'; |
|
|
|
import { error } from '../lib/error'; |
|
|
|
import { handleError, error } from '../lib/error'; |
|
|
|
import NowSecrets from '../lib/secrets'; |
|
|
|
import ms from 'ms'; |
|
|
|
|
|
|
@ -80,11 +81,7 @@ if (argv.help || !subcommand) { |
|
|
|
try { |
|
|
|
await run(token); |
|
|
|
} catch (err) { |
|
|
|
if (err.userError) { |
|
|
|
error(err.message); |
|
|
|
} else { |
|
|
|
error(`Unknown error: ${err.stack}`); |
|
|
|
} |
|
|
|
handleError(err); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
}) |
|
|
@ -104,11 +101,19 @@ async function run (token) { |
|
|
|
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}`); |
|
|
|
return exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const list = []; |
|
|
|
|
|
|
|
const list = await secrets.ls(); |
|
|
|
const elapsed = ms(new Date() - start); |
|
|
|
console.log(`> ${list.length} secrets found ${chalk.gray(`[${elapsed}]`)}`); |
|
|
|
const cur = Date.now(); |
|
|
|
const out = table(list.map((secret) => { |
|
|
|
return [ |
|
|
|
'', |
|
|
|
secret.uid, |
|
|
|
chalk.bold(secret.name), |
|
|
|
chalk.gray(ms(cur - new Date(secret.created)) + ' ago') |
|
|
|
]; |
|
|
|
}), { align: ['l', 'r', 'l'], hsep: ' '.repeat(3) }); |
|
|
|
if (out) console.log('\n' + out + '\n'); |
|
|
|
return secrets.close(); |
|
|
|
} |
|
|
|
|
|
|
@ -117,7 +122,7 @@ async function run (token) { |
|
|
|
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rm <id | name>`')}`); |
|
|
|
return exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const secret = await secrets.rm(args[0]); |
|
|
|
const elapsed = ms(new Date() - start); |
|
|
|
console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`); |
|
|
|
return secrets.close(); |
|
|
@ -128,12 +133,7 @@ async function run (token) { |
|
|
|
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rename <old-name> <new-name>`')}`); |
|
|
|
return exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const secret = { |
|
|
|
name: 'my-password', |
|
|
|
uid: 'sec_iuh32u23bfigf2gu' |
|
|
|
}; |
|
|
|
|
|
|
|
const secret = await secrets.patch(args[0], args[1]); |
|
|
|
const elapsed = ms(new Date() - start); |
|
|
|
console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} renamed to ${chalk.bold('my-secret-name')} ${chalk.gray(`[${elapsed}]`)}`); |
|
|
|
return secrets.close(); |
|
|
@ -149,23 +149,16 @@ async function run (token) { |
|
|
|
} |
|
|
|
return exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
const [name, value_] = args; |
|
|
|
|
|
|
|
let value; |
|
|
|
if (argv.base64) { |
|
|
|
value = { base64: value_ }; |
|
|
|
} else { |
|
|
|
value = value_; |
|
|
|
} |
|
|
|
|
|
|
|
const secret = { |
|
|
|
name: 'my-password', |
|
|
|
uid: 'sec_iuh32u23bfigf2gu' |
|
|
|
}; |
|
|
|
|
|
|
|
const secret = await secrets.add(name, value); |
|
|
|
const elapsed = ms(new Date() - start); |
|
|
|
console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} added ${chalk.gray(`[${elapsed}]`)}`); |
|
|
|
console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(name)} ${chalk.gray(`(${secret.uid})`)} added ${chalk.gray(`[${elapsed}]`)}`); |
|
|
|
return secrets.close(); |
|
|
|
} |
|
|
|
|
|
|
@ -173,3 +166,8 @@ async function run (token) { |
|
|
|
help(); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
process.on('uncaughtException', (err) => { |
|
|
|
handleError(err); |
|
|
|
exit(1); |
|
|
|
}); |
|
|
|