vaulter-cli 2.3.2 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/commands/help.js +40 -18
- package/src/commands/ls.js +5 -3
- package/src/commands/view.js +72 -24
- package/src/lib/ui.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vaulter-cli",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "CLI tool for Vaulter - Secure API Key Manager",
|
|
5
5
|
"author": "faris-sait",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"chalk": "^5.3.0",
|
|
33
33
|
"cli-table3": "^0.6.3",
|
|
34
|
+
"clipboardy": "^4.0.0",
|
|
34
35
|
"commander": "^12.0.0",
|
|
35
36
|
"inquirer": "^9.2.0",
|
|
36
37
|
"open": "^10.0.0",
|
package/src/commands/help.js
CHANGED
|
@@ -12,26 +12,48 @@ export async function showHelp() {
|
|
|
12
12
|
console.log(status);
|
|
13
13
|
console.log('');
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
const sections = [
|
|
16
|
+
{
|
|
17
|
+
label: 'SETUP',
|
|
18
|
+
commands: [
|
|
19
|
+
{ name: 'init', desc: 'Initialize current directory as a Vaulter project' },
|
|
20
|
+
{ name: 'sign-in', desc: 'Authenticate with Vaulter via browser' },
|
|
21
|
+
{ name: 'sign-out', desc: 'Sign out and clear saved credentials' },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'VAULT KEYS',
|
|
26
|
+
commands: [
|
|
27
|
+
{ name: 'ls', desc: 'List all API keys in your vault' },
|
|
28
|
+
{ name: 'add <name>', desc: 'Add a new API key to your vault' },
|
|
29
|
+
{ name: 'remove <name-or-id>', desc: 'Remove an API key from your vault' },
|
|
30
|
+
{ name: 'view [key_names...]', desc: 'Decrypt and display keys in your terminal' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: 'FILES',
|
|
35
|
+
commands: [
|
|
36
|
+
{ name: 'make [file]', desc: 'Generate a .env file from your vault keys' },
|
|
37
|
+
{ name: 'save [file]', desc: 'Upload a local .env file to your vault' },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'MORE',
|
|
42
|
+
commands: [
|
|
43
|
+
{ name: 'web-app', desc: 'Open the Vaulter web app in your browser' },
|
|
44
|
+
{ name: 'help', desc: 'Show this help message' },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
30
47
|
];
|
|
31
48
|
|
|
32
|
-
for (const
|
|
33
|
-
|
|
34
|
-
console.log(
|
|
49
|
+
for (const section of sections) {
|
|
50
|
+
console.log(purple.bold(' ' + section.label));
|
|
51
|
+
console.log('');
|
|
52
|
+
for (const cmd of section.commands) {
|
|
53
|
+
const padded = cmd.name.padEnd(22);
|
|
54
|
+
console.log(` ${white.bold(padded)} ${dim(cmd.desc)}`);
|
|
55
|
+
}
|
|
56
|
+
console.log('');
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
console.log('');
|
package/src/commands/ls.js
CHANGED
|
@@ -43,21 +43,23 @@ export async function listKeys() {
|
|
|
43
43
|
for (const key of keys) {
|
|
44
44
|
const tags = (key.tags || []).join(', ') || dim('none');
|
|
45
45
|
const created = new Date(key.created_at).toLocaleDateString();
|
|
46
|
-
const
|
|
46
|
+
const usageCount = key.usage_count || 0;
|
|
47
|
+
const usage = usageCount > 0 ? dim(`${usageCount}x`) : dim('—');
|
|
47
48
|
|
|
48
49
|
table.push([
|
|
49
50
|
chalk.white(key.name),
|
|
50
51
|
chalk.hex('#a78bfa')(key.masked_key),
|
|
51
52
|
dim(tags),
|
|
52
53
|
dim(created),
|
|
53
|
-
|
|
54
|
+
usage,
|
|
54
55
|
]);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
console.log('');
|
|
58
59
|
console.log(table.toString());
|
|
59
60
|
console.log('');
|
|
60
|
-
|
|
61
|
+
const label = keys.length === 1 ? '1 key in your vault' : `${keys.length} keys in your vault`;
|
|
62
|
+
console.log(dim(` ${label}`));
|
|
61
63
|
tip('Run `vaulter make .env` to export keys to a .env file.');
|
|
62
64
|
console.log('');
|
|
63
65
|
} catch (err) {
|
package/src/commands/view.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
import ora from 'ora';
|
|
3
|
-
import Table from 'cli-table3';
|
|
4
3
|
import chalk from 'chalk';
|
|
4
|
+
import clipboardy from 'clipboardy';
|
|
5
5
|
import { apiFetch } from '../lib/api.js';
|
|
6
|
-
import { purple, dim, error, warn } from '../lib/ui.js';
|
|
6
|
+
import { purple, dim, error, warn, success, tip } from '../lib/ui.js';
|
|
7
|
+
|
|
8
|
+
const DIVIDER_WIDTH = 60;
|
|
9
|
+
const divider = chalk.dim('─'.repeat(DIVIDER_WIDTH));
|
|
10
|
+
|
|
11
|
+
function printKeyCard(name, value, index, total) {
|
|
12
|
+
const label = purple.bold(name);
|
|
13
|
+
const counter = chalk.dim(`[${index + 1}/${total}]`);
|
|
14
|
+
console.log(` ${label} ${counter}`);
|
|
15
|
+
console.log(` ${divider}`);
|
|
16
|
+
console.log(` ${chalk.hex('#a78bfa')(value)}`);
|
|
17
|
+
console.log('');
|
|
18
|
+
}
|
|
7
19
|
|
|
8
20
|
export async function viewKeys(names) {
|
|
9
21
|
const spinner = ora({ text: 'Fetching vault keys...', color: 'magenta' }).start();
|
|
@@ -30,7 +42,6 @@ export async function viewKeys(names) {
|
|
|
30
42
|
let selected;
|
|
31
43
|
|
|
32
44
|
if (names.length === 0) {
|
|
33
|
-
// Interactive checkbox selection
|
|
34
45
|
console.log('');
|
|
35
46
|
const { selectedKeys } = await inquirer.prompt([
|
|
36
47
|
{
|
|
@@ -54,7 +65,6 @@ export async function viewKeys(names) {
|
|
|
54
65
|
|
|
55
66
|
selected = selectedKeys;
|
|
56
67
|
} else {
|
|
57
|
-
// Match provided names case-insensitively
|
|
58
68
|
selected = [];
|
|
59
69
|
for (const name of names) {
|
|
60
70
|
const match = keys.find((k) => k.name.toLowerCase() === name.toLowerCase());
|
|
@@ -78,35 +88,73 @@ export async function viewKeys(names) {
|
|
|
78
88
|
for (const key of selected) {
|
|
79
89
|
try {
|
|
80
90
|
const data = await apiFetch(`/api/keys/${key.id}?decrypt=true`);
|
|
81
|
-
rows.push(
|
|
91
|
+
rows.push({ name: key.name, value: data.decrypted_key });
|
|
82
92
|
} catch (err) {
|
|
83
|
-
rows.push(
|
|
93
|
+
rows.push({ name: key.name, value: null });
|
|
84
94
|
}
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
decryptSpinner.stop();
|
|
88
98
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
table.push(row);
|
|
99
|
+
const failed = rows.filter(r => r.value === null);
|
|
100
|
+
failed.forEach(r => warn(`Failed to decrypt "${r.name}"`));
|
|
101
|
+
|
|
102
|
+
// Display cards
|
|
103
|
+
console.log('');
|
|
104
|
+
console.log(` ${chalk.dim('━'.repeat(DIVIDER_WIDTH))}`);
|
|
105
|
+
console.log('');
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < rows.length; i++) {
|
|
108
|
+
const { name, value } = rows[i];
|
|
109
|
+
if (value === null) {
|
|
110
|
+
printKeyCard(name, chalk.dim('(failed to decrypt)'), i, rows.length);
|
|
111
|
+
} else {
|
|
112
|
+
printKeyCard(name, value, i, rows.length);
|
|
113
|
+
}
|
|
105
114
|
}
|
|
106
115
|
|
|
116
|
+
console.log(` ${chalk.dim('━'.repeat(DIVIDER_WIDTH))}`);
|
|
107
117
|
console.log('');
|
|
108
|
-
console.log(
|
|
118
|
+
console.log(` ${chalk.yellow('⚠')} ${chalk.yellow.bold('These values are sensitive.')} ${chalk.dim('Clear your terminal when done.')}`);
|
|
119
|
+
console.log(` ${chalk.dim('💡 Tip: Select a key below to copy it to your clipboard.')}`);
|
|
109
120
|
console.log('');
|
|
110
|
-
|
|
121
|
+
|
|
122
|
+
// Clipboard copy loop
|
|
123
|
+
const copyableRows = rows.filter((r) => r.value !== null);
|
|
124
|
+
if (copyableRows.length === 0) return;
|
|
125
|
+
|
|
126
|
+
let copying = true;
|
|
127
|
+
while (copying) {
|
|
128
|
+
const { toCopy } = await inquirer.prompt([
|
|
129
|
+
{
|
|
130
|
+
type: 'list',
|
|
131
|
+
name: 'toCopy',
|
|
132
|
+
message: purple('Copy a key to clipboard:'),
|
|
133
|
+
choices: [
|
|
134
|
+
...copyableRows.map((r) => ({
|
|
135
|
+
name: `${chalk.white(r.name)} ${chalk.dim(r.value.slice(0, 24) + (r.value.length > 24 ? '...' : ''))}`,
|
|
136
|
+
value: r,
|
|
137
|
+
})),
|
|
138
|
+
new inquirer.Separator(),
|
|
139
|
+
{ name: chalk.dim('Done'), value: null },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
if (toCopy === null) {
|
|
145
|
+
copying = false;
|
|
146
|
+
} else {
|
|
147
|
+
try {
|
|
148
|
+
await clipboardy.write(toCopy.value);
|
|
149
|
+
success(`${chalk.white(toCopy.name)} copied to clipboard.`);
|
|
150
|
+
console.log('');
|
|
151
|
+
} catch {
|
|
152
|
+
warn('Could not access clipboard. Copy the value manually from above.');
|
|
153
|
+
console.log('');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
tip('Run `clear` to wipe your terminal and protect these values.');
|
|
111
159
|
console.log('');
|
|
112
160
|
}
|
package/src/lib/ui.js
CHANGED
|
@@ -11,11 +11,11 @@ export const yellow = chalk.yellow;
|
|
|
11
11
|
export const cyan = chalk.cyan;
|
|
12
12
|
|
|
13
13
|
export function success(msg) {
|
|
14
|
-
console.log(green(' ' + msg));
|
|
14
|
+
console.log(green(' ✔ ' + msg));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function error(msg) {
|
|
18
|
-
console.log(red(' ' + msg));
|
|
18
|
+
console.log(red(' ✗ ' + msg));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function info(msg) {
|
|
@@ -23,7 +23,7 @@ export function info(msg) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function warn(msg) {
|
|
26
|
-
console.log(yellow(' ' + msg));
|
|
26
|
+
console.log(yellow(' ⚠ ' + msg));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function tip(msg) {
|