bwx 0.2.1 → 0.2.2
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/README.md +1 -0
- package/package.json +1 -1
- package/src/cli/commands/config.ts +72 -2
- package/src/cli/program.ts +1 -1
- package/src/config/store.ts +4 -0
- package/src/index.ts +22 -0
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ bwx doctor
|
|
|
70
70
|
|---------|-------------|
|
|
71
71
|
| `bwx config email [addr]` | Set account email |
|
|
72
72
|
| `bwx config master-password` | Store master password in Keychain |
|
|
73
|
+
| `bwx config list` / `bwx cfg ls` | Show config path + redacted content |
|
|
73
74
|
|
|
74
75
|
### Global flags
|
|
75
76
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
import { getGlobalOpts } from "../program.ts";
|
|
3
|
-
import { emitSuccess } from "../io.ts";
|
|
3
|
+
import { emitData, emitSuccess } from "../io.ts";
|
|
4
4
|
import { CliError, ExitCode } from "../errors.ts";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getConfigPath,
|
|
7
|
+
loadConfig,
|
|
8
|
+
saveConfig,
|
|
9
|
+
} from "../../config/store.ts";
|
|
6
10
|
|
|
7
11
|
export function registerConfig(program: Command): void {
|
|
8
12
|
const configCmd = program
|
|
@@ -90,6 +94,72 @@ export function registerConfig(program: Command): void {
|
|
|
90
94
|
|
|
91
95
|
emitSuccess("Master password saved to Keychain", opts);
|
|
92
96
|
});
|
|
97
|
+
|
|
98
|
+
configCmd
|
|
99
|
+
.command("list").alias("ls")
|
|
100
|
+
.description("Show config file path and redacted content")
|
|
101
|
+
.action(async function (this: Command) {
|
|
102
|
+
const opts = getGlobalOpts(this);
|
|
103
|
+
const path = getConfigPath();
|
|
104
|
+
const file = Bun.file(path);
|
|
105
|
+
const exists = await file.exists();
|
|
106
|
+
let config: unknown = null;
|
|
107
|
+
|
|
108
|
+
if (exists) {
|
|
109
|
+
try {
|
|
110
|
+
config = JSON.parse(await file.text());
|
|
111
|
+
} catch (err) {
|
|
112
|
+
throw new CliError(
|
|
113
|
+
`Config file is not valid JSON: ${
|
|
114
|
+
err instanceof Error ? err.message : String(err)
|
|
115
|
+
}`,
|
|
116
|
+
ExitCode.Config,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
emitData(
|
|
122
|
+
{
|
|
123
|
+
path,
|
|
124
|
+
exists,
|
|
125
|
+
config: redactSensitive(config),
|
|
126
|
+
},
|
|
127
|
+
opts,
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const SENSITIVE_KEY_RE = [
|
|
133
|
+
/pass(word)?/i,
|
|
134
|
+
/secret/i,
|
|
135
|
+
/token/i,
|
|
136
|
+
/api[-_]?key/i,
|
|
137
|
+
/private/i,
|
|
138
|
+
/credential/i,
|
|
139
|
+
/session/i,
|
|
140
|
+
/auth/i,
|
|
141
|
+
/totp/i,
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
function redactSensitive(value: unknown): unknown {
|
|
145
|
+
if (!value || typeof value !== "object") {
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
return value.map((item) => redactSensitive(item));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const out: Record<string, unknown> = {};
|
|
154
|
+
for (const [key, current] of Object.entries(value)) {
|
|
155
|
+
out[key] = isSensitiveKey(key) ? "***REDACTED***" : redactSensitive(current);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function isSensitiveKey(key: string): boolean {
|
|
162
|
+
return SENSITIVE_KEY_RE.some((pattern) => pattern.test(key));
|
|
93
163
|
}
|
|
94
164
|
|
|
95
165
|
async function readLine(): Promise<string> {
|
package/src/cli/program.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function buildProgram(): Command {
|
|
|
19
19
|
program
|
|
20
20
|
.name("bwx")
|
|
21
21
|
.description("Bitwarden Extended CLI")
|
|
22
|
-
.version("0.2.
|
|
22
|
+
.version("0.2.2")
|
|
23
23
|
.option("--json", "JSON output")
|
|
24
24
|
.option("--plain", "Plain parseable output")
|
|
25
25
|
.option("-q, --quiet", "Suppress log output")
|
package/src/config/store.ts
CHANGED
|
@@ -4,6 +4,10 @@ const CONFIG_DIR =
|
|
|
4
4
|
process.env.XDG_CONFIG_HOME ?? `${process.env.HOME}/.config`;
|
|
5
5
|
const CONFIG_PATH = `${CONFIG_DIR}/bwx/config.json`;
|
|
6
6
|
|
|
7
|
+
export function getConfigPath(): string {
|
|
8
|
+
return CONFIG_PATH;
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export async function loadConfig(): Promise<Config> {
|
|
8
12
|
try {
|
|
9
13
|
const text = await Bun.file(CONFIG_PATH).text();
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,12 @@ import type { GlobalOptions } from "./cli/types.ts";
|
|
|
7
7
|
export async function main(argv: string[]): Promise<void> {
|
|
8
8
|
const program = buildProgram();
|
|
9
9
|
|
|
10
|
+
// Bare invocation should show top-level help.
|
|
11
|
+
if (argv.length <= 2) {
|
|
12
|
+
program.outputHelp();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
// Parse global opts early for error formatting
|
|
11
17
|
let opts: GlobalOptions = {};
|
|
12
18
|
try {
|
|
@@ -26,6 +32,22 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
26
32
|
await program.parseAsync(argv);
|
|
27
33
|
} catch (err) {
|
|
28
34
|
if (err instanceof CommanderError) {
|
|
35
|
+
if (err.code === "commander.help") {
|
|
36
|
+
const helpArgv = [...argv, "--help"];
|
|
37
|
+
try {
|
|
38
|
+
await program.parseAsync(helpArgv);
|
|
39
|
+
} catch (helpErr) {
|
|
40
|
+
if (
|
|
41
|
+
!(
|
|
42
|
+
helpErr instanceof CommanderError &&
|
|
43
|
+
helpErr.code === "commander.helpDisplayed"
|
|
44
|
+
)
|
|
45
|
+
) {
|
|
46
|
+
throw helpErr;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
process.exit(err.exitCode);
|
|
50
|
+
}
|
|
29
51
|
if (err.exitCode === 0) process.exit(0); // --help, --version
|
|
30
52
|
// Commander prefixes messages with "error: " — strip it
|
|
31
53
|
const msg = err.message.replace(/^error:\s*/i, "");
|