@dataparade/cli 0.0.32 → 0.0.33
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 +56 -1
- package/dist/package.json +4 -3
- package/dist/src/cli.js +47 -4
- package/dist/src/diff/register-diff-command.d.ts +4 -0
- package/dist/src/diff/register-diff-command.js +79 -0
- package/dist/src/diff/run-diff.d.ts +80 -0
- package/dist/src/diff/run-diff.js +206 -0
- package/dist/src/diff/upload-diff.d.ts +26 -0
- package/dist/src/diff/upload-diff.js +69 -0
- package/dist/src/facts/apply-answers.js +1 -1
- package/dist/src/facts/build-facts.d.ts +3 -1
- package/dist/src/facts/build-facts.js +10 -1
- package/dist/src/facts/identity.d.ts +27 -0
- package/dist/src/facts/identity.js +203 -0
- package/dist/src/facts/io.d.ts +2 -0
- package/dist/src/facts/io.js +7 -0
- package/dist/src/facts/scan-stamps.d.ts +55 -0
- package/dist/src/facts/scan-stamps.js +165 -0
- package/dist/src/facts/schema.d.ts +243 -7
- package/dist/src/facts/schema.js +71 -1
- package/dist/src/kb/answer-fingerprint.d.ts +44 -0
- package/dist/src/kb/answer-fingerprint.js +173 -0
- package/dist/src/kb/brief.d.ts +8 -1
- package/dist/src/kb/brief.js +18 -2
- package/dist/src/kb/land.js +3 -0
- package/dist/src/kb/register-kb-commands.js +7 -1
- package/dist/src/output/git-context.d.ts +8 -0
- package/dist/src/output/git-context.js +18 -0
- package/dist/src/output/scan-output-excludes.js +5 -1
- package/dist/src/output/write-scan-knowledge.d.ts +2 -0
- package/dist/src/output/write-scan-knowledge.js +1 -0
- package/dist/src/platform-api/dataparade-app-base-url.d.ts +8 -4
- package/dist/src/platform-api/dataparade-app-base-url.js +10 -5
- package/dist/src/platform-api/upload-client.d.ts +1 -1
- package/dist/src/platform-api/upload-client.js +32 -1
- package/dist/src/platform-api/upload.types.d.ts +55 -0
- package/dist/src/sensitive-scan/process.d.ts +5 -0
- package/dist/src/sensitive-scan/process.js +48 -0
- package/dist/src/sensitive-scan/project.d.ts +12 -0
- package/dist/src/sensitive-scan/project.js +177 -0
- package/dist/src/sensitive-scan/report.d.ts +50 -0
- package/dist/src/sensitive-scan/report.js +32 -0
- package/dist/src/sensitive-scan/sessions.d.ts +2 -0
- package/dist/src/sensitive-scan/sessions.js +120 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +1 -0
- package/dist/src/ui/scan-progress-renderer.js +8 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +4 -4
- package/dist/src/upload/run-upload.js +6 -2
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/diff/run-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/run-diff.spec.js +189 -0
- package/dist/tests/unit/diff/upload-diff.spec.d.ts +1 -0
- package/dist/tests/unit/diff/upload-diff.spec.js +81 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +1 -1
- package/dist/tests/unit/facts/build-facts.spec.js +67 -1
- package/dist/tests/unit/facts/identity.spec.d.ts +1 -0
- package/dist/tests/unit/facts/identity.spec.js +148 -0
- package/dist/tests/unit/facts/scan-stamps.spec.d.ts +1 -0
- package/dist/tests/unit/facts/scan-stamps.spec.js +95 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.d.ts +1 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.js +157 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +16 -0
- package/dist/tests/unit/output/git-context.spec.js +19 -0
- package/dist/tests/unit/platform-api/dataparade-app-base-url.spec.js +9 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +101 -1
- package/dist/tests/unit/sensitive-scan/project.spec.d.ts +1 -0
- package/dist/tests/unit/sensitive-scan/project.spec.js +98 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +4 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +1 -0
- package/dist/tests/unit/upload/run-upload.spec.js +32 -0
- package/dist/vendor/kb-compare/dist/src/canonical.d.ts +80 -0
- package/dist/vendor/kb-compare/dist/src/canonical.js +119 -0
- package/dist/vendor/kb-compare/dist/src/change-set.d.ts +144 -0
- package/dist/vendor/kb-compare/dist/src/change-set.js +80 -0
- package/dist/vendor/kb-compare/dist/src/comparable.d.ts +23 -0
- package/dist/vendor/kb-compare/dist/src/comparable.js +48 -0
- package/dist/vendor/kb-compare/dist/src/compare.d.ts +52 -0
- package/dist/vendor/kb-compare/dist/src/compare.js +370 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.d.ts +40 -0
- package/dist/vendor/kb-compare/dist/src/fingerprint.js +88 -0
- package/dist/vendor/kb-compare/dist/src/index.d.ts +15 -0
- package/dist/vendor/kb-compare/dist/src/index.js +34 -0
- package/dist/vendor/kb-compare/dist/src/input.d.ts +128 -0
- package/dist/vendor/kb-compare/dist/src/input.js +75 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.d.ts +69 -0
- package/dist/vendor/kb-compare/dist/src/slot-rules.js +203 -0
- package/dist/vendor/kb-compare/dist/src/summary.d.ts +3 -0
- package/dist/vendor/kb-compare/dist/src/summary.js +47 -0
- package/dist/vendor/kb-compare/package.json +6 -0
- package/dist/vendor/scanner/dist/src/classifier/application-injection.js +5 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/stable-component-ids.js +11 -1
- package/dist/vendor/scanner/dist/src/index.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/index.js +4 -2
- package/dist/vendor/scanner/package.json +3 -1
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +10 -0
- package/dist/vendor/scanner/patterns/component-taxonomy.yaml +1 -1
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +25 -0
- package/package.json +4 -3
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.elementOfFact = elementOfFact;
|
|
4
|
+
exports.fingerprintFields = fingerprintFields;
|
|
5
|
+
exports.migrateAnswerFingerprints = migrateAnswerFingerprints;
|
|
6
|
+
const kb_compare_1 = require("../../vendor/kb-compare/dist/src/index.js");
|
|
7
|
+
const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
|
|
8
|
+
const io_1 = require("../facts/io");
|
|
9
|
+
const brief_1 = require("./brief");
|
|
10
|
+
const kb_store_1 = require("./kb-store");
|
|
11
|
+
const slot_shapes_1 = require("./slot-shapes");
|
|
12
|
+
/** The element a Fact id names in a scan, by its identity. Null when the scan has no such Fact or it has no identity. */
|
|
13
|
+
function elementOfFact(facts, factId) {
|
|
14
|
+
for (const c of facts.components) {
|
|
15
|
+
if (c.id === factId && c.identity)
|
|
16
|
+
return { subject: "component", key: c.identity.key };
|
|
17
|
+
}
|
|
18
|
+
for (const f of facts.dataFlows) {
|
|
19
|
+
if (f.id === factId && f.identity)
|
|
20
|
+
return { subject: "dataFlow", key: f.identity.key };
|
|
21
|
+
}
|
|
22
|
+
for (const item of facts.dataItems) {
|
|
23
|
+
if (item.id === factId && item.identity)
|
|
24
|
+
return { subject: "dataItem", key: item.identity.key };
|
|
25
|
+
for (const g of item.groups) {
|
|
26
|
+
if (g.id === factId && g.identity)
|
|
27
|
+
return { subject: "group", key: g.identity.key };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** Identity key and fingerprint fields for an answer about `factId`, from the scan it was given against. */
|
|
33
|
+
function fingerprintFields(facts, factId) {
|
|
34
|
+
if (factId === slot_shapes_1.SYSTEM_ASSERTS_URI) {
|
|
35
|
+
return { identityKey: slot_shapes_1.SYSTEM_ASSERTS_URI, fingerprintSource: "landed" };
|
|
36
|
+
}
|
|
37
|
+
const element = elementOfFact(facts, factId);
|
|
38
|
+
if (!element)
|
|
39
|
+
return {};
|
|
40
|
+
const fingerprint = (0, kb_compare_1.fingerprintOf)(facts, element.subject, element.key);
|
|
41
|
+
return {
|
|
42
|
+
identityKey: element.key,
|
|
43
|
+
...(fingerprint ? { fingerprint } : {}),
|
|
44
|
+
fingerprintSource: "landed",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The element the brief recorded for a Fact id: a component (actor, external system, flow endpoint) or a flow. */
|
|
48
|
+
function elementFromBrief(brief, factId) {
|
|
49
|
+
for (const flow of brief.flows) {
|
|
50
|
+
if ((flow.id === factId || flow.asserts === factId) && flow.identity) {
|
|
51
|
+
return { subject: "dataFlow", key: flow.identity.key };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const entities = [
|
|
55
|
+
...brief.actors,
|
|
56
|
+
...brief.external_systems,
|
|
57
|
+
...brief.flows.flatMap((flow) => [flow.source, flow.target]),
|
|
58
|
+
];
|
|
59
|
+
for (const entity of entities) {
|
|
60
|
+
if ((entity.id === factId || entity.asserts === factId) && entity.identity) {
|
|
61
|
+
return { subject: "component", key: entity.identity.key };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** The root Application of a scan: the component keyed by the project-name token (DATAP-858). */
|
|
67
|
+
function rootApplicationKey(facts) {
|
|
68
|
+
const roots = facts.components.filter((c) => c.identity?.key.endsWith(`|${scanner_1.PROJECT_NAME_KEY_TOKEN}`));
|
|
69
|
+
return roots.length === 1 ? roots[0].identity.key : null;
|
|
70
|
+
}
|
|
71
|
+
/** An `app:` key with its name segment swapped for the project-name token. */
|
|
72
|
+
function withProjectNameToken(key) {
|
|
73
|
+
if (!key.startsWith("app:"))
|
|
74
|
+
return null;
|
|
75
|
+
const at = key.lastIndexOf("|");
|
|
76
|
+
return at === -1 ? null : `${key.slice(0, at)}|${scanner_1.PROJECT_NAME_KEY_TOKEN}`;
|
|
77
|
+
}
|
|
78
|
+
/** The brief's entity name for a Fact id, when the brief names it. */
|
|
79
|
+
function briefEntityName(brief, factId) {
|
|
80
|
+
const entities = [...brief.actors, ...brief.external_systems, ...brief.flows.flatMap((f) => [f.source, f.target])];
|
|
81
|
+
return entities.find((e) => e.id === factId || e.asserts === factId)?.name ?? null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Give each answer without an identity key its key and a fingerprint (`fingerprintSource:
|
|
85
|
+
* migrated`). The key comes from the brief the answer cites; failing that, from the Fact with
|
|
86
|
+
* the same id in the current scan; failing that, for the root Application whose id changed
|
|
87
|
+
* once (DATAP-858), from the project-name token. The fingerprint is computed from the current
|
|
88
|
+
* scan. Answers on occurrences stay unkeyed: they are outside the carry rules (DATAP-862).
|
|
89
|
+
*/
|
|
90
|
+
function migrateAnswerFingerprints(paths, options = {}) {
|
|
91
|
+
const state = (0, kb_store_1.loadKbState)(paths);
|
|
92
|
+
const file = (0, io_1.readAnswers)(paths);
|
|
93
|
+
const facts = state.facts;
|
|
94
|
+
const root = rootApplicationKey(facts);
|
|
95
|
+
const briefs = new Map();
|
|
96
|
+
const briefFor = (sha) => {
|
|
97
|
+
if (!sha)
|
|
98
|
+
return null;
|
|
99
|
+
if (!briefs.has(sha)) {
|
|
100
|
+
try {
|
|
101
|
+
briefs.set(sha, (0, brief_1.readKbBrief)(paths, sha));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (!(error instanceof kb_store_1.KbError))
|
|
105
|
+
throw error;
|
|
106
|
+
briefs.set(sha, null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return briefs.get(sha) ?? null;
|
|
110
|
+
};
|
|
111
|
+
const result = {
|
|
112
|
+
migrated: 0,
|
|
113
|
+
alreadyKeyed: 0,
|
|
114
|
+
outcomes: {},
|
|
115
|
+
withoutFingerprint: [],
|
|
116
|
+
unresolved: [],
|
|
117
|
+
dryRun: Boolean(options.dryRun),
|
|
118
|
+
};
|
|
119
|
+
const next = file.answers.map((answer) => {
|
|
120
|
+
if (answer.identityKey) {
|
|
121
|
+
result.alreadyKeyed += 1;
|
|
122
|
+
return answer;
|
|
123
|
+
}
|
|
124
|
+
if (answer.factId === slot_shapes_1.SYSTEM_ASSERTS_URI) {
|
|
125
|
+
result.migrated += 1;
|
|
126
|
+
result.outcomes[answer.id] = "system";
|
|
127
|
+
return { ...answer, identityKey: slot_shapes_1.SYSTEM_ASSERTS_URI, fingerprintSource: "migrated" };
|
|
128
|
+
}
|
|
129
|
+
const brief = briefFor(answer.briefSha);
|
|
130
|
+
let element = brief ? elementFromBrief(brief, answer.factId) : null;
|
|
131
|
+
let outcome = element ? "brief" : "unresolved";
|
|
132
|
+
if (!element) {
|
|
133
|
+
element = elementOfFact(facts, answer.factId);
|
|
134
|
+
if (element)
|
|
135
|
+
outcome = "scan";
|
|
136
|
+
}
|
|
137
|
+
if (element?.subject === "component" && root && !(0, kb_compare_1.fingerprintOf)(facts, "component", element.key)) {
|
|
138
|
+
// A brief key from before DATAP-858 names the root by its folder; the scan now uses the token.
|
|
139
|
+
if (withProjectNameToken(element.key) === root) {
|
|
140
|
+
element = { subject: "component", key: root };
|
|
141
|
+
outcome = "root";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!element && brief && root) {
|
|
145
|
+
// A brief without identities (CLI 0.0.32 and earlier) that names the root Application.
|
|
146
|
+
const rootFact = facts.components.find((c) => c.identity?.key === root);
|
|
147
|
+
if (rootFact && briefEntityName(brief, answer.factId) === rootFact.name) {
|
|
148
|
+
element = { subject: "component", key: root };
|
|
149
|
+
outcome = "root";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!element) {
|
|
153
|
+
result.unresolved.push(answer.id);
|
|
154
|
+
result.outcomes[answer.id] = "unresolved";
|
|
155
|
+
return answer;
|
|
156
|
+
}
|
|
157
|
+
result.migrated += 1;
|
|
158
|
+
result.outcomes[answer.id] = outcome;
|
|
159
|
+
const fingerprint = (0, kb_compare_1.fingerprintOf)(facts, element.subject, element.key);
|
|
160
|
+
if (!fingerprint)
|
|
161
|
+
result.withoutFingerprint.push(answer.id);
|
|
162
|
+
return {
|
|
163
|
+
...answer,
|
|
164
|
+
identityKey: element.key,
|
|
165
|
+
...(fingerprint ? { fingerprint } : {}),
|
|
166
|
+
fingerprintSource: "migrated",
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
if (!options.dryRun && result.migrated > 0) {
|
|
170
|
+
(0, io_1.writeAnswers)(paths, { ...file, answers: next });
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
package/dist/src/kb/brief.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { A0DiscoveriesDocument } from "../discoveries/contract/discoveries-document.schema";
|
|
2
|
+
import type { FactsFile, Identity } from "../facts/schema";
|
|
2
3
|
import { type KbPaths } from "./kb-store";
|
|
3
4
|
import { type EligibleShape, type InterviewSlot } from "./slot-shapes";
|
|
4
5
|
/**
|
|
@@ -13,6 +14,8 @@ export interface KbBriefEntity {
|
|
|
13
14
|
asserts: string;
|
|
14
15
|
name: string;
|
|
15
16
|
type: string;
|
|
17
|
+
/** The Fact's identity (DATAP-842), so an answer can be matched in a later scan. Absent for KBs from CLI 0.0.32 and earlier. */
|
|
18
|
+
identity?: Identity;
|
|
16
19
|
}
|
|
17
20
|
export type FlowCrossing = "outbound_third_party" | "from_actor" | "internal";
|
|
18
21
|
export interface KbBriefFlow {
|
|
@@ -24,6 +27,8 @@ export interface KbBriefFlow {
|
|
|
24
27
|
target: KbBriefEntity;
|
|
25
28
|
data_categories: string[] | null;
|
|
26
29
|
purpose: string | null;
|
|
30
|
+
/** The flow's identity (DATAP-842). Absent for KBs from CLI 0.0.32 and earlier. */
|
|
31
|
+
identity?: Identity;
|
|
27
32
|
}
|
|
28
33
|
export interface KbBriefQuestion {
|
|
29
34
|
asserts: string;
|
|
@@ -48,7 +53,9 @@ export interface KbBrief {
|
|
|
48
53
|
/** Interview order: scope, outbound third-party flows, then people (no internal or from-actor flow slots). */
|
|
49
54
|
questions: KbBriefQuestion[];
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
/** Identities of the scan's components and flows, by Fact id. */
|
|
57
|
+
export declare function factIdentities(facts: FactsFile): Map<string, Identity>;
|
|
58
|
+
export declare function buildKbBrief(document: A0DiscoveriesDocument, identities?: ReadonlyMap<string, Identity>): KbBrief;
|
|
52
59
|
/** 40-hex SHA-1 of the canonical brief: the form the ontology requires for `brief_sha`. */
|
|
53
60
|
export declare function kbBriefSha(brief: KbBrief): string;
|
|
54
61
|
export interface WrittenKbBrief {
|
package/dist/src/kb/brief.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.factIdentities = factIdentities;
|
|
6
7
|
exports.buildKbBrief = buildKbBrief;
|
|
7
8
|
exports.kbBriefSha = kbBriefSha;
|
|
8
9
|
exports.writeKbBrief = writeKbBrief;
|
|
@@ -22,13 +23,27 @@ function rawEntityId(projectedId) {
|
|
|
22
23
|
function entityAsserts(entity) {
|
|
23
24
|
return rawEntityId(entity.id);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
/** Identities of the scan's components and flows, by Fact id. */
|
|
27
|
+
function factIdentities(facts) {
|
|
28
|
+
const result = new Map();
|
|
29
|
+
for (const fact of [...facts.components, ...facts.dataFlows]) {
|
|
30
|
+
if (fact.identity)
|
|
31
|
+
result.set(fact.id, fact.identity);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function buildKbBrief(document, identities = new Map()) {
|
|
26
36
|
const components = new Map(document.components.map((c) => [c.id, c]));
|
|
37
|
+
const withIdentity = (id) => {
|
|
38
|
+
const identity = identities.get(id);
|
|
39
|
+
return identity ? { identity } : {};
|
|
40
|
+
};
|
|
27
41
|
const brief = (c) => ({
|
|
28
42
|
id: rawEntityId(c.id),
|
|
29
43
|
asserts: entityAsserts(c),
|
|
30
44
|
name: c.name,
|
|
31
45
|
type: c.type,
|
|
46
|
+
...withIdentity(rawEntityId(c.id)),
|
|
32
47
|
});
|
|
33
48
|
const actors = document.components
|
|
34
49
|
.filter((c) => c.type === "actor")
|
|
@@ -54,6 +69,7 @@ function buildKbBrief(document) {
|
|
|
54
69
|
target: brief(target),
|
|
55
70
|
data_categories: flow.data_categories ?? null,
|
|
56
71
|
purpose: flow.purpose ?? null,
|
|
72
|
+
...withIdentity(rawEntityId(flow.id)),
|
|
57
73
|
});
|
|
58
74
|
}
|
|
59
75
|
const question = (asserts, slot, known, about) => ({
|
|
@@ -105,7 +121,7 @@ function kbBriefSha(brief) {
|
|
|
105
121
|
/** Snapshot the current KB as a brief and store it at `<kb>/briefs/<sha>.json`. */
|
|
106
122
|
function writeKbBrief(paths) {
|
|
107
123
|
const state = (0, kb_store_1.loadKbState)(paths);
|
|
108
|
-
const brief = buildKbBrief(state.document);
|
|
124
|
+
const brief = buildKbBrief(state.document, factIdentities(state.facts));
|
|
109
125
|
const sha = kbBriefSha(brief);
|
|
110
126
|
(0, kb_store_1.ensureDir)(paths.briefsDir);
|
|
111
127
|
const briefPath = path_1.default.join(paths.briefsDir, `${sha}.json`);
|
package/dist/src/kb/land.js
CHANGED
|
@@ -10,6 +10,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const apply_answers_1 = require("../facts/apply-answers");
|
|
12
12
|
const io_1 = require("../facts/io");
|
|
13
|
+
const answer_fingerprint_1 = require("./answer-fingerprint");
|
|
13
14
|
const brief_1 = require("./brief");
|
|
14
15
|
const kb_store_1 = require("./kb-store");
|
|
15
16
|
const slot_shapes_1 = require("./slot-shapes");
|
|
@@ -88,6 +89,7 @@ function landInterviewAnswer(paths, input) {
|
|
|
88
89
|
evidence: evidenceRef,
|
|
89
90
|
briefSha: input.briefSha,
|
|
90
91
|
skillSha: input.skillSha,
|
|
92
|
+
...(0, answer_fingerprint_1.fingerprintFields)(state.facts, factId),
|
|
91
93
|
};
|
|
92
94
|
return store(paths, answer, previousAnswerId(state.answers, factId, slot), input.dryRun);
|
|
93
95
|
}
|
|
@@ -126,6 +128,7 @@ function landReviewAnswer(paths, input) {
|
|
|
126
128
|
at: now.toISOString(),
|
|
127
129
|
source: "review",
|
|
128
130
|
...(input.evidence ? { evidence: input.evidence } : {}),
|
|
131
|
+
...(0, answer_fingerprint_1.fingerprintFields)(state.facts, input.target),
|
|
129
132
|
};
|
|
130
133
|
const trial = (0, apply_answers_1.applyAnswers)(state.facts, state.dataItemFiles, [answer]);
|
|
131
134
|
if (trial.orphans.length > 0) {
|
|
@@ -4,6 +4,7 @@ exports.registerKbCommands = registerKbCommands;
|
|
|
4
4
|
const layout_1 = require("../facts/layout");
|
|
5
5
|
const brief_1 = require("./brief");
|
|
6
6
|
const kb_store_1 = require("./kb-store");
|
|
7
|
+
const answer_fingerprint_1 = require("./answer-fingerprint");
|
|
7
8
|
const migrate_1 = require("./migrate");
|
|
8
9
|
const land_1 = require("./land");
|
|
9
10
|
const project_diagram_1 = require("./project-diagram");
|
|
@@ -111,12 +112,17 @@ function registerKbCommands(program) {
|
|
|
111
112
|
}
|
|
112
113
|
});
|
|
113
114
|
kb.command("migrate")
|
|
114
|
-
.description("Convert interview records from an old ocsf-discoveries/ folder (CLI 0.0.26 and earlier) into answers.json")
|
|
115
|
+
.description("Convert interview records from an old ocsf-discoveries/ folder (CLI 0.0.26 and earlier) into answers.json, or with --fingerprints give old answers an identity key and fingerprint")
|
|
115
116
|
.option("--kb <dir>", "Knowledge base directory", DEFAULT_KB_DIR)
|
|
116
117
|
.option("--from <dir>", "Old OCSF folder (default: <kb>/ocsf-discoveries)")
|
|
118
|
+
.option("--fingerprints", "Add identity keys and fingerprints to answers that have none (from the cited brief and the current scan)")
|
|
117
119
|
.option("--dry-run", "Count what would be migrated without writing")
|
|
118
120
|
.action((options) => {
|
|
119
121
|
try {
|
|
122
|
+
if (options.fingerprints) {
|
|
123
|
+
print({ ok: true, ...(0, answer_fingerprint_1.migrateAnswerFingerprints)((0, kb_store_1.resolveKbPaths)(options.kb), { dryRun: options.dryRun }) });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
120
126
|
print({ ok: true, ...(0, migrate_1.migrateInterviewRecords)((0, kb_store_1.resolveKbPaths)(options.kb), { from: options.from, dryRun: options.dryRun }) });
|
|
121
127
|
}
|
|
122
128
|
catch (error) {
|
|
@@ -6,6 +6,12 @@ type ParsedRemote = {
|
|
|
6
6
|
};
|
|
7
7
|
/** Accepts `git@host:owner/repo.git`, `ssh://git@host[:port]/owner/repo` and http(s) remotes. */
|
|
8
8
|
export declare function parseGitRemote(remote: string): ParsedRemote | null;
|
|
9
|
+
/**
|
|
10
|
+
* The remote as `https://host/owner/repo`: SCP-style and ssh remotes become https,
|
|
11
|
+
* the host is lowercased, and credentials, port and `.git` are dropped. The backend
|
|
12
|
+
* matches a repository by this URL when its root commit is unknown (DATAP-883).
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeGitRemoteUrl(remote: string): string | null;
|
|
9
15
|
/** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
|
|
10
16
|
export declare function gitContextFromRemote(remote: string, commitSha: string): GitContextSchema | null;
|
|
11
17
|
/**
|
|
@@ -14,4 +20,6 @@ export declare function gitContextFromRemote(remote: string, commitSha: string):
|
|
|
14
20
|
* or no origin all return null.
|
|
15
21
|
*/
|
|
16
22
|
export declare function detectGitContext(dir: string): GitContextSchema | null;
|
|
23
|
+
/** The normalized origin remote of the repository containing `dir`, or null. Never throws. */
|
|
24
|
+
export declare function readOriginRemoteUrl(dir: string): string | null;
|
|
17
25
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseGitRemote = parseGitRemote;
|
|
4
|
+
exports.normalizeGitRemoteUrl = normalizeGitRemoteUrl;
|
|
4
5
|
exports.gitContextFromRemote = gitContextFromRemote;
|
|
5
6
|
exports.detectGitContext = detectGitContext;
|
|
7
|
+
exports.readOriginRemoteUrl = readOriginRemoteUrl;
|
|
6
8
|
const node_child_process_1 = require("node:child_process");
|
|
7
9
|
const dataflow_wrapper_schema_1 = require("../core/schema/dataflow-wrapper.schema");
|
|
8
10
|
const GIT_TIMEOUT_MS = 5000;
|
|
@@ -41,6 +43,17 @@ function parseGitRemote(remote) {
|
|
|
41
43
|
return null;
|
|
42
44
|
return { host: host.toLowerCase(), repository, protocol };
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The remote as `https://host/owner/repo`: SCP-style and ssh remotes become https,
|
|
48
|
+
* the host is lowercased, and credentials, port and `.git` are dropped. The backend
|
|
49
|
+
* matches a repository by this URL when its root commit is unknown (DATAP-883).
|
|
50
|
+
*/
|
|
51
|
+
function normalizeGitRemoteUrl(remote) {
|
|
52
|
+
const parsed = parseGitRemote(remote);
|
|
53
|
+
if (!parsed)
|
|
54
|
+
return null;
|
|
55
|
+
return `${parsed.protocol}//${parsed.host}/${parsed.repository}`;
|
|
56
|
+
}
|
|
44
57
|
/** Maps a remote to the dataflow git context; null for hosts other than GitHub and GitLab. */
|
|
45
58
|
function gitContextFromRemote(remote, commitSha) {
|
|
46
59
|
const parsed = parseGitRemote(remote);
|
|
@@ -102,3 +115,8 @@ function detectGitContext(dir) {
|
|
|
102
115
|
return null;
|
|
103
116
|
return gitContextFromRemote(remote, commitSha);
|
|
104
117
|
}
|
|
118
|
+
/** The normalized origin remote of the repository containing `dir`, or null. Never throws. */
|
|
119
|
+
function readOriginRemoteUrl(dir) {
|
|
120
|
+
const remote = git(dir, ['remote', 'get-url', 'origin']);
|
|
121
|
+
return remote ? normalizeGitRemoteUrl(remote) : null;
|
|
122
|
+
}
|
|
@@ -13,6 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const SCAN_OUTPUT_ENTRIES = [
|
|
14
14
|
"dataflow.json",
|
|
15
15
|
"facts.json",
|
|
16
|
+
"sensitive-findings.json",
|
|
16
17
|
"data-items/**",
|
|
17
18
|
"graphify.json",
|
|
18
19
|
"answers.json",
|
|
@@ -40,5 +41,8 @@ function scanOutputExcludes(scanRoot, dataflowOutputPath) {
|
|
|
40
41
|
return [];
|
|
41
42
|
}
|
|
42
43
|
const prefix = relative ? `${relative.split(path_1.default.sep).join("/")}/` : "";
|
|
43
|
-
return prefix ? [`${prefix}**`] :
|
|
44
|
+
return prefix ? [`${prefix}**`] : [...new Set([
|
|
45
|
+
...SCAN_OUTPUT_ENTRIES,
|
|
46
|
+
path_1.default.basename(dataflowOutputPath),
|
|
47
|
+
])];
|
|
44
48
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DataParadeGraph, type OrchestratorScanResult } from '../../vendor/scanner/dist/src/index.js';
|
|
2
2
|
import type { OutputLayout } from '../facts/layout';
|
|
3
3
|
import { type DataflowHierarchy } from './c4-hierarchy';
|
|
4
|
+
import type { ScanStamps } from "../facts/schema";
|
|
4
5
|
/**
|
|
5
6
|
* Where Graphify keeps its working files and cache between scans, outside the output
|
|
6
7
|
* folder: `~/.cache/dataparade/graphify/<hash of the scan root>`.
|
|
@@ -28,6 +29,7 @@ export interface WriteScanFactsOptions {
|
|
|
28
29
|
cliVersion: string;
|
|
29
30
|
scannerVersion: string;
|
|
30
31
|
scannedAt?: string;
|
|
32
|
+
stamps?: ScanStamps;
|
|
31
33
|
}
|
|
32
34
|
/** Write facts.json and data-items/. answers.json is not touched. */
|
|
33
35
|
export declare function writeScanFacts(layout: OutputLayout, options: WriteScanFactsOptions): import("../facts/build-facts").BuiltFacts;
|
|
@@ -109,6 +109,7 @@ function writeScanFacts(layout, options) {
|
|
|
109
109
|
cliVersion: options.cliVersion,
|
|
110
110
|
scannerVersion: options.scannerVersion,
|
|
111
111
|
scannedAt: options.scannedAt,
|
|
112
|
+
stamps: options.stamps,
|
|
112
113
|
});
|
|
113
114
|
(0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
|
|
114
115
|
return built;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default DataParade web app
|
|
3
|
-
*
|
|
2
|
+
* Default DataParade web app. Used when the CLI prints dashboard preview links and
|
|
3
|
+
* neither DATAPARADE_APP_URL nor the API's upload response names the app.
|
|
4
4
|
*/
|
|
5
5
|
export declare const DEFAULT_DATAPARADE_APP_URL = "https://app.dataparade.io";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Resolve web app origin (no trailing slash): DATAPARADE_APP_URL, else the app the API
|
|
8
|
+
* named in its upload response (so an upload to the dev API links to the dev app), else
|
|
9
|
+
* the default.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getDataparadeAppBaseUrl(env?: NodeJS.ProcessEnv, fromApi?: string): string;
|
|
@@ -3,12 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DEFAULT_DATAPARADE_APP_URL = void 0;
|
|
4
4
|
exports.getDataparadeAppBaseUrl = getDataparadeAppBaseUrl;
|
|
5
5
|
/**
|
|
6
|
-
* Default DataParade web app
|
|
7
|
-
*
|
|
6
|
+
* Default DataParade web app. Used when the CLI prints dashboard preview links and
|
|
7
|
+
* neither DATAPARADE_APP_URL nor the API's upload response names the app.
|
|
8
8
|
*/
|
|
9
9
|
exports.DEFAULT_DATAPARADE_APP_URL = "https://app.dataparade.io";
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Resolve web app origin (no trailing slash): DATAPARADE_APP_URL, else the app the API
|
|
12
|
+
* named in its upload response (so an upload to the dev API links to the dev app), else
|
|
13
|
+
* the default.
|
|
14
|
+
*/
|
|
15
|
+
function getDataparadeAppBaseUrl(env = process.env, fromApi) {
|
|
16
|
+
const api = fromApi?.trim();
|
|
17
|
+
const base = env.DATAPARADE_APP_URL?.trim() || (api && /^https?:\/\//.test(api) ? api : "") || exports.DEFAULT_DATAPARADE_APP_URL;
|
|
13
18
|
return base.replace(/\/$/, "");
|
|
14
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ScanUploadFile } from '../upload/collect-scan-sidecars';
|
|
2
2
|
import type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse } from './upload.types';
|
|
3
|
-
export type { CliAnonymousUploadPreviewResponse, CliUploadPreviewInput, CliUploadPreviewResponse, } from './upload.types';
|
|
3
|
+
export type { CliAnonymousUploadPreviewResponse, CliUploadComparison, CliUploadCompareRequest, CliUploadCompleteResponse, CliUploadPreviewInput, CliUploadPreviewResponse, } from './upload.types';
|
|
4
4
|
/** Upload rejected by the API; `status` is the HTTP status (429 = rate limit). */
|
|
5
5
|
export declare class CliUploadError extends Error {
|
|
6
6
|
readonly status: number;
|
|
@@ -94,7 +94,38 @@ async function cliUploadPreview(input) {
|
|
|
94
94
|
}
|
|
95
95
|
const created = (await res.json());
|
|
96
96
|
if (input.files && input.files.length > 0) {
|
|
97
|
-
|
|
97
|
+
const draftUrl = `${(0, dataparade_api_base_url_1.getDataparadeApiBaseUrl)()}/api/scans/cli/upload/${encodeURIComponent(created.draftId)}`;
|
|
98
|
+
await postScanFiles(`${draftUrl}/files`, buildAuthHeaders(input.apiKey), input.files);
|
|
99
|
+
const complete = await completeScanUpload(draftUrl, input.apiKey, input.remoteUrl ?? null, input.compare);
|
|
100
|
+
return { ...created, complete };
|
|
98
101
|
}
|
|
99
102
|
return created;
|
|
100
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Tells the backend the scan files are all uploaded, so it stores the scan in the
|
|
106
|
+
* knowledge base (DATAP-883). With `compare` (`diff --upload` head, DATAP-890) the
|
|
107
|
+
* backend also stores the rename map and compares the head with the base. The
|
|
108
|
+
* preview works without it, so a failure only warns and gives null.
|
|
109
|
+
*/
|
|
110
|
+
async function completeScanUpload(draftUrl, apiKey, remoteUrl, compare) {
|
|
111
|
+
try {
|
|
112
|
+
const res = await fetch(`${draftUrl}/complete`, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: buildAuthHeaders(apiKey),
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
...(remoteUrl ? { remoteUrl } : {}),
|
|
117
|
+
...(compare ? { compare } : {}),
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
console.warn(`[upload] warning: the scan was uploaded but not stored for comparison (${res.status}).`);
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return (await res.json());
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
128
|
+
console.warn(`[upload] warning: the scan was uploaded but not stored for comparison: ${message}`);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1,11 +1,62 @@
|
|
|
1
1
|
export type CliUploadPreviewResponse = {
|
|
2
2
|
draftId: string;
|
|
3
3
|
projectName?: string | null;
|
|
4
|
+
/** The web app of the API that took the upload. Older backends leave it out. */
|
|
5
|
+
appUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* What `POST upload/:draftId/complete` returned (DATAP-883): the stored scan, and for a
|
|
8
|
+
* `diff --upload` head the comparison with the base. Null when the call failed.
|
|
9
|
+
*/
|
|
10
|
+
complete?: CliUploadCompleteResponse | null;
|
|
11
|
+
};
|
|
12
|
+
/** A comparison the backend ran (DATAP-891), or why it did not. */
|
|
13
|
+
export type CliUploadComparison = {
|
|
14
|
+
compared: true;
|
|
15
|
+
created: boolean;
|
|
16
|
+
comparison: {
|
|
17
|
+
id: string;
|
|
18
|
+
changeSet: {
|
|
19
|
+
renames?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
bindings: Array<{
|
|
23
|
+
answerId: string;
|
|
24
|
+
status: string;
|
|
25
|
+
reason: string;
|
|
26
|
+
}>;
|
|
27
|
+
summary: string;
|
|
28
|
+
} | {
|
|
29
|
+
compared: false;
|
|
30
|
+
reason: string;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
export type CliUploadCompleteResponse = {
|
|
34
|
+
stored: true;
|
|
35
|
+
scanId: string;
|
|
36
|
+
repositoryId: string;
|
|
37
|
+
created: boolean;
|
|
38
|
+
comparable: boolean;
|
|
39
|
+
comparison?: CliUploadComparison;
|
|
40
|
+
} | {
|
|
41
|
+
stored: false;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
/** Sent with the head upload of `dataparade diff --upload` (DATAP-890). */
|
|
45
|
+
export type CliUploadCompareRequest = {
|
|
46
|
+
baseCommitSha: string;
|
|
47
|
+
rootCommitSha: string;
|
|
48
|
+
renames: Array<{
|
|
49
|
+
from: string;
|
|
50
|
+
to: string;
|
|
51
|
+
similarity?: number;
|
|
52
|
+
}>;
|
|
4
53
|
};
|
|
5
54
|
export type CliAnonymousUploadPreviewResponse = {
|
|
6
55
|
claimToken: string;
|
|
7
56
|
expiresAt: string;
|
|
8
57
|
projectName: string;
|
|
58
|
+
/** The web app of the API that took the upload. Older backends leave it out. */
|
|
59
|
+
appUrl?: string;
|
|
9
60
|
};
|
|
10
61
|
export type CliUploadPreviewInput = {
|
|
11
62
|
apiKey?: string;
|
|
@@ -22,4 +73,8 @@ export type CliUploadPreviewInput = {
|
|
|
22
73
|
relativePath: string;
|
|
23
74
|
content: string;
|
|
24
75
|
}>;
|
|
76
|
+
/** Normalized origin remote, sent when the upload is completed (DATAP-883). */
|
|
77
|
+
remoteUrl?: string | null;
|
|
78
|
+
/** From `diff --upload` on the head scan: compare it with the base after it is stored. */
|
|
79
|
+
compare?: CliUploadCompareRequest;
|
|
25
80
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runLocalScanner = runLocalScanner;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_stream_1 = require("node:stream");
|
|
6
|
+
const promises_1 = require("node:stream/promises");
|
|
7
|
+
/** Scanner stderr may contain third-party diagnostics. Never forward it. */
|
|
8
|
+
async function runLocalScanner(executable, args, input) {
|
|
9
|
+
const child = (0, node_child_process_1.spawn)(executable, args, {
|
|
10
|
+
stdio: [input ? 'pipe' : 'ignore', 'pipe', 'ignore'],
|
|
11
|
+
windowsHide: true,
|
|
12
|
+
});
|
|
13
|
+
const output = [];
|
|
14
|
+
let size = 0;
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const timer = setTimeout(() => child.kill(), 300_000);
|
|
17
|
+
const completed = new Promise((resolve, reject) => {
|
|
18
|
+
child.once('error', reject);
|
|
19
|
+
child.once('close', resolve);
|
|
20
|
+
});
|
|
21
|
+
child.stdout?.on('data', (chunk) => {
|
|
22
|
+
size += chunk.length;
|
|
23
|
+
if (size > 64 * 1024 * 1024)
|
|
24
|
+
child.kill();
|
|
25
|
+
else
|
|
26
|
+
output.push(chunk);
|
|
27
|
+
});
|
|
28
|
+
const sending = input && child.stdin
|
|
29
|
+
? (0, promises_1.pipeline)(node_stream_1.Readable.from(input), child.stdin, {
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
}).catch((error) => {
|
|
32
|
+
if (error.code !== 'EPIPE' &&
|
|
33
|
+
error.code !== 'ABORT_ERR' &&
|
|
34
|
+
error.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
|
|
35
|
+
child.kill();
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
: Promise.resolve();
|
|
40
|
+
try {
|
|
41
|
+
const [code] = await Promise.all([completed, sending]);
|
|
42
|
+
return { code, output: Buffer.concat(output).toString('utf8') };
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
controller.abort();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ModelMode } from './report';
|
|
2
|
+
export declare const SENSITIVE_FINDINGS_BASENAME = "sensitive-findings.json";
|
|
3
|
+
type ProjectScan = {
|
|
4
|
+
root: string;
|
|
5
|
+
target: string;
|
|
6
|
+
excludes: string[];
|
|
7
|
+
modelMode: ModelMode;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
/** A separate local artifact. Nothing here is passed to the structural scanner. */
|
|
11
|
+
export declare function writeProjectSensitiveScan(dataflowOutputPath: string, options: ProjectScan, warn: (message: string) => void): Promise<number | undefined>;
|
|
12
|
+
export {};
|