Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/src/content/docs/reference/network-egress.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ An in-process guard says nothing about a child process, so the offline phases' s
|---|---|---|---|
| `packages/core/src/codegen/fetch.ts` | `fetch` | the upstream schema URL a caller passes | `fetchWithCache`/`fetchWithRetry` — the single transport under every lexicon's `spec/fetch.ts`, the k8s CRD loader, `chant vendor` and `chant dev pinned-upgrade`. Caches to disk, bounds each attempt, and falls back to the committed snapshot when the endpoint is unreachable. |
| `lexicons/aws/src/spec/fetch.ts` | `fetch` | the CloudFormation resource specification and Cloud Control schema endpoints | The aws spec fetch follows redirects itself rather than going through the shared cache helper; run by `chant dev generate`, never by a build. |
| `lexicons/aws/scripts/refresh-enum-overlay.ts` | `fetch` | `raw.githubusercontent.com`, for the botocore service models the overlay's own entries name | Diffs the curated enum overlay (chant #1497) against the botocore shapes its values were read from, and with `--write` restamps them. A maintainer command, reached only by hand or by `just refresh-enum-overlay`; generate, bundle, validate, build and the test suite all read the committed `src/codegen/enum-overlay.json` and reach nothing. |
| `lexicons/cpln/src/spec/snapshot-cli.ts` | `fetch` | the Control Plane OpenAPI document | `just snapshot` refreshes the committed offline spec snapshot; run on a networked machine on purpose, and the snapshot is what everything else reads. |
| `lexicons/azure/scripts/fetch-quickstart-templates.ts` | `fetch` | the Azure quickstart-templates repository | Builds the ARM fixture corpus the azure serializer is tested against; a maintainer script, not part of the lexicon's published surface. |

Expand All @@ -123,7 +124,7 @@ Freshness checks that run in this repository's own CI, against `api.github.com`.
| `scripts/dogwood-freshness.ts` | `fetch` | `api.github.com` commit and tree metadata | Compares the committed dogwood pin against upstream for `scripts/check-dogwood-freshness.ts`. The transport is injectable, which is why the comparison half is unit-tested without a network. |
| `scripts/prior-art-sweep.ts` | `fetch` | the rule indexes of the tools the audit rules credit: `raw.githubusercontent.com`, `api.github.com` directory listings, and a few tools' own docs sites (checkov.io, PSRule for Azure, the Bicep linter page) | Diffs each credited tool's published rule list against `scripts/prior-art/snapshot.json` so a rule that appears or disappears upstream, or a credit whose upstream id no longer resolves, is reported. Run by the monthly `prior-art-sweep` workflow and by hand; never by a CLI command or a test. |

**31 modules** across `packages/`, `lexicons/`, `scripts/`, `ops/` call a network primitive directly. Every other module that reaches the network does so through one of them.
**32 modules** across `packages/`, `lexicons/`, `scripts/`, `ops/` call a network primitive directly. Every other module that reaches the network does so through one of them.

{/* GENERATED:egress-catalogue:end */}

Expand Down
27 changes: 27 additions & 0 deletions lexicons/aws/docs/pages/cloudformation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ Common resources get fixed short names for stability. When two services define t

**Discovering available resources:** Your editor's autocomplete is the best tool — every resource is a named export from the lexicon. You can also run `chant list` to see all resource types, or browse the generated TypeScript types.

## Allowed values in generated types

Where the CloudFormation Registry schema declares `AllowedValues` for a property, the generated declaration is a union of literals rather than a bare `string` or `number`:

```ts
new LogGroup({ RetentionInDays: 45 });
// Type '45' is not assignable to type '1 | 1096 | 120 | 14 | 150 | 180 | 1827 | ... | 90'
```

The value of that is the error text. It lists the whole valid set, so the compiler answers the question instead of sending you to the console.

The Registry schema is silent on many properties that people write constantly, and it is inconsistent about which: `AWS::SageMaker::NotebookInstance.InstanceType` carried a union while `AWS::EC2::Instance.InstanceType` was a bare `string`. Two sources close that gap at generation time, both of them applied before anything is parsed, and neither of them reachable from `chant build`:

1. **cfn-lint patches.** `src/codegen/patches.ts` fetches the cfn-lint patch set and applies `manual.json`, `smithy.json` and `format.json` to each raw schema. Most of the unions you see beyond the bare Registry come from here.
2. **A curated enum overlay.** `src/codegen/enum-overlay.json` is a checked-in list of `(CloudFormation type, JSON pointer, values)` entries, applied by `src/codegen/enum-overlay.ts`. The first set covers the properties written most often across this repo's examples, docs and composites: Lambda `Runtime`, EC2 `InstanceType`, `Tenancy` and `VolumeType`, ELBv2 `Protocol`, `TargetType` and `Scheme`, SNS `Protocol`, the five DynamoDB table enums, RDS `Engine`, and Application Auto Scaling `ServiceNamespace` and `ScalableDimension`.

An overlay entry mints a named type beside the narrowed property, the same way a `$ref` to an enum definition in the Registry schema does. `AWS::Lambda::Function.Runtime` becomes `Runtime?: Function_Runtime`, and `Function_Runtime` is exported from the lexicon's `types` entry point, so a composite can name the union instead of restating its values.

Two rules govern the overlay:

- The spec wins. An entry whose property already declares `enum`, from the Registry or from a cfn-lint patch, leaves the spec alone and reports itself as redundant so it can be retired. Upstream is refreshed on every `generate` and is the source that keeps tracking AWS.
- An entry that matches nothing is an error. A renamed or removed property fails the generate rather than silently applying curated values to a property that no longer exists.

