vaulter-cli 2.3.3 → 2.3.5
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 +1 -1
- package/src/commands/help.js +40 -18
- package/src/commands/ls.js +5 -3
- package/src/commands/sign-in.js +87 -93
- package/src/commands/view.js +6 -2
- package/src/lib/ui.js +3 -3
package/package.json
CHANGED
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/sign-in.js
CHANGED
|
@@ -1,107 +1,101 @@
|
|
|
1
|
-
import http from 'http';
|
|
2
1
|
import crypto from 'crypto';
|
|
3
2
|
import open from 'open';
|
|
4
3
|
import ora from 'ora';
|
|
5
|
-
import { saveToken
|
|
4
|
+
import { saveToken } from '../lib/auth.js';
|
|
6
5
|
import { getApiUrl } from '../lib/config.js';
|
|
7
6
|
import { printLogo } from '../assets/logo.js';
|
|
8
7
|
import { success, error, info } from '../lib/ui.js';
|
|
9
8
|
|
|
9
|
+
const POLL_INTERVAL_MS = 2000;
|
|
10
|
+
const TIMEOUT_MS = 120000;
|
|
11
|
+
|
|
12
|
+
function isSSH() {
|
|
13
|
+
return !!(process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION);
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export async function signIn() {
|
|
17
|
+
const requestId = crypto.randomBytes(16).toString('hex');
|
|
11
18
|
const state = crypto.randomBytes(16).toString('hex');
|
|
19
|
+
const apiUrl = getApiUrl();
|
|
20
|
+
|
|
21
|
+
// Register pending auth request on backend
|
|
22
|
+
const registerRes = await fetch(`${apiUrl}/api/cli/auth-request`, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: { 'Content-Type': 'application/json' },
|
|
25
|
+
body: JSON.stringify({ request_id: requestId, state }),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!registerRes.ok) {
|
|
29
|
+
const data = await registerRes.json().catch(() => ({}));
|
|
30
|
+
error(`Failed to start authentication: ${data.error || registerRes.status}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const authUrl = `${apiUrl}/cli-auth?request_id=${requestId}&state=${state}`;
|
|
35
|
+
|
|
36
|
+
console.log('');
|
|
37
|
+
if (isSSH()) {
|
|
38
|
+
info('Open this URL in your browser to authenticate:');
|
|
39
|
+
console.log(` ${authUrl}`);
|
|
40
|
+
} else {
|
|
41
|
+
info('Opening browser for authentication...');
|
|
42
|
+
info(`If the browser doesn't open, visit:`);
|
|
43
|
+
console.log(` ${authUrl}`);
|
|
44
|
+
open(authUrl);
|
|
45
|
+
}
|
|
46
|
+
console.log('');
|
|
47
|
+
|
|
48
|
+
const spinner = ora({
|
|
49
|
+
text: 'Waiting for browser authorization...',
|
|
50
|
+
color: 'magenta',
|
|
51
|
+
}).start();
|
|
12
52
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (token) {
|
|
41
|
-
saveToken(token);
|
|
42
|
-
|
|
43
|
-
// Verify the token works
|
|
44
|
-
try {
|
|
45
|
-
const verifyRes = await fetch(`${getApiUrl()}/api/keys`, {
|
|
46
|
-
headers: { 'Authorization': `Bearer ${token}` },
|
|
47
|
-
});
|
|
48
|
-
if (!verifyRes.ok) throw new Error('Verification failed');
|
|
49
|
-
} catch {
|
|
50
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
51
|
-
res.end('<html><body style="background:#0f172a;color:#ef4444;font-family:sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0"><h2>Token verification failed. Please try again.</h2></body></html>');
|
|
52
|
-
spinner.fail('Token verification failed.');
|
|
53
|
-
server.close();
|
|
54
|
-
resolve();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
59
|
-
res.end('<html><body style="background:#0f172a;color:#a78bfa;font-family:sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0"><div style="text-align:center"><h2 style="color:#22c55e">Authenticated!</h2><p>You can close this tab and return to your terminal.</p></div></body></html>');
|
|
60
|
-
spinner.succeed('Authenticated successfully!');
|
|
61
|
-
await printLogo();
|
|
62
|
-
success('You are now signed in to Vaulter.');
|
|
63
|
-
info('Run `vaulter ls` to list your keys.');
|
|
64
|
-
server.close();
|
|
65
|
-
resolve();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
70
|
-
res.end('<html><body style="background:#0f172a;color:#ef4444;font-family:sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0"><h2>Missing token. Please try again.</h2></body></html>');
|
|
71
|
-
spinner.fail('No token received.');
|
|
72
|
-
server.close();
|
|
73
|
-
resolve();
|
|
53
|
+
const deadline = Date.now() + TIMEOUT_MS;
|
|
54
|
+
|
|
55
|
+
while (Date.now() < deadline) {
|
|
56
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
57
|
+
|
|
58
|
+
let pollData;
|
|
59
|
+
try {
|
|
60
|
+
const pollRes = await fetch(`${apiUrl}/api/cli/auth-request/${requestId}`);
|
|
61
|
+
pollData = await pollRes.json();
|
|
62
|
+
} catch {
|
|
63
|
+
// Network hiccup — keep polling
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (pollData.status === 'completed') {
|
|
68
|
+
const token = pollData.token;
|
|
69
|
+
|
|
70
|
+
// Verify the token works
|
|
71
|
+
try {
|
|
72
|
+
const verifyRes = await fetch(`${apiUrl}/api/keys`, {
|
|
73
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
74
|
+
});
|
|
75
|
+
if (!verifyRes.ok) throw new Error('Verification failed');
|
|
76
|
+
} catch {
|
|
77
|
+
spinner.fail('Token verification failed. Please try again.');
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
color: 'magenta',
|
|
98
|
-
}).start();
|
|
99
|
-
|
|
100
|
-
// 120 second timeout
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
spinner.fail('Authorization timed out (120s). Please try again.');
|
|
103
|
-
server.close();
|
|
104
|
-
resolve();
|
|
105
|
-
}, 120000);
|
|
106
|
-
});
|
|
81
|
+
saveToken(token);
|
|
82
|
+
spinner.succeed('Authenticated successfully!');
|
|
83
|
+
await printLogo();
|
|
84
|
+
success('You are now signed in to Vaulter.');
|
|
85
|
+
info('Run `vaulter ls` to list your keys.');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (pollData.status === 'denied') {
|
|
90
|
+
spinner.fail('Authorization denied.');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (pollData.status === 'expired') {
|
|
95
|
+
spinner.fail('Authorization request expired. Please try again.');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
spinner.fail('Authorization timed out (120s). Please try again.');
|
|
107
101
|
}
|
package/src/commands/view.js
CHANGED
|
@@ -3,7 +3,7 @@ import ora from 'ora';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import clipboardy from 'clipboardy';
|
|
5
5
|
import { apiFetch } from '../lib/api.js';
|
|
6
|
-
import { purple, dim, error, warn,
|
|
6
|
+
import { purple, dim, error, warn, success, tip } from '../lib/ui.js';
|
|
7
7
|
|
|
8
8
|
const DIVIDER_WIDTH = 60;
|
|
9
9
|
const divider = chalk.dim('─'.repeat(DIVIDER_WIDTH));
|
|
@@ -96,6 +96,9 @@ export async function viewKeys(names) {
|
|
|
96
96
|
|
|
97
97
|
decryptSpinner.stop();
|
|
98
98
|
|
|
99
|
+
const failed = rows.filter(r => r.value === null);
|
|
100
|
+
failed.forEach(r => warn(`Failed to decrypt "${r.name}"`));
|
|
101
|
+
|
|
99
102
|
// Display cards
|
|
100
103
|
console.log('');
|
|
101
104
|
console.log(` ${chalk.dim('━'.repeat(DIVIDER_WIDTH))}`);
|
|
@@ -143,7 +146,7 @@ export async function viewKeys(names) {
|
|
|
143
146
|
} else {
|
|
144
147
|
try {
|
|
145
148
|
await clipboardy.write(toCopy.value);
|
|
146
|
-
|
|
149
|
+
success(`${chalk.white(toCopy.name)} copied to clipboard.`);
|
|
147
150
|
console.log('');
|
|
148
151
|
} catch {
|
|
149
152
|
warn('Could not access clipboard. Copy the value manually from above.');
|
|
@@ -152,5 +155,6 @@ export async function viewKeys(names) {
|
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
|
|
158
|
+
tip('Run `clear` to wipe your terminal and protect these values.');
|
|
155
159
|
console.log('');
|
|
156
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) {
|