@stigmer/cli 3.41.1-dev.20261014105239.g2cb3baa8ca8c → 3.41.1-dev.20261014134545.g492e758eaf83
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/commands/access-history/index.d.ts.map +1 -1
- package/commands/access-history/index.js +11 -6
- package/commands/access-history/index.js.map +1 -1
- package/package.json +7 -7
- package/resources/access-history.d.ts +19 -5
- package/resources/access-history.d.ts.map +1 -1
- package/resources/access-history.js +46 -14
- package/resources/access-history.js.map +1 -1
- package/src/commands/access-history/index.ts +20 -8
- package/src/resources/access-history.ts +57 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/access-history/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/access-history/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsD5D"}
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
//
|
|
12
12
|
// `export` is for a security team's tools: each line is one entry's proto
|
|
13
13
|
// JSON, and `--after` with the last `sequence` a tool holds asks for exactly
|
|
14
|
-
// what came since, which no entry can slip past.
|
|
14
|
+
// what came since, which no entry can slip past. When the server's retention
|
|
15
|
+
// removed entries after that one, a note says which on stderr, so stdout
|
|
16
|
+
// stays JSON Lines. The table `list` prints is followed by how long the
|
|
17
|
+
// server keeps the history.
|
|
15
18
|
//
|
|
16
19
|
// Thin handlers: resolve credentials and org, delegate to
|
|
17
20
|
// resources/access-history, render. Heavy modules are lazy-imported so
|
|
@@ -42,18 +45,18 @@ export function registerAccessHistory(program) {
|
|
|
42
45
|
import("../../output/index.js"),
|
|
43
46
|
import("@stigmer/protos/ai/stigmer/iam/iampolicy/v1/io_pb"),
|
|
44
47
|
]);
|
|
45
|
-
const entries = await resources.listAccessHistory(session.client, session.org, limit);
|
|
48
|
+
const { entries, retentionDays } = await resources.listAccessHistory(session.client, session.org, limit);
|
|
46
49
|
if (format === "json") {
|
|
47
50
|
process.stdout.write(output.renderProtoListJson(AccessHistoryEntrySchema, entries));
|
|
48
51
|
}
|
|
49
52
|
else if (format === "yaml") {
|
|
50
53
|
process.stdout.write(output.renderProtoListYaml(AccessHistoryEntrySchema, entries));
|
|
51
54
|
}
|
|
52
|
-
else if (entries.length === 0) {
|
|
53
|
-
process.stdout.write(output.renderEmpty("access changes"));
|
|
54
|
-
}
|
|
55
55
|
else {
|
|
56
|
-
process.stdout.write(
|
|
56
|
+
process.stdout.write(entries.length === 0
|
|
57
|
+
? output.renderEmpty("access changes")
|
|
58
|
+
: output.renderTable(resources.ACCESS_HISTORY_TABLE_HEADERS, resources.accessHistoryRows(entries)));
|
|
59
|
+
process.stdout.write(resources.retentionLine(retentionDays));
|
|
57
60
|
}
|
|
58
61
|
});
|
|
59
62
|
addReadFlags(listCmd);
|
|
@@ -67,6 +70,8 @@ export function registerAccessHistory(program) {
|
|
|
67
70
|
const session = await openSession(command);
|
|
68
71
|
await resources.exportAccessHistoryLines(session.client, session.org, after, (line) => {
|
|
69
72
|
process.stdout.write(line);
|
|
73
|
+
}, (note) => {
|
|
74
|
+
process.stderr.write(note);
|
|
70
75
|
});
|
|
71
76
|
});
|
|
72
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/access-history/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6BAA6B;AAC7B,EAAE;AACF,iFAAiF;AACjF,6EAA6E;AAC7E,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources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,EAAE,CAAC;IAChC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,MAAM,mBAAmB,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;IAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/cli",
|
|
3
|
-
"version": "3.41.1-dev.
|
|
3
|
+
"version": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
4
4
|
"description": "Stigmer command-line interface — manage agents, MCP servers, skills, and runs from the terminal",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"@connectrpc/connect": "^2.0.0",
|
|
35
35
|
"@connectrpc/connect-node": "^2.1.1",
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
37
|
-
"@stigmer/ink": "3.41.1-dev.
|
|
38
|
-
"@stigmer/mcp-server": "3.41.1-dev.
|
|
39
|
-
"@stigmer/plugin-package": "3.41.1-dev.
|
|
40
|
-
"@stigmer/protos": "3.41.1-dev.
|
|
41
|
-
"@stigmer/sdk": "3.41.1-dev.
|
|
42
|
-
"@stigmer/zip-structure": "3.41.1-dev.
|
|
37
|
+
"@stigmer/ink": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
38
|
+
"@stigmer/mcp-server": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
39
|
+
"@stigmer/plugin-package": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
40
|
+
"@stigmer/protos": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
41
|
+
"@stigmer/sdk": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
42
|
+
"@stigmer/zip-structure": "3.41.1-dev.20261014134545.g492e758eaf83",
|
|
43
43
|
"commander": "^12.1.0",
|
|
44
44
|
"fflate": "^0.8.3",
|
|
45
45
|
"ink": "^7.0.0",
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { type AccessHistoryEntry } from "@stigmer/protos/ai/stigmer/iam/iampolicy/v1/io_pb";
|
|
2
|
-
import { type Stigmer } from "@stigmer/sdk";
|
|
2
|
+
import { type RemovedAccessHistory, type Stigmer } from "@stigmer/sdk";
|
|
3
3
|
/** The client these helpers call. */
|
|
4
4
|
export type AccessHistoryClient = Pick<Stigmer, "iamPolicy">;
|
|
5
|
-
/**
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/** What `list` reads: the newest entries, and how long the server keeps the history. */
|
|
6
|
+
export interface AccessHistoryListing {
|
|
7
|
+
readonly entries: AccessHistoryEntry[];
|
|
8
|
+
/** Days the server keeps the history; 0 for good. */
|
|
9
|
+
readonly retentionDays: number;
|
|
10
|
+
}
|
|
11
|
+
/** The newest `limit` entries, newest first, with the first page's retention window. */
|
|
12
|
+
export declare function listAccessHistory(client: AccessHistoryClient, org: string, limit: number): Promise<AccessHistoryListing>;
|
|
13
|
+
/** The line `list` prints under its table: how long the server keeps the history. */
|
|
14
|
+
export declare function retentionLine(retentionDays: number): string;
|
|
15
|
+
/** The note `export` writes apart from the lines when the server removed entries after the caller's. */
|
|
16
|
+
export declare function removedNote(removed: RemovedAccessHistory): string;
|
|
17
|
+
/**
|
|
18
|
+
* Writes every entry after `after`, oldest first, one JSON line each, and
|
|
19
|
+
* a removed run, when there is one, as one note; answers how many lines it
|
|
20
|
+
* wrote.
|
|
21
|
+
*/
|
|
22
|
+
export declare function exportAccessHistoryLines(client: AccessHistoryClient, org: string, after: bigint, write: (line: string) => void, note: (line: string) => void): Promise<number>;
|
|
9
23
|
/** `--after`: the last sequence the caller holds, a whole number. */
|
|
10
24
|
export declare function parseAfterSequence(raw: string | undefined): bigint;
|
|
11
25
|
export declare const ACCESS_HISTORY_TABLE_HEADERS: readonly ["#", "WHEN", "CHANGE", "WHO", "ROLE", "ON", "BY", "WHY"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-history.d.ts","sourceRoot":"","sources":["../src/resources/access-history.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"access-history.d.ts","sourceRoot":"","sources":["../src/resources/access-history.ts"],"names":[],"mappings":"AAqBA,OAAO,EAGL,KAAK,kBAAkB,EAGxB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAItB,qCAAqC;AACrC,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAQ7D,wFAAwF;AACxF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,EAAE,CAAC;IACvC,qDAAqD;IACrD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,wFAAwF;AACxF,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,mBAAmB,EAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,oBAAoB,CAAC,CAc/B;AAED,qFAAqF;AACrF,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED,wGAAwG;AACxG,wBAAgB,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAUjE;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,mBAAmB,EAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC3B,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMlE;AAED,eAAO,MAAM,4BAA4B,oEAAqE,CAAC;AAE/G,+BAA+B;AAC/B,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,kBAAkB,EAAE,GAAG,MAAM,EAAE,EAAE,CAWpF"}
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
// an open-source server keeps none and says so, and that sentence reaches
|
|
8
8
|
// the user as the server wrote it.
|
|
9
9
|
//
|
|
10
|
-
// `list` reads newest first, up to `--limit` entries, following pages
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
10
|
+
// `list` reads newest first, up to `--limit` entries, following pages,
|
|
11
|
+
// and keeps the first page's word on retention: how many days the server
|
|
12
|
+
// keeps the history. `export` is the follow read: oldest first, after the
|
|
13
|
+
// last entry the caller holds (`--after`), every page, one entry per line,
|
|
14
|
+
// through `@stigmer/sdk`'s `exportAccessHistory`, so the console's download
|
|
15
|
+
// and this command write the same lines; when the server's retention
|
|
16
|
+
// removed entries after the caller's, the export says so once, apart from
|
|
17
|
+
// the lines.
|
|
15
18
|
import { create } from "@bufbuild/protobuf";
|
|
16
19
|
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
|
17
20
|
import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
|
|
@@ -23,18 +26,47 @@ import { readCursorPages } from "./cursor-pages.js";
|
|
|
23
26
|
const MAX_SEQUENCE = BigInt("9223372036854775807");
|
|
24
27
|
/** The most entries one page of the history returns. */
|
|
25
28
|
const MAX_PAGE_SIZE = 100;
|
|
26
|
-
/** The newest `limit` entries, newest first. */
|
|
29
|
+
/** The newest `limit` entries, newest first, with the first page's retention window. */
|
|
27
30
|
export async function listAccessHistory(client, org, limit) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
let first;
|
|
32
|
+
const entries = await readCursorPages(limit, async (pageSize, pageToken) => {
|
|
33
|
+
const page = await client.iamPolicy.listAccessHistory(create(ListAccessHistoryInputSchema, {
|
|
34
|
+
org,
|
|
35
|
+
pageSize: Math.min(pageSize, MAX_PAGE_SIZE),
|
|
36
|
+
pageToken,
|
|
37
|
+
}));
|
|
38
|
+
first ??= page;
|
|
39
|
+
return page;
|
|
40
|
+
});
|
|
41
|
+
return { entries, retentionDays: first?.retentionDays ?? 0 };
|
|
33
42
|
}
|
|
34
|
-
/**
|
|
35
|
-
export
|
|
43
|
+
/** The line `list` prints under its table: how long the server keeps the history. */
|
|
44
|
+
export function retentionLine(retentionDays) {
|
|
45
|
+
return retentionDays > 0
|
|
46
|
+
? `Entries older than ${retentionDays} ${retentionDays === 1 ? "day" : "days"} are removed.\n`
|
|
47
|
+
: "Kept for good.\n";
|
|
48
|
+
}
|
|
49
|
+
/** The note `export` writes apart from the lines when the server removed entries after the caller's. */
|
|
50
|
+
export function removedNote(removed) {
|
|
51
|
+
const run = removed.first === removed.last
|
|
52
|
+
? `entry ${removed.first} is`
|
|
53
|
+
: `entries ${removed.first} to ${removed.last} are`;
|
|
54
|
+
const why = removed.retentionDays > 0
|
|
55
|
+
? `this server removes entries older than ${removed.retentionDays} ${removed.retentionDays === 1 ? "day" : "days"}`
|
|
56
|
+
: "this server removed them";
|
|
57
|
+
return `${run} no longer kept: ${why}\n`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Writes every entry after `after`, oldest first, one JSON line each, and
|
|
61
|
+
* a removed run, when there is one, as one note; answers how many lines it
|
|
62
|
+
* wrote.
|
|
63
|
+
*/
|
|
64
|
+
export async function exportAccessHistoryLines(client, org, after, write, note) {
|
|
36
65
|
let written = 0;
|
|
37
|
-
|
|
66
|
+
const onRemoved = (removed) => {
|
|
67
|
+
note(removedNote(removed));
|
|
68
|
+
};
|
|
69
|
+
for await (const entry of exportAccessHistory(client.iamPolicy, org, { after, onRemoved })) {
|
|
38
70
|
write(`${accessHistoryJsonLine(entry)}\n`);
|
|
39
71
|
written += 1;
|
|
40
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-history.js","sourceRoot":"","sources":["../src/resources/access-history.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,0EAA0E;AAC1E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,
|
|
1
|
+
{"version":3,"file":"access-history.js","sourceRoot":"","sources":["../src/resources/access-history.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,4EAA4E;AAC5E,0EAA0E;AAC1E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,yEAAyE;AACzE,0EAA0E;AAC1E,2EAA2E;AAC3E,4EAA4E;AAC5E,qEAAqE;AACrE,0EAA0E;AAC1E,aAAa;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AACtH,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGjB,4BAA4B,GAC7B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,GAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,kEAAkE;AAClE,MAAM,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEnD,wDAAwD;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AI,EAAE,CAAC;AACpF,CAAC;AAED,SAAS,UAAU,CAAC,KAAyB;IAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;IAChC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC;IAC1D,IAAI,kBAAkB,CAAC,QAAQ,CAAC;QAAE,OAAO,GAAG,IAAI,IAAI,QAAQ,CAAC,EAAE,YAAY,CAAC;IAC5E,OAAO,GAAG,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,SAAS,OAAO,CAAC,KAAyB;IACxC,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3E,CAAC"}
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
//
|
|
12
12
|
// `export` is for a security team's tools: each line is one entry's proto
|
|
13
13
|
// JSON, and `--after` with the last `sequence` a tool holds asks for exactly
|
|
14
|
-
// what came since, which no entry can slip past.
|
|
14
|
+
// what came since, which no entry can slip past. When the server's retention
|
|
15
|
+
// removed entries after that one, a note says which on stderr, so stdout
|
|
16
|
+
// stays JSON Lines. The table `list` prints is followed by how long the
|
|
17
|
+
// server keeps the history.
|
|
15
18
|
//
|
|
16
19
|
// Thin handlers: resolve credentials and org, delegate to
|
|
17
20
|
// resources/access-history, render. Heavy modules are lazy-imported so
|
|
@@ -57,17 +60,18 @@ export function registerAccessHistory(program: Command): void {
|
|
|
57
60
|
import("../../output/index.js"),
|
|
58
61
|
import("@stigmer/protos/ai/stigmer/iam/iampolicy/v1/io_pb"),
|
|
59
62
|
]);
|
|
60
|
-
const entries = await resources.listAccessHistory(session.client, session.org, limit);
|
|
63
|
+
const { entries, retentionDays } = await resources.listAccessHistory(session.client, session.org, limit);
|
|
61
64
|
if (format === "json") {
|
|
62
65
|
process.stdout.write(output.renderProtoListJson(AccessHistoryEntrySchema, entries));
|
|
63
66
|
} else if (format === "yaml") {
|
|
64
67
|
process.stdout.write(output.renderProtoListYaml(AccessHistoryEntrySchema, entries));
|
|
65
|
-
} else if (entries.length === 0) {
|
|
66
|
-
process.stdout.write(output.renderEmpty("access changes"));
|
|
67
68
|
} else {
|
|
68
69
|
process.stdout.write(
|
|
69
|
-
|
|
70
|
+
entries.length === 0
|
|
71
|
+
? output.renderEmpty("access changes")
|
|
72
|
+
: output.renderTable(resources.ACCESS_HISTORY_TABLE_HEADERS, resources.accessHistoryRows(entries)),
|
|
70
73
|
);
|
|
74
|
+
process.stdout.write(resources.retentionLine(retentionDays));
|
|
71
75
|
}
|
|
72
76
|
});
|
|
73
77
|
addReadFlags(listCmd);
|
|
@@ -80,9 +84,17 @@ export function registerAccessHistory(program: Command): void {
|
|
|
80
84
|
const resources = await import("../../resources/access-history.js");
|
|
81
85
|
const after = resources.parseAfterSequence(options.after);
|
|
82
86
|
const session = await openSession(command);
|
|
83
|
-
await resources.exportAccessHistoryLines(
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
await resources.exportAccessHistoryLines(
|
|
88
|
+
session.client,
|
|
89
|
+
session.org,
|
|
90
|
+
after,
|
|
91
|
+
(line) => {
|
|
92
|
+
process.stdout.write(line);
|
|
93
|
+
},
|
|
94
|
+
(note) => {
|
|
95
|
+
process.stderr.write(note);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
86
98
|
});
|
|
87
99
|
}
|
|
88
100
|
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
// an open-source server keeps none and says so, and that sentence reaches
|
|
8
8
|
// the user as the server wrote it.
|
|
9
9
|
//
|
|
10
|
-
// `list` reads newest first, up to `--limit` entries, following pages
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
10
|
+
// `list` reads newest first, up to `--limit` entries, following pages,
|
|
11
|
+
// and keeps the first page's word on retention: how many days the server
|
|
12
|
+
// keeps the history. `export` is the follow read: oldest first, after the
|
|
13
|
+
// last entry the caller holds (`--after`), every page, one entry per line,
|
|
14
|
+
// through `@stigmer/sdk`'s `exportAccessHistory`, so the console's download
|
|
15
|
+
// and this command write the same lines; when the server's retention
|
|
16
|
+
// removed entries after the caller's, the export says so once, apart from
|
|
17
|
+
// the lines.
|
|
15
18
|
|
|
16
19
|
import { create } from "@bufbuild/protobuf";
|
|
17
20
|
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
|
@@ -20,12 +23,14 @@ import {
|
|
|
20
23
|
AccessChange,
|
|
21
24
|
AccessChangeCause,
|
|
22
25
|
type AccessHistoryEntry,
|
|
26
|
+
type AccessHistoryPage,
|
|
23
27
|
ListAccessHistoryInputSchema,
|
|
24
28
|
} from "@stigmer/protos/ai/stigmer/iam/iampolicy/v1/io_pb";
|
|
25
29
|
import {
|
|
26
30
|
accessHistoryJsonLine,
|
|
27
31
|
exportAccessHistory,
|
|
28
32
|
isDeletedReference,
|
|
33
|
+
type RemovedAccessHistory,
|
|
29
34
|
type Stigmer,
|
|
30
35
|
} from "@stigmer/sdk";
|
|
31
36
|
import { UsageError } from "../errors/usage-error.js";
|
|
@@ -40,32 +45,71 @@ const MAX_SEQUENCE = BigInt("9223372036854775807");
|
|
|
40
45
|
/** The most entries one page of the history returns. */
|
|
41
46
|
const MAX_PAGE_SIZE = 100;
|
|
42
47
|
|
|
43
|
-
/**
|
|
48
|
+
/** What `list` reads: the newest entries, and how long the server keeps the history. */
|
|
49
|
+
export interface AccessHistoryListing {
|
|
50
|
+
readonly entries: AccessHistoryEntry[];
|
|
51
|
+
/** Days the server keeps the history; 0 for good. */
|
|
52
|
+
readonly retentionDays: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The newest `limit` entries, newest first, with the first page's retention window. */
|
|
44
56
|
export async function listAccessHistory(
|
|
45
57
|
client: AccessHistoryClient,
|
|
46
58
|
org: string,
|
|
47
59
|
limit: number,
|
|
48
|
-
): Promise<
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
): Promise<AccessHistoryListing> {
|
|
61
|
+
let first: AccessHistoryPage | undefined;
|
|
62
|
+
const entries = await readCursorPages(limit, async (pageSize, pageToken) => {
|
|
63
|
+
const page = await client.iamPolicy.listAccessHistory(
|
|
51
64
|
create(ListAccessHistoryInputSchema, {
|
|
52
65
|
org,
|
|
53
66
|
pageSize: Math.min(pageSize, MAX_PAGE_SIZE),
|
|
54
67
|
pageToken,
|
|
55
68
|
}),
|
|
56
|
-
)
|
|
57
|
-
|
|
69
|
+
);
|
|
70
|
+
first ??= page;
|
|
71
|
+
return page;
|
|
72
|
+
});
|
|
73
|
+
return { entries, retentionDays: first?.retentionDays ?? 0 };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The line `list` prints under its table: how long the server keeps the history. */
|
|
77
|
+
export function retentionLine(retentionDays: number): string {
|
|
78
|
+
return retentionDays > 0
|
|
79
|
+
? `Entries older than ${retentionDays} ${retentionDays === 1 ? "day" : "days"} are removed.\n`
|
|
80
|
+
: "Kept for good.\n";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The note `export` writes apart from the lines when the server removed entries after the caller's. */
|
|
84
|
+
export function removedNote(removed: RemovedAccessHistory): string {
|
|
85
|
+
const run =
|
|
86
|
+
removed.first === removed.last
|
|
87
|
+
? `entry ${removed.first} is`
|
|
88
|
+
: `entries ${removed.first} to ${removed.last} are`;
|
|
89
|
+
const why =
|
|
90
|
+
removed.retentionDays > 0
|
|
91
|
+
? `this server removes entries older than ${removed.retentionDays} ${removed.retentionDays === 1 ? "day" : "days"}`
|
|
92
|
+
: "this server removed them";
|
|
93
|
+
return `${run} no longer kept: ${why}\n`;
|
|
58
94
|
}
|
|
59
95
|
|
|
60
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Writes every entry after `after`, oldest first, one JSON line each, and
|
|
98
|
+
* a removed run, when there is one, as one note; answers how many lines it
|
|
99
|
+
* wrote.
|
|
100
|
+
*/
|
|
61
101
|
export async function exportAccessHistoryLines(
|
|
62
102
|
client: AccessHistoryClient,
|
|
63
103
|
org: string,
|
|
64
104
|
after: bigint,
|
|
65
105
|
write: (line: string) => void,
|
|
106
|
+
note: (line: string) => void,
|
|
66
107
|
): Promise<number> {
|
|
67
108
|
let written = 0;
|
|
68
|
-
|
|
109
|
+
const onRemoved = (removed: RemovedAccessHistory): void => {
|
|
110
|
+
note(removedNote(removed));
|
|
111
|
+
};
|
|
112
|
+
for await (const entry of exportAccessHistory(client.iamPolicy, org, { after, onRemoved })) {
|
|
69
113
|
write(`${accessHistoryJsonLine(entry)}\n`);
|
|
70
114
|
written += 1;
|
|
71
115
|
}
|