@indigoai-us/hq-cli 5.7.0 → 5.8.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/dist/commands/_patterns.d.ts +2 -0
- package/dist/commands/_patterns.js +9 -2
- package/dist/commands/files.d.ts +3 -0
- package/dist/commands/files.js +224 -0
- package/dist/index.js +6 -3
- package/dist/utils/cognito-session.js +3 -4
- package/package.json +1 -1
- package/src/commands/_patterns.ts +8 -0
- package/src/commands/files.ts +249 -0
- package/src/index.ts +5 -1
- package/src/utils/cognito-session.ts +1 -2
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0d9c591b-d54a-52b4-85c3-32a9030953ca")}catch(e){}}();
|
|
3
3
|
export const SECRET_NAME_PATTERN = /^[A-Z][A-Z0-9_]*(?:\/[A-Z][A-Z0-9_]+)*$/;
|
|
4
4
|
export const GROUP_ID_PATTERN = /^grp_[A-Za-z0-9_-]+$/;
|
|
5
|
+
export const EMAIL_PATTERN = /^[^\s]+@[^\s]+$/;
|
|
6
|
+
export function normalizeFilePrefix(prefix) {
|
|
7
|
+
if (prefix.endsWith("/")) {
|
|
8
|
+
return prefix + "*";
|
|
9
|
+
}
|
|
10
|
+
return prefix;
|
|
11
|
+
}
|
|
5
12
|
//# sourceMappingURL=_patterns.js.map
|
|
6
|
-
//# debugId=
|
|
13
|
+
//# debugId=0d9c591b-d54a-52b4-85c3-32a9030953ca
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3d902660-a8aa-5671-ab69-21ffc0143c60")}catch(e){}}();
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
5
|
+
import { vaultApiFetch, getCompanyUid } from "./secrets.js";
|
|
6
|
+
import { GROUP_ID_PATTERN, EMAIL_PATTERN, normalizeFilePrefix } from "./_patterns.js";
|
|
7
|
+
export function registerFilesCommand(program) {
|
|
8
|
+
const files = program
|
|
9
|
+
.command("files")
|
|
10
|
+
.description("Manage file access controls in HQ vault")
|
|
11
|
+
.option("--company <slug>", "Company slug (resolves to companyUid)");
|
|
12
|
+
files
|
|
13
|
+
.command("share <prefix>")
|
|
14
|
+
.description("Share a file prefix with a person or group")
|
|
15
|
+
.requiredOption("--with <principal>", "Email address or group id to share with")
|
|
16
|
+
.requiredOption("--permission <level>", "Permission level: read | write")
|
|
17
|
+
.action(async (prefix, opts) => {
|
|
18
|
+
try {
|
|
19
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
20
|
+
if (!["read", "write"].includes(opts.permission)) {
|
|
21
|
+
console.error(chalk.red(`Invalid permission '${opts.permission}': must be one of read, write`));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const principal = opts.with;
|
|
25
|
+
const isEmail = EMAIL_PATTERN.test(principal);
|
|
26
|
+
const isGroup = GROUP_ID_PATTERN.test(principal);
|
|
27
|
+
if (!isEmail && !isGroup) {
|
|
28
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a group id matching grp_<alphanumeric>`));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
const granteeType = isEmail ? "email" : "group";
|
|
32
|
+
const granteeId = isEmail ? principal.trim().toLowerCase() : principal;
|
|
33
|
+
const token = await ensureCognitoToken();
|
|
34
|
+
const companySlug = files.opts().company;
|
|
35
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
36
|
+
let res = await vaultApiFetch({
|
|
37
|
+
token,
|
|
38
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl/grant`,
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: { prefix: canonicalPrefix, granteeType, granteeId, permission: opts.permission },
|
|
41
|
+
});
|
|
42
|
+
// No ACL row exists yet for this prefix. Auto-create one with this
|
|
43
|
+
// grant as its first entry, then report success — saves the caller
|
|
44
|
+
// from needing a separate "create" step.
|
|
45
|
+
let autoCreated = false;
|
|
46
|
+
if (res.status === 404) {
|
|
47
|
+
res = await vaultApiFetch({
|
|
48
|
+
token,
|
|
49
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl`,
|
|
50
|
+
method: "POST",
|
|
51
|
+
body: {
|
|
52
|
+
prefix: canonicalPrefix,
|
|
53
|
+
entries: [{ granteeType, granteeId, permission: opts.permission }],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
autoCreated = res.ok;
|
|
57
|
+
}
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
const body = await res.json().catch(() => ({}));
|
|
60
|
+
if (res.status === 401) {
|
|
61
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
62
|
+
}
|
|
63
|
+
else if (res.status === 403) {
|
|
64
|
+
console.error(chalk.red("Not authorized to share this file prefix"));
|
|
65
|
+
}
|
|
66
|
+
else if (res.status === 404) {
|
|
67
|
+
console.error(chalk.red("ACL record not found — the prefix may not have an ACL yet"));
|
|
68
|
+
}
|
|
69
|
+
else if (res.status === 409) {
|
|
70
|
+
console.error(chalk.red("Concurrent modification — please retry"));
|
|
71
|
+
}
|
|
72
|
+
else if (res.status >= 500) {
|
|
73
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
77
|
+
}
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
const data = await res.json();
|
|
81
|
+
const printedPrefix = data.acl?.path ?? data.acl?.prefix ?? canonicalPrefix;
|
|
82
|
+
const verb = autoCreated ? "Created ACL and granted" : "Granted";
|
|
83
|
+
console.log(chalk.green(`${verb} ${opts.permission} on ${printedPrefix} to ${granteeId}`));
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
files
|
|
91
|
+
.command("unshare <prefix>")
|
|
92
|
+
.description("Remove a file access grant")
|
|
93
|
+
.requiredOption("--with <principal>", "Email address or group id to remove")
|
|
94
|
+
.action(async (prefix, opts) => {
|
|
95
|
+
try {
|
|
96
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
97
|
+
const principal = opts.with;
|
|
98
|
+
const isEmail = EMAIL_PATTERN.test(principal);
|
|
99
|
+
const isGroup = GROUP_ID_PATTERN.test(principal);
|
|
100
|
+
if (!isEmail && !isGroup) {
|
|
101
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a group id matching grp_<alphanumeric>`));
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
const granteeType = isEmail ? "email" : "group";
|
|
105
|
+
const granteeId = isEmail ? principal.trim().toLowerCase() : principal;
|
|
106
|
+
const token = await ensureCognitoToken();
|
|
107
|
+
const companySlug = files.opts().company;
|
|
108
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
109
|
+
const res = await vaultApiFetch({
|
|
110
|
+
token,
|
|
111
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl/revoke`,
|
|
112
|
+
method: "POST",
|
|
113
|
+
body: { prefix: canonicalPrefix, granteeType, granteeId },
|
|
114
|
+
});
|
|
115
|
+
if (!res.ok) {
|
|
116
|
+
const body = await res.json().catch(() => ({}));
|
|
117
|
+
if (res.status === 401) {
|
|
118
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
119
|
+
}
|
|
120
|
+
else if (res.status === 403) {
|
|
121
|
+
console.error(chalk.red("Not authorized to modify this file prefix's ACL"));
|
|
122
|
+
}
|
|
123
|
+
else if (res.status === 404) {
|
|
124
|
+
console.log(chalk.green(`Grant already absent for '${canonicalPrefix}' / ${granteeId}`));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
else if (res.status >= 500) {
|
|
128
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
132
|
+
}
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
console.log(chalk.green(`Removed grant for ${granteeId} on '${canonicalPrefix}'`));
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
files
|
|
143
|
+
.command("acl <prefix>")
|
|
144
|
+
.description("Show the ACL (access control list) for a file prefix")
|
|
145
|
+
.action(async (prefix) => {
|
|
146
|
+
try {
|
|
147
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
148
|
+
const token = await ensureCognitoToken();
|
|
149
|
+
const companySlug = files.opts().company;
|
|
150
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
151
|
+
const res = await vaultApiFetch({
|
|
152
|
+
token,
|
|
153
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl`,
|
|
154
|
+
query: { prefix: canonicalPrefix },
|
|
155
|
+
});
|
|
156
|
+
if (!res.ok) {
|
|
157
|
+
const body = await res.json().catch(() => ({}));
|
|
158
|
+
if (res.status === 401) {
|
|
159
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
160
|
+
}
|
|
161
|
+
else if (res.status === 403) {
|
|
162
|
+
console.error(chalk.red("Not authorized to view this file prefix's ACL"));
|
|
163
|
+
}
|
|
164
|
+
else if (res.status === 404) {
|
|
165
|
+
console.error(chalk.red(`No ACL record exists for '${canonicalPrefix}'`));
|
|
166
|
+
}
|
|
167
|
+
else if (res.status >= 500) {
|
|
168
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
172
|
+
}
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
const data = await res.json();
|
|
176
|
+
const acl = data.acl;
|
|
177
|
+
const aclStatus = acl.open ? "open" : "restricted";
|
|
178
|
+
const aclPrefix = acl.path ?? acl.prefix ?? canonicalPrefix;
|
|
179
|
+
console.log(chalk.green(`ACL for ${aclPrefix} (${aclStatus})`));
|
|
180
|
+
console.log(`Creator: ${acl.creatorUid}`);
|
|
181
|
+
if (acl.effectivePermission) {
|
|
182
|
+
console.log(`Your effective permission: ${acl.effectivePermission}`);
|
|
183
|
+
}
|
|
184
|
+
if (acl.entries.length === 0) {
|
|
185
|
+
if (acl.open) {
|
|
186
|
+
console.log(chalk.gray("Open ACL — all active members have read access."));
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log(chalk.gray("No explicit grants — only creator has access."));
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
console.log("Entries:");
|
|
194
|
+
const TYPE_W = Math.max(4, ...acl.entries.map((e) => e.granteeType.length));
|
|
195
|
+
const GRANTEE_W = Math.max(7, ...acl.entries.map((e) => e.granteeId.length));
|
|
196
|
+
const PERM_W = Math.max(10, ...acl.entries.map((e) => e.permission.length));
|
|
197
|
+
const BY_W = Math.max(10, ...acl.entries.map((e) => e.grantedBy.length));
|
|
198
|
+
const tableHeader = [
|
|
199
|
+
"TYPE".padEnd(TYPE_W),
|
|
200
|
+
"GRANTEE".padEnd(GRANTEE_W),
|
|
201
|
+
"PERMISSION".padEnd(PERM_W),
|
|
202
|
+
"GRANTED_BY".padEnd(BY_W),
|
|
203
|
+
"GRANTED_AT",
|
|
204
|
+
].join(" ");
|
|
205
|
+
console.log(chalk.bold(tableHeader));
|
|
206
|
+
for (const e of acl.entries) {
|
|
207
|
+
const grantedAt = e.grantedAt.slice(0, 10);
|
|
208
|
+
console.log([
|
|
209
|
+
e.granteeType.padEnd(TYPE_W),
|
|
210
|
+
e.granteeId.padEnd(GRANTEE_W),
|
|
211
|
+
e.permission.padEnd(PERM_W),
|
|
212
|
+
e.grantedBy.padEnd(BY_W),
|
|
213
|
+
grantedAt,
|
|
214
|
+
].join(" "));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=files.js.map
|
|
224
|
+
//# debugId=3d902660-a8aa-5671-ab69-21ffc0143c60
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* HQ CLI - Module management, package management, and cloud sync for HQ
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="79222b07-0f20-582f-962f-6bc13b8c1c88")}catch(e){}}();
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
import { initSentry, Sentry } from "./sentry.js";
|
|
9
9
|
import { registerAddCommand } from "./commands/add.js";
|
|
@@ -24,12 +24,13 @@ import { registerTeamSyncCommand } from "./commands/team-sync.js";
|
|
|
24
24
|
import { registerAuthCommands } from "./commands/auth.js";
|
|
25
25
|
import { registerSecretsCommand } from "./commands/secrets.js";
|
|
26
26
|
import { registerGroupsCommand } from "./commands/groups.js";
|
|
27
|
+
import { registerFilesCommand } from "./commands/files.js";
|
|
27
28
|
initSentry();
|
|
28
29
|
const program = new Command();
|
|
29
30
|
program
|
|
30
31
|
.name("hq")
|
|
31
32
|
.description("HQ management CLI — modules, packages, and cloud sync")
|
|
32
|
-
.version("5.
|
|
33
|
+
.version("5.8.4");
|
|
33
34
|
// Module management subcommand group
|
|
34
35
|
const modulesCmd = program
|
|
35
36
|
.command("modules")
|
|
@@ -73,6 +74,8 @@ registerAuthCommands(program);
|
|
|
73
74
|
registerSecretsCommand(program);
|
|
74
75
|
// Groups management (subcommand group — hq groups create|delete|add|remove|list|members)
|
|
75
76
|
registerGroupsCommand(program);
|
|
77
|
+
// Files ACL management (subcommand group — hq files share|unshare|acl)
|
|
78
|
+
registerFilesCommand(program);
|
|
76
79
|
// Onboarding (top-level — Cognito + vault-service provisioning)
|
|
77
80
|
registerOnboardCommand(program);
|
|
78
81
|
(async () => {
|
|
@@ -88,4 +91,4 @@ registerOnboardCommand(program);
|
|
|
88
91
|
}
|
|
89
92
|
})();
|
|
90
93
|
//# sourceMappingURL=index.js.map
|
|
91
|
-
//# debugId=
|
|
94
|
+
//# debugId=79222b07-0f20-582f-962f-6bc13b8c1c88
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* HQ_VAULT_API_URL — vault-service API Gateway URL
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
22
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="71d8f748-f249-50df-aa1f-eae381ea608d")}catch(e){}}();
|
|
23
23
|
import * as os from "os";
|
|
24
24
|
import * as path from "path";
|
|
25
25
|
import chalk from "chalk";
|
|
@@ -40,8 +40,7 @@ export const DEFAULT_COGNITO = {
|
|
|
40
40
|
? process.env.HQ_COGNITO_IDENTITY_PROVIDER || undefined
|
|
41
41
|
: "Google",
|
|
42
42
|
};
|
|
43
|
-
export const DEFAULT_VAULT_API_URL = process.env.HQ_VAULT_API_URL ??
|
|
44
|
-
"https://4nfy67z28h.execute-api.us-east-1.amazonaws.com";
|
|
43
|
+
export const DEFAULT_VAULT_API_URL = process.env.HQ_VAULT_API_URL ?? "https://hqapi.getindigo.ai";
|
|
45
44
|
export const DEFAULT_HQ_ROOT = path.join(os.homedir(), "hq");
|
|
46
45
|
/**
|
|
47
46
|
* Return a non-expired Cognito access token, refreshing or browser-logging-in
|
|
@@ -109,4 +108,4 @@ export async function refreshCachedSession() {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
//# sourceMappingURL=cognito-session.js.map
|
|
112
|
-
//# debugId=
|
|
111
|
+
//# debugId=71d8f748-f249-50df-aa1f-eae381ea608d
|
package/package.json
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export const SECRET_NAME_PATTERN = /^[A-Z][A-Z0-9_]*(?:\/[A-Z][A-Z0-9_]+)*$/;
|
|
2
2
|
export const GROUP_ID_PATTERN = /^grp_[A-Za-z0-9_-]+$/;
|
|
3
|
+
export const EMAIL_PATTERN = /^[^\s]+@[^\s]+$/;
|
|
4
|
+
|
|
5
|
+
export function normalizeFilePrefix(prefix: string): string {
|
|
6
|
+
if (prefix.endsWith("/")) {
|
|
7
|
+
return prefix + "*";
|
|
8
|
+
}
|
|
9
|
+
return prefix;
|
|
10
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
4
|
+
import { vaultApiFetch, getCompanyUid } from "./secrets.js";
|
|
5
|
+
import { GROUP_ID_PATTERN, EMAIL_PATTERN, normalizeFilePrefix } from "./_patterns.js";
|
|
6
|
+
|
|
7
|
+
export function registerFilesCommand(program: Command): void {
|
|
8
|
+
const files = program
|
|
9
|
+
.command("files")
|
|
10
|
+
.description("Manage file access controls in HQ vault")
|
|
11
|
+
.option("--company <slug>", "Company slug (resolves to companyUid)");
|
|
12
|
+
|
|
13
|
+
files
|
|
14
|
+
.command("share <prefix>")
|
|
15
|
+
.description("Share a file prefix with a person or group")
|
|
16
|
+
.requiredOption("--with <principal>", "Email address or group id to share with")
|
|
17
|
+
.requiredOption("--permission <level>", "Permission level: read | write")
|
|
18
|
+
.action(async (prefix: string, opts: { with: string; permission: string }) => {
|
|
19
|
+
try {
|
|
20
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
21
|
+
|
|
22
|
+
if (!["read", "write"].includes(opts.permission)) {
|
|
23
|
+
console.error(chalk.red(`Invalid permission '${opts.permission}': must be one of read, write`));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const principal = opts.with;
|
|
28
|
+
const isEmail = EMAIL_PATTERN.test(principal);
|
|
29
|
+
const isGroup = GROUP_ID_PATTERN.test(principal);
|
|
30
|
+
if (!isEmail && !isGroup) {
|
|
31
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a group id matching grp_<alphanumeric>`));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
const granteeType = isEmail ? "email" : "group";
|
|
35
|
+
const granteeId = isEmail ? principal.trim().toLowerCase() : principal;
|
|
36
|
+
|
|
37
|
+
const token = await ensureCognitoToken();
|
|
38
|
+
const companySlug = files.opts().company as string | undefined;
|
|
39
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
40
|
+
|
|
41
|
+
let res = await vaultApiFetch({
|
|
42
|
+
token,
|
|
43
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl/grant`,
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: { prefix: canonicalPrefix, granteeType, granteeId, permission: opts.permission },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// No ACL row exists yet for this prefix. Auto-create one with this
|
|
49
|
+
// grant as its first entry, then report success — saves the caller
|
|
50
|
+
// from needing a separate "create" step.
|
|
51
|
+
let autoCreated = false;
|
|
52
|
+
if (res.status === 404) {
|
|
53
|
+
res = await vaultApiFetch({
|
|
54
|
+
token,
|
|
55
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl`,
|
|
56
|
+
method: "POST",
|
|
57
|
+
body: {
|
|
58
|
+
prefix: canonicalPrefix,
|
|
59
|
+
entries: [{ granteeType, granteeId, permission: opts.permission }],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
autoCreated = res.ok;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!res.ok) {
|
|
66
|
+
const body = await res.json().catch(() => ({})) as Record<string, string>;
|
|
67
|
+
if (res.status === 401) {
|
|
68
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
69
|
+
} else if (res.status === 403) {
|
|
70
|
+
console.error(chalk.red("Not authorized to share this file prefix"));
|
|
71
|
+
} else if (res.status === 404) {
|
|
72
|
+
console.error(chalk.red("ACL record not found — the prefix may not have an ACL yet"));
|
|
73
|
+
} else if (res.status === 409) {
|
|
74
|
+
console.error(chalk.red("Concurrent modification — please retry"));
|
|
75
|
+
} else if (res.status >= 500) {
|
|
76
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
77
|
+
} else {
|
|
78
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
79
|
+
}
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const data = await res.json() as { acl?: { path?: string; prefix?: string } };
|
|
84
|
+
const printedPrefix = data.acl?.path ?? data.acl?.prefix ?? canonicalPrefix;
|
|
85
|
+
const verb = autoCreated ? "Created ACL and granted" : "Granted";
|
|
86
|
+
console.log(chalk.green(`${verb} ${opts.permission} on ${printedPrefix} to ${granteeId}`));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
files
|
|
94
|
+
.command("unshare <prefix>")
|
|
95
|
+
.description("Remove a file access grant")
|
|
96
|
+
.requiredOption("--with <principal>", "Email address or group id to remove")
|
|
97
|
+
.action(async (prefix: string, opts: { with: string }) => {
|
|
98
|
+
try {
|
|
99
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
100
|
+
|
|
101
|
+
const principal = opts.with;
|
|
102
|
+
const isEmail = EMAIL_PATTERN.test(principal);
|
|
103
|
+
const isGroup = GROUP_ID_PATTERN.test(principal);
|
|
104
|
+
if (!isEmail && !isGroup) {
|
|
105
|
+
console.error(chalk.red(`Invalid principal '${principal}': must be an email address or a group id matching grp_<alphanumeric>`));
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
const granteeType = isEmail ? "email" : "group";
|
|
109
|
+
const granteeId = isEmail ? principal.trim().toLowerCase() : principal;
|
|
110
|
+
|
|
111
|
+
const token = await ensureCognitoToken();
|
|
112
|
+
const companySlug = files.opts().company as string | undefined;
|
|
113
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
114
|
+
|
|
115
|
+
const res = await vaultApiFetch({
|
|
116
|
+
token,
|
|
117
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl/revoke`,
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: { prefix: canonicalPrefix, granteeType, granteeId },
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (!res.ok) {
|
|
123
|
+
const body = await res.json().catch(() => ({})) as Record<string, string>;
|
|
124
|
+
if (res.status === 401) {
|
|
125
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
126
|
+
} else if (res.status === 403) {
|
|
127
|
+
console.error(chalk.red("Not authorized to modify this file prefix's ACL"));
|
|
128
|
+
} else if (res.status === 404) {
|
|
129
|
+
console.log(chalk.green(`Grant already absent for '${canonicalPrefix}' / ${granteeId}`));
|
|
130
|
+
return;
|
|
131
|
+
} else if (res.status >= 500) {
|
|
132
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
133
|
+
} else {
|
|
134
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
135
|
+
}
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.log(chalk.green(`Removed grant for ${granteeId} on '${canonicalPrefix}'`));
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
files
|
|
147
|
+
.command("acl <prefix>")
|
|
148
|
+
.description("Show the ACL (access control list) for a file prefix")
|
|
149
|
+
.action(async (prefix: string) => {
|
|
150
|
+
try {
|
|
151
|
+
const canonicalPrefix = normalizeFilePrefix(prefix);
|
|
152
|
+
|
|
153
|
+
const token = await ensureCognitoToken();
|
|
154
|
+
const companySlug = files.opts().company as string | undefined;
|
|
155
|
+
const companyUid = await getCompanyUid(token, companySlug);
|
|
156
|
+
|
|
157
|
+
const res = await vaultApiFetch({
|
|
158
|
+
token,
|
|
159
|
+
path: `/files/${encodeURIComponent(companyUid)}/acl`,
|
|
160
|
+
query: { prefix: canonicalPrefix },
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
if (!res.ok) {
|
|
164
|
+
const body = await res.json().catch(() => ({})) as Record<string, string>;
|
|
165
|
+
if (res.status === 401) {
|
|
166
|
+
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
167
|
+
} else if (res.status === 403) {
|
|
168
|
+
console.error(chalk.red("Not authorized to view this file prefix's ACL"));
|
|
169
|
+
} else if (res.status === 404) {
|
|
170
|
+
console.error(chalk.red(`No ACL record exists for '${canonicalPrefix}'`));
|
|
171
|
+
} else if (res.status >= 500) {
|
|
172
|
+
console.error(chalk.red(`Server error: ${body.error ?? res.statusText}`));
|
|
173
|
+
} else {
|
|
174
|
+
console.error(chalk.red(body.message ?? body.error ?? "Invalid request"));
|
|
175
|
+
}
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const data = await res.json() as {
|
|
180
|
+
acl: {
|
|
181
|
+
itemType: string;
|
|
182
|
+
companyUid: string;
|
|
183
|
+
// Server returns `path` (the FileAcl field name); older builds
|
|
184
|
+
// used `prefix`. Read both so the CLI works against either.
|
|
185
|
+
path?: string;
|
|
186
|
+
prefix?: string;
|
|
187
|
+
creatorUid: string;
|
|
188
|
+
open?: boolean;
|
|
189
|
+
entries: Array<{
|
|
190
|
+
granteeType: string;
|
|
191
|
+
granteeId: string;
|
|
192
|
+
permission: string;
|
|
193
|
+
grantedBy: string;
|
|
194
|
+
grantedAt: string;
|
|
195
|
+
}>;
|
|
196
|
+
effectivePermission?: string | null;
|
|
197
|
+
createdAt: string;
|
|
198
|
+
updatedAt: string;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const acl = data.acl;
|
|
203
|
+
const aclStatus = acl.open ? "open" : "restricted";
|
|
204
|
+
const aclPrefix = acl.path ?? acl.prefix ?? canonicalPrefix;
|
|
205
|
+
|
|
206
|
+
console.log(chalk.green(`ACL for ${aclPrefix} (${aclStatus})`));
|
|
207
|
+
console.log(`Creator: ${acl.creatorUid}`);
|
|
208
|
+
if (acl.effectivePermission) {
|
|
209
|
+
console.log(`Your effective permission: ${acl.effectivePermission}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (acl.entries.length === 0) {
|
|
213
|
+
if (acl.open) {
|
|
214
|
+
console.log(chalk.gray("Open ACL — all active members have read access."));
|
|
215
|
+
} else {
|
|
216
|
+
console.log(chalk.gray("No explicit grants — only creator has access."));
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
console.log("Entries:");
|
|
222
|
+
const TYPE_W = Math.max(4, ...acl.entries.map((e) => e.granteeType.length));
|
|
223
|
+
const GRANTEE_W = Math.max(7, ...acl.entries.map((e) => e.granteeId.length));
|
|
224
|
+
const PERM_W = Math.max(10, ...acl.entries.map((e) => e.permission.length));
|
|
225
|
+
const BY_W = Math.max(10, ...acl.entries.map((e) => e.grantedBy.length));
|
|
226
|
+
const tableHeader = [
|
|
227
|
+
"TYPE".padEnd(TYPE_W),
|
|
228
|
+
"GRANTEE".padEnd(GRANTEE_W),
|
|
229
|
+
"PERMISSION".padEnd(PERM_W),
|
|
230
|
+
"GRANTED_BY".padEnd(BY_W),
|
|
231
|
+
"GRANTED_AT",
|
|
232
|
+
].join(" ");
|
|
233
|
+
console.log(chalk.bold(tableHeader));
|
|
234
|
+
for (const e of acl.entries) {
|
|
235
|
+
const grantedAt = e.grantedAt.slice(0, 10);
|
|
236
|
+
console.log([
|
|
237
|
+
e.granteeType.padEnd(TYPE_W),
|
|
238
|
+
e.granteeId.padEnd(GRANTEE_W),
|
|
239
|
+
e.permission.padEnd(PERM_W),
|
|
240
|
+
e.grantedBy.padEnd(BY_W),
|
|
241
|
+
grantedAt,
|
|
242
|
+
].join(" "));
|
|
243
|
+
}
|
|
244
|
+
} catch (err) {
|
|
245
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
246
|
+
process.exit(1);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { registerTeamSyncCommand } from "./commands/team-sync.js";
|
|
|
24
24
|
import { registerAuthCommands } from "./commands/auth.js";
|
|
25
25
|
import { registerSecretsCommand } from "./commands/secrets.js";
|
|
26
26
|
import { registerGroupsCommand } from "./commands/groups.js";
|
|
27
|
+
import { registerFilesCommand } from "./commands/files.js";
|
|
27
28
|
|
|
28
29
|
initSentry();
|
|
29
30
|
|
|
@@ -32,7 +33,7 @@ const program = new Command();
|
|
|
32
33
|
program
|
|
33
34
|
.name("hq")
|
|
34
35
|
.description("HQ management CLI — modules, packages, and cloud sync")
|
|
35
|
-
.version("5.
|
|
36
|
+
.version("5.8.4");
|
|
36
37
|
|
|
37
38
|
// Module management subcommand group
|
|
38
39
|
const modulesCmd = program
|
|
@@ -92,6 +93,9 @@ registerSecretsCommand(program);
|
|
|
92
93
|
// Groups management (subcommand group — hq groups create|delete|add|remove|list|members)
|
|
93
94
|
registerGroupsCommand(program);
|
|
94
95
|
|
|
96
|
+
// Files ACL management (subcommand group — hq files share|unshare|acl)
|
|
97
|
+
registerFilesCommand(program);
|
|
98
|
+
|
|
95
99
|
// Onboarding (top-level — Cognito + vault-service provisioning)
|
|
96
100
|
registerOnboardCommand(program);
|
|
97
101
|
|
|
@@ -50,8 +50,7 @@ export const DEFAULT_COGNITO: CognitoAuthConfig = {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export const DEFAULT_VAULT_API_URL =
|
|
53
|
-
process.env.HQ_VAULT_API_URL ??
|
|
54
|
-
"https://4nfy67z28h.execute-api.us-east-1.amazonaws.com";
|
|
53
|
+
process.env.HQ_VAULT_API_URL ?? "https://hqapi.getindigo.ai";
|
|
55
54
|
|
|
56
55
|
export const DEFAULT_HQ_ROOT = path.join(os.homedir(), "hq");
|
|
57
56
|
|