Each entry records where its values came from, either a botocore service model or an AWS documentation page, and the date they were read. `just refresh-enum-overlay` diffs the botocore-sourced entries against botocore's current `develop` and prints the documentation-sourced ones for a human to re-read. It reaches the network, so it is a manual command and no build step calls it.

Narrowing a property is a breaking change for anyone passing a value the union omits, even though every such value was already rejected at deploy. Overlay changes therefore ship with a release of the lexicon, and the release notes name what newly fails to compile.

## Imports and cross-file references

Chant projects use standard TypeScript imports. Lexicon types come from the lexicon package, and cross-file references are standard imports:
Expand Down
4 changes: 4 additions & 0 deletions lexicons/aws/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ docs-build:
import-samples *args:
bash scripts/import-aws-samples.sh {{args}}

# Diff the curated enum overlay against its recorded sources (network; never part of a build)
refresh-enum-overlay *args:
npx tsx scripts/refresh-enum-overlay.ts {{args}}

# Package the lexicon (generate + validate)
package: generate validate
139 changes: 139 additions & 0 deletions lexicons/aws/scripts/refresh-enum-overlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env tsx
/**
* Refresh the curated enum overlay from its recorded sources (chant #1497).
*
* Manual only. It reaches the network, so it is deliberately not a package
* script and nothing in `generate`, `bundle`, `validate` or `build` calls it:
* `chant build` and the test suite read the checked-in
* `src/codegen/enum-overlay.json` and nothing else.
*
* npx tsx lexicons/aws/scripts/refresh-enum-overlay.ts # report drift, exit 1 if any
* npx tsx lexicons/aws/scripts/refresh-enum-overlay.ts --write # apply it and restamp `reviewed`
*
* Entries sourced from a botocore service model are refreshed automatically:
* botocore is the same data cfn-lint derives its own enum patches from, and it
* is machine-readable, so the diff is exact. Entries sourced from an AWS
* documentation page are reported with their URL for a human to re-read, since
* no machine-readable form of those lists exists.
*/

import { readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import type { EnumOverlayEntry } from "../src/codegen/enum-overlay";

const OVERLAY_PATH = join(
dirname(dirname(fileURLToPath(import.meta.url))),
"src",
"codegen",
"enum-overlay.json",
);

const BOTOCORE_BASE = "https://raw.githubusercontent.com/boto/botocore/develop/botocore/data";

interface ServiceModel {
shapes?: Record<string, { enum?: string[] }>;
}

const modelCache = new Map<string, Promise<ServiceModel>>();

function serviceModel(service: string, apiVersion: string): Promise<ServiceModel> {
const url = `${BOTOCORE_BASE}/${service}/${apiVersion}/service-2.json`;
let pending = modelCache.get(url);
if (!pending) {
pending = (async () => {
const res = await fetch(url);
if (!res.ok) throw new Error(`${url} returned ${res.status}`);
return (await res.json()) as ServiceModel;
})();
modelCache.set(url, pending);
}
return pending;
}

function today(): string {
return new Date().toISOString().slice(0, 10);
}

function difference(a: string[], b: string[]): string[] {
const other = new Set(b);
return a.filter((v) => !other.has(v));
}

async function main(): Promise<void> {
const write = process.argv.includes("--write");
const document = JSON.parse(readFileSync(OVERLAY_PATH, "utf-8")) as {
entries: EnumOverlayEntry[];
};

let drifted = 0;
let manual = 0;

for (const entry of document.entries) {
const where = `${entry.type}${entry.pointer}`;

if (entry.source.kind === "docs") {
manual++;
console.log(`manual ${where}`);
console.log(` ${entry.values.length} value(s), last read ${entry.reviewed}`);
console.log(` ${entry.source.url}`);
continue;
}

const { service, apiVersion, shape } = entry.source;
let model: ServiceModel;
try {
model = await serviceModel(service, apiVersion);
} catch (err) {
console.error(`FAILED ${where}: ${err instanceof Error ? err.message : String(err)}`);
process.exitCode = 1;
continue;
}

const upstream = model.shapes?.[shape]?.enum;
if (!upstream) {
console.error(`FAILED ${where}: botocore ${service} has no enum shape ${shape}`);
process.exitCode = 1;
continue;
}

const fresh = [...new Set(upstream)].sort();
const added = difference(fresh, entry.values);
const removed = difference(entry.values, fresh);

if (added.length === 0 && removed.length === 0) {
console.log(`ok ${where} (${entry.values.length})`);
continue;
}

drifted++;
console.log(`drift ${where}`);
if (added.length > 0) console.log(` + ${added.join(", ")}`);
// A removed value is worth a second look before it is applied: narrowing
// further is the half of a refresh that can break a template that compiles
// today.
if (removed.length > 0) console.log(` - ${removed.join(", ")}`);

if (write) {
entry.values = fresh;
entry.reviewed = today();
}
}

if (write && drifted > 0) {
writeFileSync(OVERLAY_PATH, `${JSON.stringify(document, null, 2)}\n`);
console.log(`\nrewrote ${OVERLAY_PATH} (${drifted} entr${drifted === 1 ? "y" : "ies"})`);
console.log("Run `npm run generate` in lexicons/aws and re-check the surface before committing.");
return;
}

console.log(
`\n${drifted} entr${drifted === 1 ? "y" : "ies"} drifted, ${manual} need a human to re-read the docs page.`,
);
if (drifted > 0) {
console.log("Re-run with --write to apply the botocore half.");
process.exitCode = 1;
}
}

await main();
Loading
Loading