@intentius/chant-lexicon-terraform 0.124.87 → 0.124.88
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/action-ops.d.ts.map +1 -1
- package/dist/action-ops.js +3 -1
- package/dist/chant-floors.d.ts +30 -0
- package/dist/chant-floors.d.ts.map +1 -0
- package/dist/chant-floors.js +29 -0
- package/dist/components/capability-plugin.d.ts +15 -1
- package/dist/components/capability-plugin.d.ts.map +1 -1
- package/dist/components/capability-plugin.js +13 -5
- package/dist/components/compose-group.d.ts +5 -1
- package/dist/components/compose-group.d.ts.map +1 -1
- package/dist/components/compose-group.js +7 -4
- package/dist/engine-timings.d.ts +249 -0
- package/dist/engine-timings.d.ts.map +1 -0
- package/dist/engine-timings.js +569 -0
- package/dist/integrity.json +2 -2
- package/dist/live-roots.d.ts +93 -0
- package/dist/live-roots.d.ts.map +1 -0
- package/dist/live-roots.js +206 -0
- package/dist/manifest.json +1 -1
- package/dist/migration-history.d.ts +105 -0
- package/dist/migration-history.d.ts.map +1 -0
- package/dist/migration-history.js +159 -0
- package/dist/module-catalog/index.d.ts +1 -0
- package/dist/module-catalog/index.d.ts.map +1 -1
- package/dist/module-catalog/index.js +3 -1
- package/dist/op/activities/live-detect.d.ts +15 -0
- package/dist/op/activities/live-detect.d.ts.map +1 -1
- package/dist/op/activities/live-detect.js +94 -0
- package/dist/op/activities/terraform.d.ts +1 -65
- package/dist/op/activities/terraform.d.ts.map +1 -1
- package/dist/op/activities/terraform.js +4 -54
- package/dist/op/command-hook.d.ts +88 -0
- package/dist/op/command-hook.d.ts.map +1 -0
- package/dist/op/command-hook.js +115 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -0
- package/dist/state/exec.d.ts +23 -0
- package/dist/state/exec.d.ts.map +1 -1
- package/dist/state/exec.js +38 -0
- package/dist/state-ops.d.ts.map +1 -1
- package/dist/state-ops.js +3 -1
- package/dist/terragrunt/index.d.ts +3 -1
- package/dist/terragrunt/index.d.ts.map +1 -1
- package/dist/terragrunt/index.js +3 -1
- package/dist/terragrunt/place.d.ts +27 -0
- package/dist/terragrunt/place.d.ts.map +1 -0
- package/dist/terragrunt/place.js +52 -0
- package/package.json +2 -2
- package/src/action-ops.ts +3 -1
- package/src/chant-floors.ts +32 -0
- package/src/components/capability-plugin.ts +27 -6
- package/src/components/compose-group.test.ts +29 -0
- package/src/components/compose-group.ts +12 -5
- package/src/components/terraform-apply-command-hook.test.ts +43 -0
- package/src/engine-timings.test.ts +203 -0
- package/src/engine-timings.ts +718 -0
- package/src/live-roots.test.ts +80 -0
- package/src/live-roots.ts +244 -0
- package/src/migration-history.test.ts +83 -0
- package/src/migration-history.ts +199 -0
- package/src/module-catalog/index.ts +4 -1
- package/src/op/activities/live-detect.ts +87 -0
- package/src/op/activities/terraform.ts +12 -111
- package/src/op/command-hook.ts +182 -0
- package/src/registry/index.ts +1 -0
- package/src/state/engine-env.test.ts +18 -0
- package/src/state/exec.ts +38 -0
- package/src/state-ops.ts +3 -1
- package/src/terragrunt/index.ts +3 -1
- package/src/terragrunt/place.test.ts +42 -0
- package/src/terragrunt/place.ts +75 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-roots.d.ts","sourceRoot":"","sources":["../src/live-roots.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElG,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhG,8HAA8H;AAC9H,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,SAAc,GAAG,MAAM,EAAE,CAEhG;AAED,iHAAiH;AACjH,wBA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EAAE,CAO1E"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which roots are choudoufu live roots, their estates, and the setup
|
|
3
|
+
* choudoufu resolves for each (chant#4910).
|
|
4
|
+
*
|
|
5
|
+
* - {@link liveRoots}: the roots that keep their resources under choudoufu's
|
|
6
|
+
* live markers, a `live` block in a `terraform` block or an
|
|
7
|
+
* `estate.chdf.hcl` sidecar.
|
|
8
|
+
* - {@link estateOf}: a root's estate as its files name it, and the estates
|
|
9
|
+
* whose recorded outputs it reads through `data "terraform_estate_outputs"`.
|
|
10
|
+
* - {@link readLiveSetup}: the record store and estate choudoufu resolves
|
|
11
|
+
* for a root, from `choudoufu live-check -json` (its `estate`,
|
|
12
|
+
* `estate_source` and `record_store` fields), remembered for the process,
|
|
13
|
+
* and {@link resolvedEstate}, which prefers it to the files' own name. A
|
|
14
|
+
* choudoufu release that prints no `estate_source` gives no setup, and the
|
|
15
|
+
* readers fall back to the files.
|
|
16
|
+
* - {@link setupLine}, {@link storePhrase}, {@link bucketTarget},
|
|
17
|
+
* {@link checkStoreBucket} and {@link bucketLines}: the setup as a log line,
|
|
18
|
+
* and core's bucket check (`@intentius/chant/bucket-check`, chant#4558) on
|
|
19
|
+
* the resolved store.
|
|
20
|
+
*
|
|
21
|
+
* Text reads, as `./op/activities/live-detect.ts` does them: no HCL parser
|
|
22
|
+
* is loaded. Lifted from terragucci's `detect.ts` (`liveRoots`, `estateOf`)
|
|
23
|
+
* and `live-setup.ts`, so terragucci deletes its copies.
|
|
24
|
+
*/
|
|
25
|
+
import { join, resolve } from "node:path";
|
|
26
|
+
import { checkBucket } from "@intentius/chant/bucket-check";
|
|
27
|
+
import { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
|
|
28
|
+
import { runBinary } from "./state/exec.js";
|
|
29
|
+
export { declaresLive, detectLiveEstate, estateOutputReads } from "./op/activities/live-detect.js";
|
|
30
|
+
/** The roots of `roots` (paths under `repo`) that keep their resources under choudoufu's live markers, in the order given. */
|
|
31
|
+
export function liveRoots(repo, roots, binary = "choudoufu") {
|
|
32
|
+
return roots.filter((r) => declaresLive(join(repo, r), binary));
|
|
33
|
+
}
|
|
34
|
+
/** A root's estate, as its sidecar or `live` block names it, and the estates whose recorded outputs it reads. */
|
|
35
|
+
export function estateOf(dir, binary = "choudoufu") {
|
|
36
|
+
const estate = detectLiveEstate(dir, binary);
|
|
37
|
+
return { ...(estate ? { estate } : {}), reads: estateOutputReads(dir, binary).map((r) => r.estate) };
|
|
38
|
+
}
|
|
39
|
+
const str = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
40
|
+
/** The setup in a `live-check -json` document, or undefined when the document is not JSON or comes from a choudoufu that does not print `estate_source`. */
|
|
41
|
+
export function parseLiveSetup(stdout) {
|
|
42
|
+
let doc;
|
|
43
|
+
try {
|
|
44
|
+
doc = JSON.parse(stdout);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (!doc || typeof doc !== "object" || typeof doc.estate_source !== "string")
|
|
50
|
+
return undefined;
|
|
51
|
+
const rs = doc.record_store && typeof doc.record_store === "object" ? doc.record_store : undefined;
|
|
52
|
+
const kind = str(rs?.kind);
|
|
53
|
+
const store = rs && kind
|
|
54
|
+
? {
|
|
55
|
+
kind,
|
|
56
|
+
bucket: str(rs.bucket) ?? "",
|
|
57
|
+
prefix: str(rs.prefix) ?? "",
|
|
58
|
+
source: str(rs.source) ?? "",
|
|
59
|
+
...(str(rs.declared_at) ? { declaredAt: str(rs.declared_at) } : {}),
|
|
60
|
+
...(str(rs.note) ? { note: str(rs.note) } : {}),
|
|
61
|
+
}
|
|
62
|
+
: undefined;
|
|
63
|
+
const estate = str(doc.estate);
|
|
64
|
+
return { ...(estate ? { estate } : {}), estateSource: doc.estate_source, ...(store ? { store } : {}) };
|
|
65
|
+
}
|
|
66
|
+
const known = new Map();
|
|
67
|
+
/** Keep what choudoufu resolved for a root's directory, for the readers below. */
|
|
68
|
+
export function rememberLiveSetup(dir, setup) {
|
|
69
|
+
known.set(resolve(dir), setup);
|
|
70
|
+
}
|
|
71
|
+
/** What choudoufu resolved for a root's directory in this process, if it was read. */
|
|
72
|
+
export function knownLiveSetup(dir) {
|
|
73
|
+
return known.get(resolve(dir));
|
|
74
|
+
}
|
|
75
|
+
/** For tests: forget every setup read so far. */
|
|
76
|
+
export function forgetLiveSetups() {
|
|
77
|
+
known.clear();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* `choudoufu live-check -json <dir>` for one root, run in the directory, and
|
|
81
|
+
* the setup it prints, remembered for the process. Undefined when the binary
|
|
82
|
+
* prints none (an older release, a root it cannot read, or no binary at
|
|
83
|
+
* all); the caller then reads the files. A root that live-check blocks still
|
|
84
|
+
* prints its setup, so the exit code is not read.
|
|
85
|
+
*/
|
|
86
|
+
export async function readLiveSetup(dir, options = {}) {
|
|
87
|
+
const at = resolve(dir);
|
|
88
|
+
const had = known.get(at);
|
|
89
|
+
if (had)
|
|
90
|
+
return had;
|
|
91
|
+
const exec = options.exec ?? runBinary;
|
|
92
|
+
let stdout;
|
|
93
|
+
try {
|
|
94
|
+
stdout = (await exec(options.binary ?? "choudoufu", ["live-check", "-json", at], at, options.env ?? process.env)).stdout;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const setup = parseLiveSetup(stdout);
|
|
100
|
+
if (setup)
|
|
101
|
+
known.set(at, setup);
|
|
102
|
+
return setup;
|
|
103
|
+
}
|
|
104
|
+
/** A live root's estate: choudoufu's resolved name when it was read, else the name its files write. */
|
|
105
|
+
export function resolvedEstate(dir, binary = "choudoufu") {
|
|
106
|
+
return knownLiveSetup(dir)?.estate ?? estateOf(dir, binary).estate;
|
|
107
|
+
}
|
|
108
|
+
const STORE_FROM = {
|
|
109
|
+
record_store: "from its record_store block",
|
|
110
|
+
backend: "derived from its backend block",
|
|
111
|
+
implied: "the local store, since no backend block gives one",
|
|
112
|
+
};
|
|
113
|
+
const ESTATE_FROM = {
|
|
114
|
+
explicit: "named by its live block",
|
|
115
|
+
tags: "from its tofu-estate tags",
|
|
116
|
+
backend_key: "from the backend key",
|
|
117
|
+
root_path: "from the root's path",
|
|
118
|
+
none: "none resolves",
|
|
119
|
+
};
|
|
120
|
+
/** The store as one phrase: `s3 bucket "acme" under tofu-records/prod/`. */
|
|
121
|
+
export function storePhrase(s) {
|
|
122
|
+
if (s.kind === "local")
|
|
123
|
+
return `the local directory ${s.bucket || ".tofu-records"} under ${s.prefix}`;
|
|
124
|
+
if (s.kind === "azurerm")
|
|
125
|
+
return `azurerm container ${s.bucket} under ${s.prefix}`;
|
|
126
|
+
if (s.kind === "kubernetes")
|
|
127
|
+
return `kubernetes namespace ${s.bucket} under ${s.prefix}`;
|
|
128
|
+
return `${s.kind} bucket "${s.bucket}" under ${s.prefix}`;
|
|
129
|
+
}
|
|
130
|
+
/** A root's setup on one line: where its records go, where that came from, and its estate. */
|
|
131
|
+
export function setupLine(root, setup) {
|
|
132
|
+
const s = setup.store;
|
|
133
|
+
const where = s ? `records in ${storePhrase(s)} (${STORE_FROM[s.source] ?? s.source}${s.declaredAt ? ` at ${s.declaredAt}` : ""})` : "no record store resolved";
|
|
134
|
+
const estate = setup.estate ? `estate "${setup.estate}" (${ESTATE_FROM[setup.estateSource] ?? setup.estateSource})` : "no estate resolves";
|
|
135
|
+
return `${root}: ${where}; ${estate}${s?.note ? `; ${s.note}` : ""}`;
|
|
136
|
+
}
|
|
137
|
+
/** The setup's store is the local directory, which is empty on every CI run. */
|
|
138
|
+
export const onLocalStore = (setup) => setup.store?.kind === "local";
|
|
139
|
+
/**
|
|
140
|
+
* The bucket core's check reads for a resolved store, or why there is none.
|
|
141
|
+
* `backend` is the root's backend block's string attributes, for the s3
|
|
142
|
+
* region and the azurerm subscription and resource group. s3 takes the
|
|
143
|
+
* region from there or the job, and an emulator's endpoint and keys from the
|
|
144
|
+
* job; gcs an emulator from `STORAGE_EMULATOR_HOST`; azurerm needs the
|
|
145
|
+
* subscription and resource group, from the backend block or
|
|
146
|
+
* `ARM_SUBSCRIPTION_ID`.
|
|
147
|
+
*/
|
|
148
|
+
export function bucketTarget(s, backend = {}, env = process.env) {
|
|
149
|
+
if (s.kind === "s3") {
|
|
150
|
+
const region = backend.region ?? env.AWS_REGION ?? env.AWS_DEFAULT_REGION;
|
|
151
|
+
if (!region)
|
|
152
|
+
return { skip: "no region: set region in the backend block or AWS_REGION" };
|
|
153
|
+
const endpoint = env.AWS_ENDPOINT_URL_S3 ?? env.AWS_ENDPOINT_URL;
|
|
154
|
+
const keys = env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY
|
|
155
|
+
? { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY, ...(env.AWS_SESSION_TOKEN ? { sessionToken: env.AWS_SESSION_TOKEN } : {}) }
|
|
156
|
+
: undefined;
|
|
157
|
+
if (endpoint && !keys)
|
|
158
|
+
return { skip: "AWS_ENDPOINT_URL is set with no AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY" };
|
|
159
|
+
return { target: { store: "s3", bucket: s.bucket, region, ...(endpoint ? { endpoint, credentials: keys } : {}) } };
|
|
160
|
+
}
|
|
161
|
+
if (s.kind === "gcs") {
|
|
162
|
+
const emulator = env.STORAGE_EMULATOR_HOST;
|
|
163
|
+
return { target: { store: "gcs", bucket: s.bucket, ...(emulator ? { endpoint: /^https?:\/\//.test(emulator) ? emulator : `http://${emulator}`, token: null } : {}) } };
|
|
164
|
+
}
|
|
165
|
+
if (s.kind === "azurerm") {
|
|
166
|
+
const [account, container] = s.bucket.split("/");
|
|
167
|
+
const subscriptionId = backend.subscription_id ?? env.ARM_SUBSCRIPTION_ID;
|
|
168
|
+
const resourceGroup = backend.resource_group_name;
|
|
169
|
+
if (!account || !container)
|
|
170
|
+
return { skip: "the store names no storage account and container" };
|
|
171
|
+
if (!subscriptionId || !resourceGroup)
|
|
172
|
+
return { skip: "the bucket check needs the subscription and resource group: set resource_group_name in the backend block, and subscription_id there or ARM_SUBSCRIPTION_ID" };
|
|
173
|
+
return { target: { store: "azblob", subscriptionId, resourceGroup, account, container } };
|
|
174
|
+
}
|
|
175
|
+
return { skip: `a ${s.kind} store has no bucket to check` };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Core's bucket check on a root's resolved store: the settings choudoufu
|
|
179
|
+
* refuses to open the bucket without. It reads only. A store with no bucket,
|
|
180
|
+
* or a check that cannot run, is skipped with the reason; nothing here throws.
|
|
181
|
+
* `check` is injectable for tests.
|
|
182
|
+
*/
|
|
183
|
+
export async function checkStoreBucket(s, backend = {}, env = process.env, check = checkBucket) {
|
|
184
|
+
if (s.kind === "local")
|
|
185
|
+
return { skipped: "the local store has no bucket" };
|
|
186
|
+
const t = bucketTarget(s, backend, env);
|
|
187
|
+
if ("skip" in t)
|
|
188
|
+
return { skipped: t.skip };
|
|
189
|
+
try {
|
|
190
|
+
return { checked: await check(t.target, { namespaces: s.prefix ? [s.prefix] : [] }) };
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
return { skipped: `the bucket could not be checked: ${e.message}` };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** The bucket check's outcome as lines: one for a correct bucket, else one per setting that did not pass, with its fix. */
|
|
197
|
+
export function bucketLines(root, outcome) {
|
|
198
|
+
if ("skipped" in outcome)
|
|
199
|
+
return [`${root}: bucket not checked: ${outcome.skipped}`];
|
|
200
|
+
const r = outcome.checked;
|
|
201
|
+
if (r.correct)
|
|
202
|
+
return [`${root}: bucket ${r.bucket} has every setting choudoufu needs (${r.settings.map((f) => f.setting).join(", ")})`];
|
|
203
|
+
return r.settings
|
|
204
|
+
.filter((f) => f.verdict !== "ok")
|
|
205
|
+
.map((f) => `${root}: bucket ${r.bucket}: ${f.setting} ${f.verdict === "unreadable" ? "could not be read" : "fails"}: ${f.found}${f.unwaivable ? " (no allow_insecure reaches this one)" : ""}${f.fix ? `; fix: ${f.fix}` : ""}`);
|
|
206
|
+
}
|
package/dist/manifest.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A state migration's history, read back from the lines chant wrote
|
|
3
|
+
* (chant#4910): each `finished` line of the migration's gated requests
|
|
4
|
+
* (`_gates/<op>/applied.jsonl` on `chant/lifecycle`, written by core's
|
|
5
|
+
* `runStateMigration` with `migrationFacts`), as one history line per run,
|
|
6
|
+
* and the revert of a migration that applied, each root back to the version
|
|
7
|
+
* the migration recorded before it wrote.
|
|
8
|
+
*
|
|
9
|
+
* The history line is the form terragucci's `done.jsonl` has always held,
|
|
10
|
+
* so a product that kept such a file before chant ran its gate reads the two
|
|
11
|
+
* together ({@link migrationHistory}). Besides core's facts, a finished
|
|
12
|
+
* line's detail may carry the product's `file_digest`, its change
|
|
13
|
+
* (`migration_change`, else `change`) and the migration a revert put back
|
|
14
|
+
* (`revert`); they are read when there.
|
|
15
|
+
*
|
|
16
|
+
* Lifted from terragucci's `finishedMigrationLines`, `migrationHistory` and
|
|
17
|
+
* `revertMigration` (migrate.ts), so terragucci deletes its copies and keeps
|
|
18
|
+
* its file's words.
|
|
19
|
+
*/
|
|
20
|
+
import { type Restore } from "./state-migration.js";
|
|
21
|
+
/** One root of a history line: where its state is, and its version and digest before and after. */
|
|
22
|
+
export interface MigrationHistoryRoot {
|
|
23
|
+
root: string;
|
|
24
|
+
location: string | null;
|
|
25
|
+
before: string | null;
|
|
26
|
+
after: string | null;
|
|
27
|
+
before_digest: string | null;
|
|
28
|
+
after_digest: string | null;
|
|
29
|
+
/** A backend move's source, and the version read there. */
|
|
30
|
+
source?: string | null;
|
|
31
|
+
source_version?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** One run of a migration, as its history holds it. */
|
|
34
|
+
export interface MigrationHistoryLine {
|
|
35
|
+
version: 1;
|
|
36
|
+
kind: "migration";
|
|
37
|
+
op: string;
|
|
38
|
+
/** The migration's name. */
|
|
39
|
+
gate: string;
|
|
40
|
+
timestamp: string;
|
|
41
|
+
planDigest?: string;
|
|
42
|
+
file_digest?: string;
|
|
43
|
+
/** `applied` or `failed`. A run refused under the locks wrote nothing and has no line. */
|
|
44
|
+
result: string;
|
|
45
|
+
approvedBy?: string;
|
|
46
|
+
/** The migration's change: `moves`, `backends`, `revert`, `retag`, `adopt`, as the product's detail names it. */
|
|
47
|
+
change: string | null;
|
|
48
|
+
/** The migration a revert put back. */
|
|
49
|
+
revert?: string;
|
|
50
|
+
roots: MigrationHistoryRoot[];
|
|
51
|
+
error?: string;
|
|
52
|
+
/** `finished`: read from a gated request's finished line. */
|
|
53
|
+
source?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The finished lines of a migration op's `applied.jsonl` as history lines,
|
|
57
|
+
* oldest first. A line without a `result` is skipped (the migration threw
|
|
58
|
+
* before it ended), and so is a run refused under the lock, which wrote
|
|
59
|
+
* nothing.
|
|
60
|
+
*/
|
|
61
|
+
export declare function finishedMigrationLines(appliedText: string, op: string): MigrationHistoryLine[];
|
|
62
|
+
/** Where a migration op's history is kept on `chant/lifecycle`: chant's `applied.jsonl`, and the product's own earlier file, if it kept one. */
|
|
63
|
+
export interface MigrationHistoryFiles {
|
|
64
|
+
op: string;
|
|
65
|
+
/** The product's file of history lines written before chant ran the gate, such as `_gates/tf-migrate/done.jsonl`. */
|
|
66
|
+
earlier?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A migration op's history as history-line text, one JSON line each: the
|
|
70
|
+
* product's earlier lines first, then each finished line of chant's gated
|
|
71
|
+
* requests. The newest line of a migration wins. `show` reads a path on
|
|
72
|
+
* `chant/lifecycle` as the caller wants it read (the remote ref as last
|
|
73
|
+
* fetched, say), answering "" for a path that is not there.
|
|
74
|
+
*/
|
|
75
|
+
export declare function migrationHistory(show: (path: string) => string, files: MigrationHistoryFiles): string;
|
|
76
|
+
/** The newest line of each migration that ran its writes, by name. */
|
|
77
|
+
export declare function doneMigrations(history: string): Map<string, {
|
|
78
|
+
status: string;
|
|
79
|
+
file_digest?: string;
|
|
80
|
+
timestamp: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** The name a revert of `name` takes. */
|
|
83
|
+
export declare const revertName: (name: string) => string;
|
|
84
|
+
/** A revert of a migration that applied: its name, each root's restore, and the migration file that asks for it. */
|
|
85
|
+
export interface MigrationRevert {
|
|
86
|
+
name: string;
|
|
87
|
+
restores: Restore[];
|
|
88
|
+
/** The file, `revert:` and `restores:`, under the caller's comment lines. */
|
|
89
|
+
text: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The revert of a migration that applied, from its newest applied line in
|
|
93
|
+
* `history`: each root back to the version the migration recorded before it
|
|
94
|
+
* wrote, from the version it recorded after (the write is refused when a
|
|
95
|
+
* state moved past it). A backend move, a revert, an estate retag or an
|
|
96
|
+
* estate adoption is not put back this way, and a root whose bucket kept no
|
|
97
|
+
* version cannot be put back: each throws {@link MigrationError} naming why.
|
|
98
|
+
* `where` names the history in the refusal; `header` are the file's comment
|
|
99
|
+
* lines, without their `# `.
|
|
100
|
+
*/
|
|
101
|
+
export declare function revertMigration(name: string, history: string, options?: {
|
|
102
|
+
where?: string;
|
|
103
|
+
header?: readonly string[];
|
|
104
|
+
}): MigrationRevert;
|
|
105
|
+
//# sourceMappingURL=migration-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-history.d.ts","sourceRoot":"","sources":["../src/migration-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjE,mGAAmG;AACnG,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MA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qB,GAAG,MAAM,CAIrG;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAYxH;AAED,yCAAyC;AACzC,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAA0B,CAAC;AAErE,oHAAoH;AACpH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAAG,eAAe,CAkC5I"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A state migration's history, read back from the lines chant wrote
|
|
3
|
+
* (chant#4910): each `finished` line of the migration's gated requests
|
|
4
|
+
* (`_gates/<op>/applied.jsonl` on `chant/lifecycle`, written by core's
|
|
5
|
+
* `runStateMigration` with `migrationFacts`), as one history line per run,
|
|
6
|
+
* and the revert of a migration that applied, each root back to the version
|
|
7
|
+
* the migration recorded before it wrote.
|
|
8
|
+
*
|
|
9
|
+
* The history line is the form terragucci's `done.jsonl` has always held,
|
|
10
|
+
* so a product that kept such a file before chant ran its gate reads the two
|
|
11
|
+
* together ({@link migrationHistory}). Besides core's facts, a finished
|
|
12
|
+
* line's detail may carry the product's `file_digest`, its change
|
|
13
|
+
* (`migration_change`, else `change`) and the migration a revert put back
|
|
14
|
+
* (`revert`); they are read when there.
|
|
15
|
+
*
|
|
16
|
+
* Lifted from terragucci's `finishedMigrationLines`, `migrationHistory` and
|
|
17
|
+
* `revertMigration` (migrate.ts), so terragucci deletes its copies and keeps
|
|
18
|
+
* its file's words.
|
|
19
|
+
*/
|
|
20
|
+
import { MigrationError } from "./state-migration.js";
|
|
21
|
+
/**
|
|
22
|
+
* The finished lines of a migration op's `applied.jsonl` as history lines,
|
|
23
|
+
* oldest first. A line without a `result` is skipped (the migration threw
|
|
24
|
+
* before it ended), and so is a run refused under the lock, which wrote
|
|
25
|
+
* nothing.
|
|
26
|
+
*/
|
|
27
|
+
export function finishedMigrationLines(appliedText, op) {
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const l of appliedText.split("\n").map((x) => x.trim()).filter(Boolean)) {
|
|
30
|
+
let r;
|
|
31
|
+
try {
|
|
32
|
+
r = JSON.parse(l);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (r.version !== 1 || r.kind !== "finished" || typeof r.gate !== "string" || typeof r.timestamp !== "string")
|
|
38
|
+
continue;
|
|
39
|
+
const d = r.detail && typeof r.detail === "object" ? r.detail : {};
|
|
40
|
+
if (typeof d.result !== "string" || d.result === "refused")
|
|
41
|
+
continue;
|
|
42
|
+
const str = (k) => (typeof d[k] === "string" ? d[k] : null);
|
|
43
|
+
const roots = (str("roots") ?? "")
|
|
44
|
+
.split(",")
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.map((root) => ({
|
|
47
|
+
root,
|
|
48
|
+
location: str(`${root}.location`),
|
|
49
|
+
before: str(`${root}.before`),
|
|
50
|
+
after: str(`${root}.after`),
|
|
51
|
+
before_digest: str(`${root}.before_digest`),
|
|
52
|
+
after_digest: str(`${root}.after_digest`),
|
|
53
|
+
...(str(`${root}.source`) ? { source: str(`${root}.source`), source_version: str(`${root}.source_version`) } : {}),
|
|
54
|
+
}));
|
|
55
|
+
out.push({
|
|
56
|
+
version: 1,
|
|
57
|
+
kind: "migration",
|
|
58
|
+
op,
|
|
59
|
+
gate: r.gate,
|
|
60
|
+
timestamp: r.timestamp,
|
|
61
|
+
...(typeof r.planDigest === "string" ? { planDigest: r.planDigest } : {}),
|
|
62
|
+
...(str("file_digest") ? { file_digest: str("file_digest") } : {}),
|
|
63
|
+
result: d.result,
|
|
64
|
+
...(str("approved_by") ? { approvedBy: str("approved_by") } : {}),
|
|
65
|
+
change: str("migration_change") ?? str("change"),
|
|
66
|
+
...(str("revert") ? { revert: str("revert") } : {}),
|
|
67
|
+
roots,
|
|
68
|
+
...(str("error") ? { error: str("error") } : {}),
|
|
69
|
+
source: "finished",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A migration op's history as history-line text, one JSON line each: the
|
|
76
|
+
* product's earlier lines first, then each finished line of chant's gated
|
|
77
|
+
* requests. The newest line of a migration wins. `show` reads a path on
|
|
78
|
+
* `chant/lifecycle` as the caller wants it read (the remote ref as last
|
|
79
|
+
* fetched, say), answering "" for a path that is not there.
|
|
80
|
+
*/
|
|
81
|
+
export function migrationHistory(show, files) {
|
|
82
|
+
const earlier = files.earlier ? show(files.earlier).split("\n").map((l) => l.trim()).filter(Boolean) : [];
|
|
83
|
+
const finished = finishedMigrationLines(show(`_gates/${files.op}/applied.jsonl`), files.op).map((l) => JSON.stringify(l));
|
|
84
|
+
return [...earlier, ...finished].join("\n") + "\n";
|
|
85
|
+
}
|
|
86
|
+
/** The newest line of each migration that ran its writes, by name. */
|
|
87
|
+
export function doneMigrations(history) {
|
|
88
|
+
const out = new Map();
|
|
89
|
+
for (const line of history.split("\n").map((l) => l.trim()).filter(Boolean)) {
|
|
90
|
+
try {
|
|
91
|
+
const r = JSON.parse(line);
|
|
92
|
+
if (r.kind !== "migration" || typeof r.gate !== "string" || typeof r.timestamp !== "string")
|
|
93
|
+
continue;
|
|
94
|
+
out.set(r.gate, { status: String(r.result), ...(typeof r.file_digest === "string" ? { file_digest: r.file_digest } : {}), timestamp: r.timestamp });
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** The name a revert of `name` takes. */
|
|
103
|
+
export const revertName = (name) => `${name}-revert`;
|
|
104
|
+
/**
|
|
105
|
+
* The revert of a migration that applied, from its newest applied line in
|
|
106
|
+
* `history`: each root back to the version the migration recorded before it
|
|
107
|
+
* wrote, from the version it recorded after (the write is refused when a
|
|
108
|
+
* state moved past it). A backend move, a revert, an estate retag or an
|
|
109
|
+
* estate adoption is not put back this way, and a root whose bucket kept no
|
|
110
|
+
* version cannot be put back: each throws {@link MigrationError} naming why.
|
|
111
|
+
* `where` names the history in the refusal; `header` are the file's comment
|
|
112
|
+
* lines, without their `# `.
|
|
113
|
+
*/
|
|
114
|
+
export function revertMigration(name, history, options = {}) {
|
|
115
|
+
let line;
|
|
116
|
+
for (const l of history.split("\n").map((x) => x.trim()).filter(Boolean)) {
|
|
117
|
+
try {
|
|
118
|
+
const r = JSON.parse(l);
|
|
119
|
+
if (r.kind === "migration" && r.gate === name && r.result === "applied")
|
|
120
|
+
line = r;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!line)
|
|
127
|
+
throw new MigrationError(`chant/lifecycle records no applied migration ${name}${options.where ? `, ${options.where}` : ""}`);
|
|
128
|
+
if (line.change === "backends")
|
|
129
|
+
throw new MigrationError(`${name} moved states to new backends; put it back with a backend move the other way, which reads each state where it is now`);
|
|
130
|
+
if (line.change === "revert")
|
|
131
|
+
throw new MigrationError(`${name} is a revert; apply the migration it put back again with a new migration file`);
|
|
132
|
+
if (line.change === "retag")
|
|
133
|
+
throw new MigrationError(`${name} retagged resources between estates; put it back with a moves migration the other way`);
|
|
134
|
+
if (line.change === "adopt")
|
|
135
|
+
throw new MigrationError(`${name} adopted a state into an estate and left the state where it was; to go back, put the backend block back in place of the live block`);
|
|
136
|
+
const roots = Array.isArray(line.roots) ? line.roots : [];
|
|
137
|
+
const problems = [];
|
|
138
|
+
const restores = roots.map((r) => {
|
|
139
|
+
const root = String(r.root);
|
|
140
|
+
if (typeof r.location !== "string" || !/^(s3|gs|az):\/\//.test(r.location))
|
|
141
|
+
problems.push(`${root}: its backend keeps no versions, so there is no earlier state to put back`);
|
|
142
|
+
if (r.before === null && r.before_digest !== null)
|
|
143
|
+
problems.push(`${root}: its bucket kept no version before ${name} wrote, so there is no earlier state to put back`);
|
|
144
|
+
if (typeof r.after !== "string")
|
|
145
|
+
problems.push(`${root}: ${name} recorded no version after its write, so a later change could not be told apart`);
|
|
146
|
+
return { root, location: String(r.location), version_id: typeof r.before === "string" ? r.before : null, from_version_id: typeof r.after === "string" ? r.after : null };
|
|
147
|
+
});
|
|
148
|
+
if (problems.length > 0)
|
|
149
|
+
throw new MigrationError(`${name} cannot be put back:\n ${problems.join("\n ")}`);
|
|
150
|
+
const q = (v) => (v === null ? "null" : JSON.stringify(v));
|
|
151
|
+
const text = [
|
|
152
|
+
...(options.header ?? [`Puts back the states migration ${name} wrote, to the versions it recorded before it wrote them.`]).map((h) => `# ${h}`),
|
|
153
|
+
`revert: ${name}`,
|
|
154
|
+
"restores:",
|
|
155
|
+
...restores.flatMap((r) => [` - root: ${r.root}`, ` location: ${r.location}`, ` version_id: ${q(r.version_id)}`, ` from_version_id: ${q(r.from_version_id)}`]),
|
|
156
|
+
"",
|
|
157
|
+
].join("\n");
|
|
158
|
+
return { name: revertName(name), restores, text };
|
|
159
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StaticRow } from "./types.js";
|
|
2
|
+
export { MODULE_CATALOG_FLOOR } from "../chant-floors.js";
|
|
2
3
|
export type { StaticRefusal, StaticRow, StaticMeasurement, StaticSource } from "./types.js";
|
|
3
4
|
/** Where the vendored rows came from. */
|
|
4
5
|
export declare const MODULE_CATALOG_SOURCE: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module-catalog/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module-catalog/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEzF,yCAAyC;AACzC,eAAO,MAAM,qBAAqB;aAChC,IAAI,EAAE,qBAAqB;aAC3B,IAAI;aACJ,MAAM;IACN,0CAA0C;aAC1C,IAAI;IACJ,4DAA4D;aAC5D,UAAU;IACV,4EAA4E;aAC5E,WAAW;CACH,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,yBAAyB,8DAA8D,CAAC;AAErG,oCAAoC;AACpC,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEzC,qCAAqC;AACrC,eAAO,MAAM,UAAU,EAAE,SAAS,SAAS,EAAgB,CAAC;AAE5D,4EAA4E;AAC5E,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,OAAO,GAAG,SAAS,CAAC;IACnE,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQxE;AAED,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGtE;AAiBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAoCpG"}
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
* it counts static rows only.
|
|
15
15
|
*
|
|
16
16
|
* This subpath, `@intentius/chant-lexicon-terraform/module-catalog`, imports
|
|
17
|
-
* nothing but its own data
|
|
17
|
+
* nothing but its own data and the lexicon's floors file (#4916), so a
|
|
18
|
+
* consumer can load it on its own.
|
|
18
19
|
*/
|
|
19
20
|
import { SOURCE_COMMIT, SOURCE_PATH, STATIC_MEASUREMENT, STATIC_ROWS } from "./static-tier.js";
|
|
21
|
+
export { MODULE_CATALOG_FLOOR } from "../chant-floors.js";
|
|
20
22
|
/** Where the vendored rows came from. */
|
|
21
23
|
export const MODULE_CATALOG_SOURCE = {
|
|
22
24
|
repo: "INTENTIUS/choudoufu",
|
|
@@ -49,4 +49,19 @@ export interface LivePolicyVerbs {
|
|
|
49
49
|
undeclaredUntagged?: string;
|
|
50
50
|
}
|
|
51
51
|
export declare function detectLivePolicyVerbs(dir: string, binary?: string): LivePolicyVerbs | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the root module directory `dir` keeps its resources under
|
|
54
|
+
* choudoufu's live markers (chant#4910): an `estate.chdf.hcl` sidecar, or a
|
|
55
|
+
* `live` block in a `terraform` block, whether or not it names an estate.
|
|
56
|
+
*/
|
|
57
|
+
export declare function declaresLive(dir: string, binary?: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Each `data "terraform_estate_outputs"` block of the root module directory
|
|
60
|
+
* `dir` (chant#4910): its label and the estate whose recorded outputs it
|
|
61
|
+
* reads. A block that names no estate as a literal is left out.
|
|
62
|
+
*/
|
|
63
|
+
export declare function estateOutputReads(dir: string, binary?: string): Array<{
|
|
64
|
+
name: string;
|
|
65
|
+
estate: string;
|
|
66
|
+
}>;
|
|
52
67
|
//# sourceMappingURL=live-detect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-detect.d.ts","sourceRoot":"","sources":["../../../src/op/activities/live-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA2EH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,MAAM,GAAG,SAAS,CAgCtF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAe;IAC9B,+HAA+H;IAC/H,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wGAAwG;IACxG,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,eAAe,GAAG,SAAS,CAgCpG"}
|
|
1
|
+
{"version":3,"file":"live-detect.d.ts","sourceRoot":"","sources":["../../../src/op/activities/live-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA2EH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,MAAM,GAAG,SAAS,CAgCtF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,eAAe;IAC9B,+HAA+H;IAC/H,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wGAAwG;IACxG,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,eAAe,GAAG,SAAS,CAgCpG;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,OAAO,CAevE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAc,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA2C5G"}
|
|
@@ -166,3 +166,97 @@ export function detectLivePolicyVerbs(dir, binary = "choudoufu") {
|
|
|
166
166
|
}
|
|
167
167
|
return undefined;
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Whether the root module directory `dir` keeps its resources under
|
|
171
|
+
* choudoufu's live markers (chant#4910): an `estate.chdf.hcl` sidecar, or a
|
|
172
|
+
* `live` block in a `terraform` block, whether or not it names an estate.
|
|
173
|
+
*/
|
|
174
|
+
export function declaresLive(dir, binary = "choudoufu") {
|
|
175
|
+
if (existsSync(join(dir, LIVE_SIDECAR_FILENAME)))
|
|
176
|
+
return true;
|
|
177
|
+
let names;
|
|
178
|
+
try {
|
|
179
|
+
names = liveFiles(dir, binary);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return names.some((name) => {
|
|
185
|
+
try {
|
|
186
|
+
return liveBlocksOf(name, stripLineComments(name, readFileSync(join(dir, name), "utf-8"))).length > 0;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Each `data "terraform_estate_outputs"` block of the root module directory
|
|
195
|
+
* `dir` (chant#4910): its label and the estate whose recorded outputs it
|
|
196
|
+
* reads. A block that names no estate as a literal is left out.
|
|
197
|
+
*/
|
|
198
|
+
export function estateOutputReads(dir, binary = "choudoufu") {
|
|
199
|
+
let names;
|
|
200
|
+
try {
|
|
201
|
+
names = liveFiles(dir, binary);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
const out = [];
|
|
207
|
+
for (const name of names) {
|
|
208
|
+
let source;
|
|
209
|
+
try {
|
|
210
|
+
source = readFileSync(join(dir, name), "utf-8");
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (isJsonConfigFile(name)) {
|
|
216
|
+
let doc;
|
|
217
|
+
try {
|
|
218
|
+
doc = JSON.parse(source);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const data = [doc?.data].flat();
|
|
224
|
+
for (const d of data) {
|
|
225
|
+
const reads = d && typeof d === "object" ? d.terraform_estate_outputs : undefined;
|
|
226
|
+
for (const r of [reads].flat()) {
|
|
227
|
+
if (!r || typeof r !== "object")
|
|
228
|
+
continue;
|
|
229
|
+
for (const [label, body] of Object.entries(r)) {
|
|
230
|
+
const estate = [body].flat().map((b) => nonEmpty(b?.estate)).find((e) => e !== undefined);
|
|
231
|
+
if (estate)
|
|
232
|
+
out.push({ name: label, estate });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const text = stripLineComments(name, source);
|
|
239
|
+
for (const m of text.matchAll(/\bdata\s+"terraform_estate_outputs"\s+"([^"]+)"\s*\{/g)) {
|
|
240
|
+
const body = bodyAt(text, m.index + m[0].length - 1);
|
|
241
|
+
const estate = body === undefined ? undefined : extractEstateAttr(body);
|
|
242
|
+
if (estate)
|
|
243
|
+
out.push({ name: m[1], estate });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
/** An HCL file's text with its `#` and `//` line comments blanked; a JSON file's as it is. */
|
|
249
|
+
function stripLineComments(name, source) {
|
|
250
|
+
return isJsonConfigFile(name) ? source : source.replace(/^\s*(#|\/\/).*$/gm, "");
|
|
251
|
+
}
|
|
252
|
+
/** The inner text of the `{ ... }` block whose opening brace is at `open`, or undefined when it never closes. */
|
|
253
|
+
function bodyAt(source, open) {
|
|
254
|
+
let depth = 0;
|
|
255
|
+
for (let i = open; i < source.length; i++) {
|
|
256
|
+
if (source[i] === "{")
|
|
257
|
+
depth++;
|
|
258
|
+
else if (source[i] === "}" && --depth === 0)
|
|
259
|
+
return source.slice(open + 1, i);
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|