@intentius/behold 0.29.52 → 0.29.54

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/demos.json CHANGED
@@ -141,7 +141,10 @@
141
141
  "setup": "bash scripts/emulators-up.sh",
142
142
  "serve": {
143
143
  "local": true,
144
- "env": "local"
144
+ "env": "local",
145
+ "processEnv": {
146
+ "GCP_PROJECT_ID": "three-cloud"
147
+ }
145
148
  }
146
149
  },
147
150
  {
package/dist/cli.js CHANGED
@@ -17746,6 +17746,8 @@ function projectAzureLogical(ir, env) {
17746
17746
  (refOut.get(e.from) ?? refOut.set(e.from, /* @__PURE__ */ new Set()).get(e.from)).add(e.to);
17747
17747
  }
17748
17748
  const RG_TITLE = env ? `resource group ${env}` : "resource group";
17749
+ const subscription = azure.map((n) => JSON.stringify(n).match(/\/subscriptions\/([0-9a-f-]{36})\//i)?.[1]).find(Boolean);
17750
+ const SUBSCRIPTION_TITLE = subscription ? `Azure subscription ${subscription}` : "Azure subscription";
17749
17751
  const vnetTitle = (v) => `VNet ${vnetCidr(v) ?? resourceName(v) ?? v.id}`;
17750
17752
  const subnetTitle = (s) => `subnet ${strAttr(s, "addressPrefix") ?? subnetShortName(s) ?? s.id}`;
17751
17753
  const guardedBy = /* @__PURE__ */ new Map();
@@ -17877,6 +17879,7 @@ function projectAzureLogical(ir, env) {
17877
17879
  const nsg = guardedSubnet ? guardedBy.get(guardedSubnet.id) : void 0;
17878
17880
  return nsg ? { ...n, attrs: { ...n.attrs, _nsg: nsg } } : n;
17879
17881
  });
17882
+ if (byContainer[RG_TITLE]) child(SUBSCRIPTION_TITLE, RG_TITLE);
17880
17883
  return { ir: { nodes, edges, groups: {} }, byContainer };
17881
17884
  }
17882
17885
 
@@ -17909,6 +17912,22 @@ var GCP_FABRIC_KINDS = /* @__PURE__ */ new Set([
17909
17912
  // chant's own annotation carrier
17910
17913
  "chant:gcp:defaultAnnotations"
17911
17914
  ]);
17915
+ var SUBNETWORK_KIND = "GCP::Compute::Subnetwork";
17916
+ function metadataName(node) {
17917
+ const name = node.attrs?.metadata?.name;
17918
+ return typeof name === "string" && name.length > 0 ? name : void 0;
17919
+ }
17920
+ function subnetsNamed(value, out = []) {
17921
+ if (!value || typeof value !== "object") return out;
17922
+ for (const [k, v] of Object.entries(value)) {
17923
+ if (k === "subnetworkRef" && v && typeof v === "object") {
17924
+ const name = v.name ?? v.external;
17925
+ if (typeof name === "string") out.push(name.split("/").pop());
17926
+ } else if (k === "subnetwork" && typeof v === "string") out.push(v.split("/").pop());
17927
+ else subnetsNamed(v, out);
17928
+ }
17929
+ return out;
17930
+ }
17912
17931
  var PROJECT_ID_ANNOTATION = "cnrm.cloud.google.com/project-id";
17913
17932
  function strAttr2(node, key3) {
17914
17933
  const v = node.attrs?.[key3];
@@ -17920,6 +17939,10 @@ function declaredProject(nodes) {
17920
17939
  const value = annotations?.[PROJECT_ID_ANNOTATION];
17921
17940
  if (typeof value === "string" && value.length > 0) return value;
17922
17941
  }
17942
+ for (const n of nodes) {
17943
+ const ref2 = n.attrs?.projectRef ?? n.attrs?.spec?.projectRef;
17944
+ if (typeof ref2?.external === "string" && ref2.external.length > 0) return ref2.external.replace(/^projects\//, "");
17945
+ }
17923
17946
  return void 0;
17924
17947
  }
17925
17948
  function collectRefs(v, out) {
@@ -17934,7 +17957,7 @@ function projectGcpLogical(ir, env) {
17934
17957
  const componentOf = componentNamer(gcp, ir.groups);
17935
17958
  const byId = new Map(gcp.map((n) => [n.id, n]));
17936
17959
  const project = declaredProject(gcp) ?? env;
17937
- const PROJECT_TITLE = project ? `project ${project}` : "project";
17960
+ const PROJECT_TITLE = project ? `GCP project ${project}` : "GCP project";
17938
17961
  const GLOBAL = "global";
17939
17962
  const locationTitle = (loc) => `location ${loc}`;
17940
17963
  const refOut = /* @__PURE__ */ new Map();
@@ -17957,14 +17980,28 @@ function projectGcpLogical(ir, env) {
17957
17980
  };
17958
17981
  const locations = /* @__PURE__ */ new Set();
17959
17982
  for (const n of gcp) {
17960
- const loc = strAttr2(n, "location");
17983
+ const loc = strAttr2(n, "location") ?? (n.kind === SUBNETWORK_KIND ? strAttr2(n, "region") : void 0);
17961
17984
  if (loc) locations.add(loc);
17962
17985
  }
17963
17986
  for (const loc of [...locations].sort()) child(PROJECT_TITLE, locationTitle(loc));
17987
+ const subnetBox = /* @__PURE__ */ new Map();
17988
+ const regionOfBox = /* @__PURE__ */ new Map();
17989
+ for (const n of gcp) {
17990
+ if (n.kind !== SUBNETWORK_KIND) continue;
17991
+ const name = metadataName(n) ?? n.id;
17992
+ const cidr = strAttr2(n, "ipCidrRange");
17993
+ const network = n.attrs?.networkRef?.name;
17994
+ const title = `subnet ${cidr ?? name}${typeof network === "string" ? ` \xB7 ${network}` : ""}`;
17995
+ const region = strAttr2(n, "region") ?? strAttr2(n, "location");
17996
+ child(region ? locationTitle(region) : PROJECT_TITLE, title);
17997
+ subnetBox.set(name, title);
17998
+ if (region) regionOfBox.set(title, region);
17999
+ }
17964
18000
  const placeOf = /* @__PURE__ */ new Map();
17965
18001
  for (const n of headline) {
18002
+ const subnet = subnetsNamed(n.attrs).map((name) => subnetBox.get(name)).find(Boolean);
17966
18003
  const loc = strAttr2(n, "location");
17967
- placeOf.set(n.id, loc ? locationTitle(loc) : GLOBAL);
18004
+ placeOf.set(n.id, subnet ?? (loc ? locationTitle(loc) : GLOBAL));
17968
18005
  }
17969
18006
  const byComponent = /* @__PURE__ */ new Map();
17970
18007
  for (const n of headline) {
@@ -17988,7 +18025,7 @@ function projectGcpLogical(ir, env) {
17988
18025
  }
17989
18026
  for (const place of places) {
17990
18027
  if (place === GLOBAL) child(PROJECT_TITLE, GLOBAL);
17991
- const part = `${component} \xB7 ${place.replace(/^location /, "")}`;
18028
+ const part = `${component} \xB7 ${regionOfBox.get(place) ?? place.replace(/^location /, "")}`;
17992
18029
  child(place, part);
17993
18030
  for (const m of members) if (placeOf.get(m.id) === place) child(part, m.id);
17994
18031
  }
@@ -18406,6 +18443,7 @@ var NO_CONTRACT_KINDS = /* @__PURE__ */ new Set([
18406
18443
  "AWS::EC2::SecurityGroupIngress"
18407
18444
  ]);
18408
18445
  var REGION_RE = /\b([a-z]{2}-[a-z]+-\d)\b/;
18446
+ var ACCOUNT_RE = /arn:aws[a-z-]*:[a-z0-9-]*:[a-z0-9-]*:(\d{12}):/;
18409
18447
  var WORD_RE = /[A-Za-z][A-Za-z0-9]*/g;
18410
18448
  function isExample(node) {
18411
18449
  return (node.sourceLoc?.file ?? "").includes("examples/");
@@ -18693,13 +18731,36 @@ function projectLogical(ir) {
18693
18731
  };
18694
18732
  const subnetTitle = (subnetId) => `${subnetScope(subnetId)} subnet ${strAttr3(byId.get(subnetId), "CidrBlock") ?? subnetId}`;
18695
18733
  const GLOBAL = "regional & global";
18734
+ const memberOf = memberNamer(ir.groups);
18735
+ const ownRefs = /* @__PURE__ */ new Map();
18736
+ for (const [from, tos] of refOut) {
18737
+ const m = memberOf(byId.get(from));
18738
+ ownRefs.set(from, new Set([...tos].filter((t2) => memberOf(byId.get(t2)) === m)));
18739
+ }
18740
+ const subnetsOf = (start) => {
18741
+ const seen = /* @__PURE__ */ new Set([start]);
18742
+ let frontier = [...ownRefs.get(start) ?? []];
18743
+ for (let depth = 0; depth < 8 && frontier.length; depth++) {
18744
+ const hit = [...new Set(frontier.filter((id) => subnetIds.has(id)))];
18745
+ if (hit.length) return hit.sort();
18746
+ const next = [];
18747
+ for (const id of frontier) {
18748
+ if (seen.has(id)) continue;
18749
+ seen.add(id);
18750
+ for (const r of ownRefs.get(id) ?? []) if (!seen.has(r)) next.push(r);
18751
+ }
18752
+ frontier = next;
18753
+ }
18754
+ return [];
18755
+ };
18696
18756
  const headline = aws.filter((n) => HEADLINE_KINDS.has(n.kind));
18697
18757
  const placeOf = /* @__PURE__ */ new Map();
18698
18758
  for (const n of headline) {
18699
- const subnet = nearestByRef(n.id, subnetIds, refOut);
18700
- if (subnet) placeOf.set(n.id, { kind: "subnet", subnet, vpc: nearestByRef(subnet, vpcIds, refOut) });
18759
+ const subnets = subnetsOf(n.id);
18760
+ const scopes = new Set(subnets.map(subnetScope));
18761
+ if (subnets.length && scopes.size === 1) placeOf.set(n.id, { kind: "subnet", subnets, vpc: nearestByRef(subnets[0], vpcIds, ownRefs) });
18701
18762
  else {
18702
- const vpc = nearestByRef(n.id, vpcIds, refOut) ?? igwToVpc.get(n.id);
18763
+ const vpc = (subnets.length ? nearestByRef(subnets[0], vpcIds, ownRefs) : void 0) ?? nearestByRef(n.id, vpcIds, ownRefs) ?? igwToVpc.get(n.id);
18703
18764
  placeOf.set(n.id, vpc ? { kind: "vpc", vpc } : { kind: "global" });
18704
18765
  }
18705
18766
  }
@@ -18708,26 +18769,41 @@ function projectLogical(ir) {
18708
18769
  const arr6 = byContainer[parent] ?? (byContainer[parent] = []);
18709
18770
  if (!arr6.includes(c)) arr6.push(c);
18710
18771
  };
18711
- const ensureSubnet = (subnetId, vpcId) => {
18712
- const t2 = subnetTitle(subnetId);
18772
+ const subnetVpc = new Map([...subnetIds].map((id) => [id, nearestByRef(id, vpcIds, ownRefs)]));
18773
+ const tierOf = (id) => [...subnetIds].filter((s) => subnetVpc.get(s) === subnetVpc.get(id) && subnetScope(s) === subnetScope(id)).sort();
18774
+ const tierTitle = (ids) => {
18775
+ const tier = tierOf(ids[0]);
18776
+ return tier.length === 1 ? subnetTitle(tier[0]) : `${subnetScope(tier[0])} subnets ${tier.map((id) => strAttr3(byId.get(id), "CidrBlock") ?? id).join(", ")}`;
18777
+ };
18778
+ const ensureSubnet = (ids, vpcId) => {
18779
+ const t2 = tierTitle(ids);
18713
18780
  if (vpcId) child(vpcTitle(vpcId), t2);
18714
18781
  return t2;
18715
18782
  };
18783
+ const placeTitle = (p) => p.kind === "subnet" ? ensureSubnet(p.subnets, p.vpc) : p.kind === "vpc" ? vpcTitle(p.vpc) : GLOBAL;
18784
+ const placeKey = (p) => p.kind === "subnet" ? `s:${tierOf(p.subnets[0]).join(",")}` : p.kind === "vpc" ? `v:${p.vpc}` : "g";
18716
18785
  const byComponent = /* @__PURE__ */ new Map();
18717
18786
  for (const n of headline) (byComponent.get(componentOf(n)) ?? byComponent.set(componentOf(n), []).get(componentOf(n))).push(n);
18718
18787
  for (const [component, members] of byComponent) {
18719
18788
  const places = members.map((m) => placeOf.get(m.id));
18720
- const subnets = new Set(places.map((p) => p.kind === "subnet" ? p.subnet : ""));
18789
+ const keys = new Set(places.map(placeKey));
18721
18790
  const vpcs = new Set(places.map((p) => p.kind === "subnet" ? p.vpc : p.kind === "vpc" ? p.vpc : void 0).filter((v) => !!v));
18722
- let parent;
18723
- if (subnets.size === 1 && !subnets.has("")) {
18724
- const p = places[0];
18725
- parent = ensureSubnet(p.subnet, p.vpc);
18726
- } else if (vpcs.size >= 1) {
18727
- parent = vpcTitle([...vpcs][0]);
18728
- } else {
18729
- parent = GLOBAL;
18791
+ if (keys.size === 1) {
18792
+ child(placeTitle(places[0]), component);
18793
+ for (const m of members) child(component, m.id);
18794
+ continue;
18730
18795
  }
18796
+ if (vpcs.size === 1 && places.every((p) => p.kind !== "global")) {
18797
+ for (const [i, m] of members.entries()) {
18798
+ const p = places[i];
18799
+ const title = placeTitle(p);
18800
+ const part = p.kind === "subnet" ? `${component} \xB7 ${subnetScope(p.subnets[0])}` : component;
18801
+ child(title, part);
18802
+ child(part, m.id);
18803
+ }
18804
+ continue;
18805
+ }
18806
+ const parent = vpcs.size >= 1 ? vpcTitle([...vpcs][0]) : GLOBAL;
18731
18807
  child(parent, component);
18732
18808
  for (const m of members) child(component, m.id);
18733
18809
  }
@@ -18825,9 +18901,58 @@ function projectLogical(ir) {
18825
18901
  frontier = next;
18826
18902
  }
18827
18903
  }
18904
+ const accountId = aws.map((n) => JSON.stringify(n).match(ACCOUNT_RE)?.[1]).find(Boolean);
18905
+ const ACCOUNT = accountId ? `AWS account ${accountId}` : "AWS account";
18906
+ const nested = new Set(Object.values(byContainer).flat());
18907
+ for (const key3 of Object.keys(byContainer)) if (!nested.has(key3)) child(ACCOUNT, key3);
18828
18908
  return { ir: { nodes: headline, edges, groups: {} }, byContainer };
18829
18909
  }
18830
18910
 
18911
+ // src/logical-simplify.ts
18912
+ var BOUNDARY_RE = /^(AWS account|Azure subscription|GCP project)\b/;
18913
+ function simplifyNesting(byContainer, members, keep = /* @__PURE__ */ new Set()) {
18914
+ const out = {};
18915
+ for (const [k, v] of Object.entries(byContainer)) out[k] = [...v];
18916
+ const isBox = (id) => Object.prototype.hasOwnProperty.call(out, id);
18917
+ const parentOf = (id) => Object.keys(out).find((k) => out[k].includes(id));
18918
+ const fixed = (k) => BOUNDARY_RE.test(k) || keep.has(k);
18919
+ for (const key3 of Object.keys(out)) {
18920
+ if (fixed(key3)) continue;
18921
+ const member = key3.split(" \xB7 ")[0];
18922
+ if (!members.has(member) || !out[key3].every((c) => !isBox(c))) continue;
18923
+ const parent = parentOf(key3);
18924
+ if (!parent) continue;
18925
+ const at2 = out[parent].indexOf(key3);
18926
+ out[parent].splice(at2, 1, ...out[key3].filter((c) => !out[parent].includes(c)));
18927
+ delete out[key3];
18928
+ }
18929
+ for (let changed = true; changed; ) {
18930
+ changed = false;
18931
+ for (const key3 of Object.keys(out)) {
18932
+ const kids = out[key3];
18933
+ if (!kids || kids.length !== 1 || !isBox(kids[0]) || fixed(key3) || fixed(kids[0])) continue;
18934
+ const inner = kids[0];
18935
+ const merged = `${key3} \u203A ${inner}`;
18936
+ out[merged] = out[inner];
18937
+ delete out[inner];
18938
+ delete out[key3];
18939
+ const parent = parentOf(key3);
18940
+ if (parent) out[parent] = out[parent].map((c) => c === key3 ? merged : c);
18941
+ changed = true;
18942
+ break;
18943
+ }
18944
+ }
18945
+ return out;
18946
+ }
18947
+ function memberPrefixes(nodes) {
18948
+ const out = /* @__PURE__ */ new Set();
18949
+ for (const n of nodes) {
18950
+ const slash = n.id.indexOf("/");
18951
+ if (slash > 0) out.add(n.id.slice(0, slash));
18952
+ }
18953
+ return out;
18954
+ }
18955
+
18831
18956
  // src/composite-deps.ts
18832
18957
  function kebabKind(kind) {
18833
18958
  return kind.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
@@ -34509,6 +34634,8 @@ function validEntry(e) {
34509
34634
  if (d.serve.dirs !== void 0 && (!Array.isArray(d.serve.dirs) || d.serve.dirs.some((x) => typeof x !== "string") || !d.serve.dirs.length)) return false;
34510
34635
  if (d.serve.spawnEnv !== void 0 && (typeof d.serve.spawnEnv !== "object" || d.serve.spawnEnv === null || Array.isArray(d.serve.spawnEnv) || Object.values(d.serve.spawnEnv).some((v) => typeof v !== "string")))
34511
34636
  return false;
34637
+ if (d.serve.processEnv !== void 0 && (typeof d.serve.processEnv !== "object" || d.serve.processEnv === null || Array.isArray(d.serve.processEnv) || Object.values(d.serve.processEnv).some((v) => typeof v !== "string")))
34638
+ return false;
34512
34639
  if (d.serve.terralith !== void 0 && typeof d.serve.terralith !== "boolean") return false;
34513
34640
  if (d.serve.carve !== void 0) {
34514
34641
  const c = d.serve.carve;
@@ -36029,7 +36156,8 @@ function createApp(cfg, broadcaster = new Broadcaster(), frames = new FrameBuffe
36029
36156
  estateRun = applyMemberPasses(ir, { detail: opts.detail });
36030
36157
  if (logical) {
36031
36158
  const logicalBefore = ir.nodes.length;
36032
- const { ir: projected, byContainer, namespaceBoxes } = projectTopology(ir, metaEnv ?? void 0, estateContext, await estateSourceRoots(opts));
36159
+ const { ir: projected, byContainer: joined, namespaceBoxes } = projectTopology(ir, metaEnv ?? void 0, estateContext, await estateSourceRoots(opts));
36160
+ const byContainer = simplifiedEstateNesting(joined, ir, namespaceBoxes);
36033
36161
  const { svg: svg2 } = renderArchitecture(projected, byContainer, { groupMarks: operatorHomeBoxMarks(ir, namespaceBoxes ?? {}), groupBadges: operatorHomeBoxBadges(ir, namespaceBoxes ?? {}), ...cardPrefixesOf(ir) ? { cardPrefixes: cardPrefixesOf(ir) } : {} });
36034
36162
  const tf2 = passNote(estateRun);
36035
36163
  const lensNote = notesFor("logical", projected, void 0, logicalBefore);
@@ -36382,7 +36510,8 @@ function createApp(cfg, broadcaster = new Broadcaster(), frames = new FrameBuffe
36382
36510
  ].join("; ") : void 0;
36383
36511
  if (logical) {
36384
36512
  const logicalBefore = ir2.nodes.length;
36385
- const { ir: projected, byContainer, namespaceBoxes } = projectTopology(ir2, env, boundContext2, await estateSourceRoots(query));
36513
+ const { ir: projected, byContainer: joined, namespaceBoxes } = projectTopology(ir2, env, boundContext2, await estateSourceRoots(query));
36514
+ const byContainer = simplifiedEstateNesting(joined, ir2, namespaceBoxes);
36386
36515
  const { svg: svg3 } = renderArchitecture(projected, byContainer, { groupMarks: operatorHomeBoxMarks(ir2, namespaceBoxes ?? {}), groupBadges: operatorHomeBoxBadges(ir2, namespaceBoxes ?? {}), ...cardPrefixesOf(ir2) ? { cardPrefixes: cardPrefixesOf(ir2) } : {} });
36387
36516
  const note3 = [
36388
36517
  notesFor("logical", projected, void 0, logicalBefore),
@@ -36980,6 +37109,11 @@ async function startServer(cfg) {
36980
37109
  process.exit(1);
36981
37110
  });
36982
37111
  }
37112
+ function simplifiedEstateNesting(byContainer, ir, namespaceBoxes) {
37113
+ const members = memberPrefixes(ir.nodes);
37114
+ if (members.size < 2) return byContainer;
37115
+ return simplifyNesting(byContainer, members, new Set(Object.values(namespaceBoxes ?? {})));
37116
+ }
36983
37117
 
36984
37118
  // src/cli.ts
36985
37119
  init_chant();
@@ -38398,6 +38532,7 @@ async function runDemo(rest) {
38398
38532
  if (entry.serve.local) serveArgs.push("--local");
38399
38533
  if (entry.serve.env) serveArgs.push("--env", entry.serve.env);
38400
38534
  setChoudoufuSpawnEnv(entry.serve.spawnEnv);
38535
+ for (const [k, v] of Object.entries(entry.serve.processEnv ?? {})) process.env[k] ??= v;
38401
38536
  await run3(serveArgs);
38402
38537
  }
38403
38538
  function spawnStep(cmd, args, cwd) {
@@ -35,4 +35,4 @@ npx serve export
35
35
 
36
36
  `cd dns && npx chant run front-door` runs the same steps as an Op.
37
37
 
38
- Needs chant 0.124.35 or newer.
38
+ Needs chant 0.124.37 or newer.
@@ -1,18 +1,25 @@
1
- import { FargateAlb, Parameter, output } from "@intentius/chant-lexicon-aws";
1
+ import { FargateAlb, VpcDefault, output } from "@intentius/chant-lexicon-aws";
2
2
 
3
3
  // The website on ECS Fargate in us-east-1, behind its own load balancer: the
4
- // ALB's DNS name is the stable hostname Route 53 points at. The VPC and its
5
- // subnets come in as parameters, so no networking is declared here.
6
- export const vpcId = new Parameter("AWS::EC2::VPC::Id", { description: "The VPC (the default one is fine)" });
7
- export const subnetIds = new Parameter("List<AWS::EC2::Subnet::Id>", { description: "Two public subnets in different zones" });
4
+ // ALB's DNS name is the stable hostname Route 53 points at. The network is
5
+ // declared here as production has it: a VPC across two zones, public subnets
6
+ // for the load balancer and private ones for the tasks, which reach out
7
+ // through a NAT gateway.
8
+ export const network = VpcDefault({
9
+ cidr: "10.20.0.0/16",
10
+ publicSubnet1Cidr: "10.20.0.0/24",
11
+ publicSubnet2Cidr: "10.20.1.0/24",
12
+ privateSubnet1Cidr: "10.20.10.0/24",
13
+ privateSubnet2Cidr: "10.20.11.0/24",
14
+ });
8
15
 
9
16
  export const web = FargateAlb({
10
17
  image: "traefik/whoami:v1.10",
11
18
  containerPort: 80,
12
19
  desiredCount: 1,
13
- vpcId: vpcId as unknown as string,
14
- publicSubnetIds: subnetIds as unknown as string[],
15
- privateSubnetIds: subnetIds as unknown as string[],
20
+ vpcId: network.vpc.VpcId,
21
+ publicSubnetIds: [network.publicSubnet1.SubnetId, network.publicSubnet2.SubnetId],
22
+ privateSubnetIds: [network.privateSubnet1.SubnetId, network.privateSubnet2.SubnetId],
16
23
  logRetentionDays: 7,
17
24
  });
18
25
 
@@ -24,14 +24,11 @@ export const identity = new ManagedIdentity({ name: "three-cloud-web", location
24
24
  export const env = new managedEnvironments({
25
25
  name: "three-cloud",
26
26
  location,
27
- // concat() rather than resourceId('.../virtualNetworks/subnets', vnet, subnet):
28
- // chant 0.124.34's apply evaluates the latter to the wrong path (fixed by
29
- // INTENTIUS/chant#4234, not yet released).
30
- vnetConfiguration: { infrastructureSubnetId: "[concat(resourceId('Microsoft.Network/virtualNetworks', 'three-cloud-vnet'), '/subnets/apps')]", internal: false },
27
+ vnetConfiguration: { infrastructureSubnetId: "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'three-cloud-vnet', 'apps')]", internal: false },
31
28
  appLogsConfiguration: {
32
29
  destination: "log-analytics",
33
30
  logAnalyticsConfiguration: {
34
- customerId: "[reference('three-cloud-logs').customerId]",
31
+ customerId: "[reference(resourceId('Microsoft.OperationalInsights/workspaces', 'three-cloud-logs')).customerId]",
35
32
  sharedKey: "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', 'three-cloud-logs'), '2023-09-01').primarySharedKey]",
36
33
  },
37
34
  },
@@ -1 +1,2 @@
1
- export default { lexicons: ["gcp"], sourceDir: "src", environments: ["local"] };
1
+ // The project every gcp resource builds, applies and is read in.
2
+ export default { lexicons: ["gcp"], sourceDir: "src", environments: ["local"], gcp: { project: "three-cloud" } };
@@ -5,20 +5,18 @@ import {
5
5
  ForwardingRule,
6
6
  GCPServiceAccount,
7
7
  RegionNetworkEndpointGroup,
8
+ Subnetwork,
8
9
  TargetHTTPProxy,
9
10
  URLMap,
11
+ VPCNetwork,
10
12
  output,
11
13
  } from "@intentius/chant-lexicon-gcp";
12
14
 
13
- // The website on Cloud Run in Tokyo, running as its own service account, behind
14
- // a global external Application Load Balancer as production sets it up: a
15
+ // The website on Cloud Run in Tokyo, running as its own service account with
16
+ // its egress in a VPC subnet, behind a global external Application Load
17
+ // Balancer as production sets it up: a
15
18
  // static address and a forwarding rule, an HTTP proxy, a URL map, a backend
16
19
  // service, and a serverless network endpoint group that names the service.
17
- // The load balancer kinds apply with chant 0.124.35 or newer (chant#4233).
18
- //
19
- // Each reference is Config Connector's `{ name }`, spelled out: chant writes
20
- // an attribute reference's `.name` as the logical id rather than the
21
- // resource's metadata.name (reported to chant).
22
20
  const region = "asia-northeast1";
23
21
 
24
22
  export const runtime = new GCPServiceAccount({
@@ -26,6 +24,17 @@ export const runtime = new GCPServiceAccount({
26
24
  displayName: "three-cloud website runtime",
27
25
  });
28
26
 
27
+ // The network Cloud Run sends its egress into (Direct VPC egress), a custom
28
+ // VPC with one subnet in the service's region.
29
+ export const vpc = new VPCNetwork({ metadata: { name: "three-cloud-vpc" }, autoCreateSubnetworks: false, routingMode: "REGIONAL" });
30
+
31
+ export const subnet = new Subnetwork({
32
+ metadata: { name: "three-cloud-apps" },
33
+ region,
34
+ ipCidrRange: "10.30.0.0/24",
35
+ networkRef: { name: vpc.name },
36
+ });
37
+
29
38
  export const web = CloudRunServiceComposite({
30
39
  name: "three-cloud-site",
31
40
  image: "traefik/whoami:v1.10",
@@ -36,13 +45,23 @@ export const web = CloudRunServiceComposite({
36
45
  maxInstanceCount: 1,
37
46
  publicAccess: true,
38
47
  serviceAccount: "three-cloud-run",
48
+ defaults: {
49
+ service: {
50
+ template: {
51
+ vpcAccess: {
52
+ egress: "PRIVATE_RANGES_ONLY",
53
+ networkInterfaces: [{ networkRef: { name: vpc.name }, subnetworkRef: { name: subnet.name } }],
54
+ },
55
+ },
56
+ },
57
+ },
39
58
  });
40
59
 
41
60
  export const neg = new RegionNetworkEndpointGroup({
42
61
  metadata: { name: "three-cloud-neg" },
43
62
  region,
44
63
  networkEndpointType: "SERVERLESS",
45
- cloudRun: { serviceRef: { name: "three-cloud-site" } },
64
+ cloudRun: { serviceRef: { name: web.service.name } },
46
65
  });
47
66
 
48
67
  // A backend service over a serverless NEG takes no health check: Cloud Run
@@ -52,19 +71,19 @@ export const backend = new BackendService({
52
71
  location: "global",
53
72
  loadBalancingScheme: "EXTERNAL_MANAGED",
54
73
  protocol: "HTTP",
55
- backend: [{ group: { networkEndpointGroupRef: { name: "three-cloud-neg" } } }],
74
+ backend: [{ group: { networkEndpointGroupRef: { name: neg.name } } }],
56
75
  });
57
76
 
58
77
  export const urlMap = new URLMap({
59
78
  metadata: { name: "three-cloud-map" },
60
79
  location: "global",
61
- defaultService: { backendServiceRef: { name: "three-cloud-backend" } },
80
+ defaultService: { backendServiceRef: { name: backend.name } },
62
81
  });
63
82
 
64
83
  export const proxy = new TargetHTTPProxy({
65
84
  metadata: { name: "three-cloud-proxy" },
66
85
  location: "global",
67
- urlMapRef: { name: "three-cloud-map" },
86
+ urlMapRef: { name: urlMap.name },
68
87
  });
69
88
 
70
89
  export const address = new ComputeAddress({ metadata: { name: "three-cloud-ip" }, location: "global" });
@@ -74,8 +93,8 @@ export const rule = new ForwardingRule({
74
93
  location: "global",
75
94
  loadBalancingScheme: "EXTERNAL_MANAGED",
76
95
  portRange: "80",
77
- ipAddress: { addressRef: { name: "three-cloud-ip" } },
78
- target: { targetHTTPProxyRef: { name: "three-cloud-proxy" } },
96
+ ipAddress: { addressRef: { name: address.name } },
97
+ target: { targetHTTPProxyRef: { name: proxy.name } },
79
98
  });
80
99
 
81
100
  // The dns member reads this as its `gcpEndpoint` parameter: the load
@@ -6,10 +6,10 @@
6
6
  "": {
7
7
  "name": "behold-example-three-cloud",
8
8
  "dependencies": {
9
- "@intentius/chant": "^0.124.35",
10
- "@intentius/chant-lexicon-aws": "^0.124.35",
11
- "@intentius/chant-lexicon-azure": "^0.124.35",
12
- "@intentius/chant-lexicon-gcp": "^0.124.35"
9
+ "@intentius/chant": "^0.124.37",
10
+ "@intentius/chant-lexicon-aws": "^0.124.37",
11
+ "@intentius/chant-lexicon-azure": "^0.124.37",
12
+ "@intentius/chant-lexicon-gcp": "^0.124.37"
13
13
  }
14
14
  },
15
15
  "node_modules/@dagrejs/dagre": {
@@ -444,9 +444,9 @@
444
444
  }
445
445
  },
446
446
  "node_modules/@intentius/chant": {
447
- "version": "0.124.35",
448
- "resolved": "https://registry.npmjs.org/@intentius/chant/-/chant-0.124.35.tgz",
449
- "integrity": "sha512-4WGA/eLFtn5bKN0SwHQILbMYnk3gEZ+nfj01a1yuq+4mTRK45JGDthZIQZMi7vTtT8lCf4lbeUjuS/UD7Qk+kw==",
447
+ "version": "0.124.37",
448
+ "resolved": "https://registry.npmjs.org/@intentius/chant/-/chant-0.124.37.tgz",
449
+ "integrity": "sha512-yfnf2Bb66kA6UHqBI76T2HM1JczhIY35k4lDsxA5GDuvz33xHRFV+BhpLJD5+uKqLRVYHIp/UqlccY5Q3yjjCw==",
450
450
  "license": "Apache-2.0",
451
451
  "dependencies": {
452
452
  "@dagrejs/dagre": "^3.0.0",
@@ -473,34 +473,34 @@
473
473
  }
474
474
  },
475
475
  "node_modules/@intentius/chant-lexicon-aws": {
476
- "version": "0.124.35",
477
- "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-aws/-/chant-lexicon-aws-0.124.35.tgz",
478
- "integrity": "sha512-yhne5yFhCRF+GqsUoleNJRANTUHvsHeoplJ8xdb1Q1LkJABuelnWDNCRaL5aXNh4ONu53OQH44TwdvU2Fr3Qeg==",
476
+ "version": "0.124.37",
477
+ "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-aws/-/chant-lexicon-aws-0.124.37.tgz",
478
+ "integrity": "sha512-H79t+Aea1P051sVOfJOBQ1ZlpMmjG7We3p71RG8H99gtFXMyV44MWlBl0eikOyHLBlZu+YU449deWLtcEiFe0Q==",
479
479
  "license": "Apache-2.0",
480
480
  "dependencies": {
481
481
  "fflate": "^0.8.2",
482
482
  "js-yaml": "^4.3.1"
483
483
  },
484
484
  "peerDependencies": {
485
- "@intentius/chant": "^0.124.35"
485
+ "@intentius/chant": "^0.124.37"
486
486
  }
487
487
  },
488
488
  "node_modules/@intentius/chant-lexicon-azure": {
489
- "version": "0.124.35",
490
- "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-azure/-/chant-lexicon-azure-0.124.35.tgz",
491
- "integrity": "sha512-pK7C2HyBbfVLxv1oTwf3YM9s+Dit4NHZTHED8dyGOcPvbO0/1+Q9B/MD5A467L94I+s5QjMMAt1yd9Gu77E9jA==",
489
+ "version": "0.124.37",
490
+ "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-azure/-/chant-lexicon-azure-0.124.37.tgz",
491
+ "integrity": "sha512-hU/q497o+4VTw4E3t6ij5Pu5YSrc9yp5O1jdCYH7p6IHe9EpGmytyVTWhsmsd8B+1i8hU5HkV41+iM4qcA8HiQ==",
492
492
  "license": "Apache-2.0",
493
493
  "dependencies": {
494
494
  "fflate": "^0.8.2"
495
495
  },
496
496
  "peerDependencies": {
497
- "@intentius/chant": "^0.124.35"
497
+ "@intentius/chant": "^0.124.37"
498
498
  }
499
499
  },
500
500
  "node_modules/@intentius/chant-lexicon-gcp": {
501
- "version": "0.124.35",
502
- "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-gcp/-/chant-lexicon-gcp-0.124.35.tgz",
503
- "integrity": "sha512-qB2vQKi7hZjBl2/1R/A+yDIoQ44wq1Y0QE16D2tN70pE06ufjwwRd1MKMVQi3oHxynM8cQCA3QL7HUfb8/ZR3Q==",
501
+ "version": "0.124.37",
502
+ "resolved": "https://registry.npmjs.org/@intentius/chant-lexicon-gcp/-/chant-lexicon-gcp-0.124.37.tgz",
503
+ "integrity": "sha512-hUojSIF0MCsohc2bgrTFy2nZ/Eoyt0PbtVtlDnAvc4HZKrE2SVamaKQUKslhAGySjGOR8BpQWcMSCT92Bl0JpQ==",
504
504
  "license": "Apache-2.0",
505
505
  "dependencies": {
506
506
  "@types/js-yaml": "^4.0.9",
@@ -508,7 +508,7 @@
508
508
  "js-yaml": "^4.3.1"
509
509
  },
510
510
  "peerDependencies": {
511
- "@intentius/chant": "^0.124.35"
511
+ "@intentius/chant": "^0.124.37"
512
512
  }
513
513
  },
514
514
  "node_modules/@types/js-yaml": {
@@ -8,9 +8,9 @@
8
8
  "front-door": "tsx scripts/front-door.ts all --out export"
9
9
  },
10
10
  "dependencies": {
11
- "@intentius/chant": "^0.124.35",
12
- "@intentius/chant-lexicon-aws": "^0.124.35",
13
- "@intentius/chant-lexicon-azure": "^0.124.35",
14
- "@intentius/chant-lexicon-gcp": "^0.124.35"
11
+ "@intentius/chant": "^0.124.37",
12
+ "@intentius/chant-lexicon-aws": "^0.124.37",
13
+ "@intentius/chant-lexicon-azure": "^0.124.37",
14
+ "@intentius/chant-lexicon-gcp": "^0.124.37"
15
15
  }
16
16
  }
@@ -157,9 +157,7 @@ async function azureOn(): Promise<void> {
157
157
 
158
158
  /** The aws member, or why it could not be applied. */
159
159
  async function applyAws(): Promise<{ endpoint: string } | { refused: string }> {
160
- const template = build("aws");
161
- const subnets = await defaultSubnets();
162
- const params = withDefaults(template, { vpcId: subnets.vpc, subnetIds: subnets.ids.join(",") });
160
+ const params = build("aws");
163
161
  // A stack that rolled back on its first create can't be updated; start it again.
164
162
  if ((await stackStatus("three-cloud-aws")) === "ROLLBACK_COMPLETE") {
165
163
  await awsDelete({ templatePath: params, stackName: "three-cloud-aws", endpoint: AWS, timeoutMs: 180_000 });
@@ -340,16 +338,6 @@ async function awsQuery(service: string, form: Record<string, string>): Promise<
340
338
  return text;
341
339
  }
342
340
 
343
- async function defaultSubnets(): Promise<{ vpc: string; ids: string[] }> {
344
- const vpcs = await awsQuery("ec2", { Action: "DescribeVpcs", Version: "2016-11-15", "Filter.1.Name": "isDefault", "Filter.1.Value.1": "true" });
345
- const vpc = /<vpcId>([^<]+)<\/vpcId>/.exec(vpcs)?.[1];
346
- if (!vpc) throw new Refusal("aws: the emulator has no default VPC");
347
- const subnets = await awsQuery("ec2", { Action: "DescribeSubnets", Version: "2016-11-15", "Filter.1.Name": "vpc-id", "Filter.1.Value.1": vpc });
348
- const ids = [...subnets.matchAll(/<subnetId>([^<]+)<\/subnetId>/g)].map((m) => m[1]!).slice(0, 2);
349
- if (ids.length < 2) throw new Refusal(`aws: the default VPC ${vpc} has fewer than two subnets`);
350
- return { vpc, ids };
351
- }
352
-
353
341
  async function stackStatus(stack: string): Promise<string | undefined> {
354
342
  try {
355
343
  const xml = await awsQuery("cloudformation", { Action: "DescribeStacks", Version: "2010-05-15", StackName: stack });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/behold",
3
- "version": "0.29.52",
3
+ "version": "0.29.54",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@hono/node-server": "^2.0.5",
50
- "@intentius/chant": "^0.124.35",
50
+ "@intentius/chant": "^0.124.37",
51
51
  "@intentius/chant-k8s-client": "^0.124.24",
52
52
  "@intentius/pinhole": "^0.5.0",
53
53
  "ajv": "^8.20.0",
package/web/app.js CHANGED
@@ -372,6 +372,10 @@ const staticMode = !!window.__BEHOLD_STATIC__;
372
372
  const publicMode = !!window.__BEHOLD_PUBLIC__;
373
373
  let manifest = null;
374
374
  if (staticMode) {
375
+ // A snapshot has no live host behind it: the controls that only make sense
376
+ // against one (the lanes view, substrate readiness, the target endpoint,
377
+ // the deploy dial) are hidden by the `static` class (index.html).
378
+ document.documentElement.classList.add("static");
375
379
  try {
376
380
  manifest = await fetch("./manifest.json").then((r) => r.json());
377
381
  } catch {
@@ -1965,6 +1969,7 @@ function renderPanelView() {
1965
1969
  }),
1966
1970
  );
1967
1971
  const lanes = document.createElement("a");
1972
+ lanes.className = "lanes-link";
1968
1973
  lanes.href = "/lanes";
1969
1974
  lanes.textContent = "lanes →";
1970
1975
  lanes.title = "The time-lanes view — captured frames of this graph over time";
@@ -2461,7 +2466,7 @@ function renderPanelScope() {
2461
2466
  );
2462
2467
  }
2463
2468
  }
2464
- if (targets.length) {
2469
+ if (targets.length && !staticMode) {
2465
2470
  host.appendChild(panelHeading("target"));
2466
2471
  const sel = document.createElement("select");
2467
2472
  for (const t of targets) sel.add(new Option(t.endpoint, t.endpoint, false, view.target === t.endpoint));
@@ -8476,7 +8481,9 @@ function render(ir, svg, m) {
8476
8481
  // from /api/project when a route doesn't echo them, e.g. /api/overlay).
8477
8482
  if (m.tier !== undefined) axes.tier = m.tier;
8478
8483
  if (m.target !== undefined) axes.target = m.target;
8479
- const axesTail = `${axes.tier ? " · tier " + axes.tier : ""}${axes.target ? " · target " + axes.target : ""}`;
8484
+ // A snapshot's target is the host it was captured from (a localhost
8485
+ // emulator, usually), which means nothing to whoever reads the page.
8486
+ const axesTail = `${axes.tier ? " · tier " + axes.tier : ""}${axes.target && !staticMode ? " · target " + axes.target : ""}`;
8480
8487
  const metaEl = document.getElementById("meta");
8481
8488
  metaEl.title = m.projectDir || "";
8482
8489
  // #195: the browser tab names the loaded project — with the header gone
@@ -10492,7 +10499,11 @@ async function initActions() {
10492
10499
  pill.title = "An exported, read-only snapshot — no live observe or deploy.";
10493
10500
  pill.style.cssText = "align-self:center;font:var(--t-caption)/1.4 var(--font-mono);color:var(--muted);border:1px solid var(--line);border-radius:var(--r-ctl);padding:2px 8px";
10494
10501
  bar.appendChild(pill);
10495
- mountHistoryPicker(bar); // #510: other commits' views, when ../history.json sits beside this one
10502
+ // #510: other commits' views, when ../history.json sits beside this one.
10503
+ // The deploy tab stays hidden unless there is history to pick from.
10504
+ mountHistoryPicker(bar).then((picker) => {
10505
+ if (picker) document.documentElement.classList.add("static-history");
10506
+ });
10496
10507
  previewMode = true;
10497
10508
  return; // nothing else in the bar is a read
10498
10509
  }
package/web/index.html CHANGED
@@ -557,6 +557,10 @@
557
557
  /* Folded in a frame, the panel is a small pill (⌘K and the expand
558
558
  chevron) in the corner, so the graph has the pane to itself. */
559
559
  .embed #panel.collapsed #panel-tabs button[data-tab] { display: none; }
560
+ /* A static export (behold export) has no live host behind it. */
561
+ .static #panel-tabs button[data-tab="substrates"], .static #panel-body section[data-tab="substrates"],
562
+ .static:not(.static-history) #panel-tabs button[data-tab="deploy"], .static:not(.static-history) #panel-body section[data-tab="deploy"],
563
+ .static .lanes-link { display: none !important; }
560
564
  .embed #panel.collapsed { width: auto; }
561
565
  .embed #panel.collapsed #panel-tabs { gap: var(--s1); padding: 2px var(--s1); }
562
566
  /* #569: ?embed=1&bare=1, the kiosk's frame: the graph alone. Nothing to