@intentius/chant-lexicon-aws 0.124.52 → 0.124.55
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/api/credential-chain.d.ts +3 -3
- package/dist/api/credential-chain.d.ts.map +1 -1
- package/dist/api/credential-chain.js +2 -2
- package/dist/api/read-client.d.ts +2 -2
- package/dist/api/read-client.d.ts.map +1 -1
- package/dist/api/read-client.js +2 -2
- package/dist/api/{sigv4.d.ts → signing.d.ts} +14 -34
- package/dist/api/signing.d.ts.map +1 -0
- package/dist/api/signing.js +95 -0
- package/dist/codegen/generate-lexicon.d.ts +2 -0
- package/dist/codegen/generate-lexicon.d.ts.map +1 -1
- package/dist/codegen/generate-lexicon.js +1 -0
- package/dist/components/__tests__/mock-cloud-executor.d.ts +4 -0
- package/dist/components/__tests__/mock-cloud-executor.d.ts.map +1 -1
- package/dist/components/__tests__/mock-cloud-executor.js +18 -1
- package/dist/components/apply.d.ts +46 -2
- package/dist/components/apply.d.ts.map +1 -1
- package/dist/components/apply.js +266 -30
- package/dist/components/cfn-adopt-run.d.ts +37 -0
- package/dist/components/cfn-adopt-run.d.ts.map +1 -0
- package/dist/components/cfn-adopt-run.js +104 -0
- package/dist/components/cfn-adopt.d.ts +99 -0
- package/dist/components/cfn-adopt.d.ts.map +1 -0
- package/dist/components/cfn-adopt.js +278 -0
- package/dist/components/cfn-imports.d.ts +84 -0
- package/dist/components/cfn-imports.d.ts.map +1 -0
- package/dist/components/cfn-imports.js +239 -0
- package/dist/components/cloud-executor.d.ts +38 -2
- package/dist/components/cloud-executor.d.ts.map +1 -1
- package/dist/components/cloud-executor.js +84 -2
- package/dist/health.js +1 -1
- package/dist/importable.d.ts +30 -0
- package/dist/importable.d.ts.map +1 -0
- package/dist/importable.js +72 -0
- package/dist/index-identity.d.ts +19 -0
- package/dist/index-identity.d.ts.map +1 -0
- package/dist/index-identity.js +79 -0
- package/dist/index-import.d.ts +25 -0
- package/dist/index-import.d.ts.map +1 -0
- package/dist/index-import.js +132 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/integrity.json +4 -4
- package/dist/listed-types.d.ts +11 -0
- package/dist/listed-types.d.ts.map +1 -0
- package/dist/listed-types.js +52 -0
- package/dist/manifest.json +1 -1
- package/dist/meta.json +13206 -1237
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +12 -3
- package/dist/reference-catalog.d.ts.map +1 -1
- package/dist/reference-catalog.js +62 -20
- package/dist/skills/chant-aws-carve-terraform.md +21 -14
- package/dist/spec/fetch.d.ts +5 -0
- package/dist/spec/fetch.d.ts.map +1 -1
- package/dist/spec/parse.d.ts +8 -0
- package/dist/spec/parse.d.ts.map +1 -1
- package/dist/spec/parse.js +3 -0
- package/package.json +2 -2
- package/src/api/credential-chain.ts +3 -3
- package/src/api/read-client.test.ts +2 -2
- package/src/api/read-client.ts +3 -3
- package/src/api/{sigv4.test.ts → signing.test.ts} +84 -96
- package/src/api/signing.ts +130 -0
- package/src/codegen/generate-lexicon.ts +3 -0
- package/src/components/__tests__/mock-cloud-executor.ts +20 -1
- package/src/components/apply.ts +288 -30
- package/src/components/cfn-adopt-run.test.ts +227 -0
- package/src/components/cfn-adopt-run.ts +141 -0
- package/src/components/cfn-adopt.test.ts +284 -0
- package/src/components/cfn-adopt.ts +340 -0
- package/src/components/cfn-exports-in-use.test.ts +146 -0
- package/src/components/cfn-imports-preview.test.ts +178 -0
- package/src/components/cfn-imports-three-stacks.test.ts +107 -0
- package/src/components/cfn-imports.test.ts +213 -0
- package/src/components/cfn-imports.ts +246 -0
- package/src/components/cfn-plan-shape-conformance.test.ts +83 -0
- package/src/components/cloud-executor.ts +127 -5
- package/src/components/demo-composed-stacks-floci.e2e.test.ts +235 -0
- package/src/derived-edges.test.ts +142 -0
- package/src/generated/lexicon-aws.json +13206 -1237
- package/src/health.ts +1 -1
- package/src/importable.test.ts +86 -0
- package/src/importable.ts +83 -0
- package/src/index-identity.test.ts +134 -0
- package/src/index-identity.ts +98 -0
- package/src/index-import.test.ts +257 -0
- package/src/index-import.ts +158 -0
- package/src/index-search.test.ts +87 -0
- package/src/index.ts +1 -1
- package/src/listed-types.test.ts +97 -0
- package/src/listed-types.ts +56 -0
- package/src/plugin.ts +13 -3
- package/src/reference-catalog.ts +63 -20
- package/src/skills/chant-aws-carve-terraform.md +21 -14
- package/src/spec/fetch.ts +5 -0
- package/src/spec/parse.test.ts +15 -0
- package/src/spec/parse.ts +12 -0
- package/src/testdata/indexed/identity.listing.json +65 -0
- package/src/testdata/indexed/import.listing.json +126 -0
- package/src/testdata/indexed/listing.json +69 -0
- package/src/testdata/indexed/topology.listing.json +350 -0
- package/src/testdata/three-cloud/dns.graph.json +336 -0
- package/src/three-cloud-parity.test.ts +49 -0
- package/dist/api/sigv4.d.ts.map +0 -1
- package/dist/api/sigv4.js +0 -185
- package/src/api/sigv4.ts +0 -243
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4524 on the aws lexicon: `chant import --index` over a fixture index.
|
|
3
|
+
*
|
|
4
|
+
* The fixture (testdata/indexed/import.listing.json) is a VPC with a subnet
|
|
5
|
+
* and a security group in it, an ECS task definition whose task role is an
|
|
6
|
+
* IAM role, an RDS instance whose master password the lister masked, a
|
|
7
|
+
* bucket, and one object of a type the lexicon does not generate. It is
|
|
8
|
+
* typed (#4521) and its edges derived (#4522, #4523) as `behold index` would
|
|
9
|
+
* write it, then imported through the aws seam and CFGenerator, the codegen
|
|
10
|
+
* `chant import <template>` uses.
|
|
11
|
+
*
|
|
12
|
+
* The emulator round trip (index, import, build, then the declared entities
|
|
13
|
+
* bind to their indexed resources through #4523 with no drift) is a
|
|
14
|
+
* maintainer run; the steps are in the #4524 issue comment.
|
|
15
|
+
*/
|
|
16
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { describe, expect, test } from "vitest";
|
|
19
|
+
import { build } from "@intentius/chant/build";
|
|
20
|
+
import { MASKED } from "@intentius/chant/deep-observation";
|
|
21
|
+
import { deriveEdges } from "@intentius/chant/lifecycle/derive-edges";
|
|
22
|
+
import { awsDeclaredIdentity, awsIndexIdentity, type IdentityManifestEntry } from "./index-identity";
|
|
23
|
+
import type { IndexDocument } from "@intentius/chant/lifecycle/index-document";
|
|
24
|
+
import { declaredNodes, planIndexImport, type IndexImportSelection } from "@intentius/chant/lifecycle/index-import";
|
|
25
|
+
import { typeListing, type ListingLexicon, type ListingResult } from "@intentius/chant/lifecycle/type-listing";
|
|
26
|
+
import { indexImportReportJson, renderIndexImport } from "@intentius/chant/cli/commands/import-index";
|
|
27
|
+
import type { LexiconPlugin } from "@intentius/chant/lexicon";
|
|
28
|
+
import { awsImportProperties, createAwsIndexImport, isImportableAwsType } from "./index-import";
|
|
29
|
+
import { awsKindForListedType } from "./listed-types";
|
|
30
|
+
import { awsPlugin } from "./plugin";
|
|
31
|
+
import { awsSerializer } from "./serializer";
|
|
32
|
+
|
|
33
|
+
// The registry rows for the fixture's types: primaryIdentifier and the
|
|
34
|
+
// schema's readOnlyProperties, which codegen writes as `attrs`.
|
|
35
|
+
const ROWS: IdentityManifestEntry[] = [
|
|
36
|
+
{ resourceType: "AWS::EC2::VPC", kind: "resource", primaryIdentifier: ["VpcId"], attrs: { VpcId: "VpcId", CidrBlockAssociations: "CidrBlockAssociations", DefaultNetworkAcl: "DefaultNetworkAcl", DefaultSecurityGroup: "DefaultSecurityGroup", Ipv6CidrBlocks: "Ipv6CidrBlocks" } },
|
|
37
|
+
{ resourceType: "AWS::EC2::Subnet", kind: "resource", primaryIdentifier: ["SubnetId"], attrs: { SubnetId: "SubnetId", NetworkAclAssociationId: "NetworkAclAssociationId", Ipv6CidrBlocks: "Ipv6CidrBlocks" } },
|
|
38
|
+
{ resourceType: "AWS::EC2::SecurityGroup", kind: "resource", primaryIdentifier: ["Id"], attrs: { GroupId: "GroupId", Id: "Id" } },
|
|
39
|
+
{ resourceType: "AWS::IAM::Role", kind: "resource", primaryIdentifier: ["RoleName"], attrs: { Arn: "Arn", RoleId: "RoleId" } },
|
|
40
|
+
{ resourceType: "AWS::ECS::TaskDefinition", kind: "resource", primaryIdentifier: ["TaskDefinitionArn"], attrs: { TaskDefinitionArn: "TaskDefinitionArn" } },
|
|
41
|
+
{ resourceType: "AWS::RDS::DBInstance", kind: "resource", primaryIdentifier: ["DBInstanceIdentifier"], attrs: { DBInstanceArn: "DBInstanceArn", DbiResourceId: "DbiResourceId", Endpoint_Address: "Endpoint.Address", Endpoint_Port: "Endpoint.Port" } },
|
|
42
|
+
{ resourceType: "AWS::S3::Bucket", kind: "resource", primaryIdentifier: ["BucketName"], attrs: { Arn: "Arn", DomainName: "DomainName", RegionalDomainName: "RegionalDomainName", WebsiteURL: "WebsiteURL" } },
|
|
43
|
+
];
|
|
44
|
+
const MANIFEST: ReadonlyMap<string, IdentityManifestEntry> = new Map(ROWS.map((e) => [e.resourceType, e]));
|
|
45
|
+
const KINDS: ReadonlySet<string> = new Set(MANIFEST.keys());
|
|
46
|
+
|
|
47
|
+
const listingLexicon: ListingLexicon = {
|
|
48
|
+
name: awsPlugin.name,
|
|
49
|
+
deepNormalizationHooks: awsPlugin.deepNormalizationHooks,
|
|
50
|
+
listedTypes: { ...awsPlugin.listedTypes!, kindFor: (t) => awsKindForListedType(t, KINDS) },
|
|
51
|
+
};
|
|
52
|
+
const identity = { ...awsIndexIdentity, declaredIdentity: (t: string, p: Record<string, unknown>) => awsDeclaredIdentity(t, p, MANIFEST) };
|
|
53
|
+
const importLexicon = { name: "aws", indexImport: createAwsIndexImport(MANIFEST), indexIdentity: identity };
|
|
54
|
+
// renderIndexImport needs the template generator, and the plan needs the seam with the test's registry rows.
|
|
55
|
+
const plugin = { ...awsPlugin, indexImport: importLexicon.indexImport } as LexiconPlugin;
|
|
56
|
+
|
|
57
|
+
const raw = readFileSync(join(import.meta.dirname, "testdata", "indexed", "import.listing.json"), "utf-8");
|
|
58
|
+
|
|
59
|
+
/** The fixture as `behold index` writes it: typed, then derived edges. */
|
|
60
|
+
function indexFrom(listing: ListingResult): IndexDocument {
|
|
61
|
+
return deriveEdges(typeListing(listing, [listingLexicon]), [
|
|
62
|
+
{ name: "aws", referenceCatalog: awsPlugin.referenceCatalog, indexIdentity: identity },
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
const doc = indexFrom(JSON.parse(raw) as ListingResult);
|
|
66
|
+
const ALL: IndexImportSelection = { all: true };
|
|
67
|
+
|
|
68
|
+
function importOf(d: IndexDocument, selection: IndexImportSelection, declared?: ReadonlyMap<string, string>) {
|
|
69
|
+
const plan = planIndexImport([d], selection, [importLexicon], declared ? { declared } : {});
|
|
70
|
+
const { files, warnings } = renderIndexImport(plan, [plugin]);
|
|
71
|
+
return { plan, files, warnings };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Build the generated source and return the synthesized template. */
|
|
75
|
+
async function synth(files: Array<{ path: string; content: string }>): Promise<Record<string, any>> {
|
|
76
|
+
const dir = mkdtempSync(join(import.meta.dirname, "../.index-import-tmp-"));
|
|
77
|
+
try {
|
|
78
|
+
const src = join(dir, "src");
|
|
79
|
+
mkdirSync(src);
|
|
80
|
+
for (const f of files) writeFileSync(join(src, f.path), f.content);
|
|
81
|
+
const result = await build(src, [awsSerializer]);
|
|
82
|
+
expect(result.errors.map((e) => e.message)).toEqual([]);
|
|
83
|
+
return JSON.parse(result.outputs.get("aws") as string);
|
|
84
|
+
} finally {
|
|
85
|
+
rmSync(dir, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const nodeById = new Map(doc.graph.nodes.map((n) => [n.id, n]));
|
|
90
|
+
|
|
91
|
+
describe("chant import --index on the aws fixture", () => {
|
|
92
|
+
test("the edges the fixture should carry are derived", () => {
|
|
93
|
+
const rules = doc.graph.edges.map((e) => e.rule);
|
|
94
|
+
expect(rules).toContain("aws:AWS::EC2::Subnet:VpcId");
|
|
95
|
+
expect(rules).toContain("aws:AWS::EC2::SecurityGroup:VpcId");
|
|
96
|
+
expect(rules).toContain("aws:AWS::ECS::TaskDefinition:TaskRoleArn");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("round trip: import, then synth, gives each resource the indexed properties", async () => {
|
|
100
|
+
const { plan, files } = importOf(doc, ALL);
|
|
101
|
+
expect(files.map((f) => f.path)).toEqual(["main.ts"]);
|
|
102
|
+
const template = await synth(files);
|
|
103
|
+
|
|
104
|
+
const imported = plan.report.resources.filter((r) => r.status === "imported");
|
|
105
|
+
expect(imported.map((r) => r.identity.listedType).sort()).toEqual([
|
|
106
|
+
"AWS::EC2::SecurityGroup",
|
|
107
|
+
"AWS::EC2::Subnet",
|
|
108
|
+
"AWS::EC2::VPC",
|
|
109
|
+
"AWS::ECS::TaskDefinition",
|
|
110
|
+
"AWS::IAM::Role",
|
|
111
|
+
"AWS::RDS::DBInstance",
|
|
112
|
+
"AWS::S3::Bucket",
|
|
113
|
+
]);
|
|
114
|
+
const byLogical = new Map(imported.map((r) => [r.logicalId!, nodeById.get(r.node)!]));
|
|
115
|
+
const params = new Set(plan.report.parameters.map((p) => p.name));
|
|
116
|
+
|
|
117
|
+
// Each reference and parameter read back as the value it stands for.
|
|
118
|
+
const resolveBack = (v: unknown): unknown => {
|
|
119
|
+
if (Array.isArray(v)) return v.map(resolveBack);
|
|
120
|
+
if (v && typeof v === "object") {
|
|
121
|
+
const o = v as Record<string, unknown>;
|
|
122
|
+
if (typeof o.Ref === "string" && Object.keys(o).length === 1) {
|
|
123
|
+
if (params.has(o.Ref)) return MASKED;
|
|
124
|
+
const n = byLogical.get(o.Ref);
|
|
125
|
+
if (n) return n.nativeId;
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(o["Fn::GetAtt"]) && Object.keys(o).length === 1) {
|
|
128
|
+
const [id, attr] = o["Fn::GetAtt"] as [string, string];
|
|
129
|
+
const n = byLogical.get(id);
|
|
130
|
+
if (n && attr === "Arn") return n.facts?.cloudIds?.find((c) => c.kind === "arn")?.value;
|
|
131
|
+
}
|
|
132
|
+
return Object.fromEntries(Object.entries(o).map(([k, x]) => [k, resolveBack(x)]));
|
|
133
|
+
}
|
|
134
|
+
return v;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
for (const [logicalId, node] of byLogical) {
|
|
138
|
+
const built = template.Resources[logicalId];
|
|
139
|
+
expect(built.Type).toBe(node.kind);
|
|
140
|
+
const expected = awsImportProperties(node.kind, node.attrs, MANIFEST);
|
|
141
|
+
expect(resolveBack(built.Properties ?? {})).toEqual(expected);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("every imported resource builds with DeletionPolicy and UpdateReplacePolicy Retain (#4536)", async () => {
|
|
146
|
+
const { plan, files } = importOf(doc, ALL);
|
|
147
|
+
const template = await synth(files);
|
|
148
|
+
for (const r of plan.report.resources.filter((x) => x.status === "imported")) {
|
|
149
|
+
expect(template.Resources[r.logicalId!]).toMatchObject({ DeletionPolicy: "Retain", UpdateReplacePolicy: "Retain" });
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("the same index and selection give byte-identical files, in any listing order", () => {
|
|
154
|
+
const first = importOf(doc, ALL);
|
|
155
|
+
const shuffled = JSON.parse(raw) as ListingResult;
|
|
156
|
+
shuffled.resources = [...shuffled.resources].reverse();
|
|
157
|
+
const again = importOf(indexFrom(shuffled), ALL);
|
|
158
|
+
expect(again.files).toEqual(first.files);
|
|
159
|
+
expect(indexImportReportJson(again.plan.report)).toBe(indexImportReportJson(first.plan.report));
|
|
160
|
+
expect(importOf(doc, ALL).files).toEqual(first.files);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("a masked secret is written as a NoEcho parameter, never as a value", async () => {
|
|
164
|
+
const { plan, files } = importOf(doc, { types: ["AWS::RDS::DBInstance"] });
|
|
165
|
+
const source = files[0].content;
|
|
166
|
+
expect(source).not.toContain(MASKED);
|
|
167
|
+
expect(plan.report.parameters).toHaveLength(1);
|
|
168
|
+
const param = plan.report.parameters[0];
|
|
169
|
+
expect(param.path).toBe("MasterUserPassword");
|
|
170
|
+
expect(source).toContain(`fill in the parameter ${param.name}`);
|
|
171
|
+
const template = await synth(files);
|
|
172
|
+
expect(template.Parameters[param.name]).toMatchObject({ Type: "String", NoEcho: true });
|
|
173
|
+
const db = plan.report.resources.find((r) => r.status === "imported")!;
|
|
174
|
+
expect(template.Resources[db.logicalId!].Properties.MasterUserPassword).toEqual({ Ref: param.name });
|
|
175
|
+
expect(JSON.stringify(template)).not.toContain(MASKED);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("derived edges become Ref and GetAtt between imported resources", async () => {
|
|
179
|
+
const { plan, files } = importOf(doc, ALL);
|
|
180
|
+
const template = await synth(files);
|
|
181
|
+
const logical = (type: string) => plan.report.resources.find((r) => r.identity.listedType === type)!.logicalId!;
|
|
182
|
+
const vpc = logical("AWS::EC2::VPC");
|
|
183
|
+
expect(template.Resources[logical("AWS::EC2::Subnet")].Properties.VpcId).toEqual({ Ref: vpc });
|
|
184
|
+
expect(template.Resources[logical("AWS::EC2::SecurityGroup")].Properties.VpcId).toEqual({ Ref: vpc });
|
|
185
|
+
expect(template.Resources[logical("AWS::ECS::TaskDefinition")].Properties.TaskRoleArn).toEqual({
|
|
186
|
+
"Fn::GetAtt": [logical("AWS::IAM::Role"), "Arn"],
|
|
187
|
+
});
|
|
188
|
+
const subnet = plan.report.resources.find((r) => r.identity.listedType === "AWS::EC2::Subnet")!;
|
|
189
|
+
expect(subnet.references).toContainEqual({
|
|
190
|
+
path: "VpcId",
|
|
191
|
+
target: "aws/000000000000/us-east-1/AWS::EC2::VPC/vpc-0imp",
|
|
192
|
+
rule: "aws:AWS::EC2::Subnet:VpcId",
|
|
193
|
+
written: "reference",
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("an edge to a resource outside the selection stays a literal, with a comment naming the edge", () => {
|
|
198
|
+
const { plan, files } = importOf(doc, { types: ["AWS::EC2::Subnet"] });
|
|
199
|
+
const source = files[0].content;
|
|
200
|
+
expect(source).toContain('"vpc-0imp"');
|
|
201
|
+
expect(source).toMatch(/VpcId = "vpc-0imp" stays a literal: derived edge aws:AWS::EC2::Subnet:VpcId to aws\/000000000000\/us-east-1\/AWS::EC2::VPC\/vpc-0imp; the target is not in the selection/);
|
|
202
|
+
const subnet = plan.report.resources[0];
|
|
203
|
+
expect(subnet.references?.[0]).toMatchObject({ path: "VpcId", written: "literal", reason: "the target is not in the selection" });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("aws: tags and read-only properties are left out", () => {
|
|
207
|
+
const vpc = doc.graph.nodes.find((n) => n.kind === "AWS::EC2::VPC")!;
|
|
208
|
+
const props = awsImportProperties(vpc.kind, vpc.attrs, MANIFEST);
|
|
209
|
+
expect(props.VpcId).toBeUndefined();
|
|
210
|
+
expect(props.Tags).toEqual([{ Key: "Name", Value: "shop" }]);
|
|
211
|
+
const db = doc.graph.nodes.find((n) => n.kind === "AWS::RDS::DBInstance")!;
|
|
212
|
+
expect(awsImportProperties(db.kind, db.attrs, MANIFEST).Endpoint).toBeUndefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("a declared bucket is reported as declared, not imported again", () => {
|
|
216
|
+
const declared = declaredNodes(
|
|
217
|
+
[doc],
|
|
218
|
+
new Map([["aws", [{ name: "assets", entityType: "AWS::S3::Bucket", props: { BucketName: "imp-assets" } }]]]),
|
|
219
|
+
[importLexicon],
|
|
220
|
+
);
|
|
221
|
+
const { plan, files } = importOf(doc, ALL, declared);
|
|
222
|
+
const bucket = plan.report.resources.find((r) => r.identity.listedType === "AWS::S3::Bucket")!;
|
|
223
|
+
expect(bucket).toMatchObject({ status: "declared", entity: "assets" });
|
|
224
|
+
expect(files[0].content).not.toContain("imp-assets");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("an unmapped type is named as unsupported, with its identity and cloud ids in the report", () => {
|
|
228
|
+
const { plan } = importOf(doc, ALL);
|
|
229
|
+
const other = plan.report.resources.find((r) => r.identity.listedType === "AWS::Example::NotGenerated")!;
|
|
230
|
+
expect(other.status).toBe("unsupported");
|
|
231
|
+
expect(other.reason).toMatch(/no lexicon kind maps/);
|
|
232
|
+
const role = plan.report.resources.find((r) => r.identity.listedType === "AWS::IAM::Role")!;
|
|
233
|
+
expect(role.identity).toEqual({ substrate: "aws", scopeId: "000000000000", listedType: "AWS::IAM::Role", location: "global", nativeId: "imp-task-role" });
|
|
234
|
+
expect(role.cloudIds).toContainEqual({ kind: "arn", value: "arn:aws:iam::000000000000:role/imp-task-role" });
|
|
235
|
+
// The global role joins the only region, so one file holds everything.
|
|
236
|
+
expect(plan.groups.map((g) => g.dir)).toEqual([""]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("a type outside the AWS organization imports when the registry has it (#4538)", () => {
|
|
240
|
+
const rows = new Map(MANIFEST);
|
|
241
|
+
rows.set("Alexa::ASK::Skill", { resourceType: "Alexa::ASK::Skill", kind: "resource", attrs: {} });
|
|
242
|
+
const seam = createAwsIndexImport(rows);
|
|
243
|
+
const skill = { id: "aws:Alexa::ASK::Skill:amzn1.ask.skill.1", kind: "Alexa::ASK::Skill", lexicon: "aws", attrs: { SkillPackage: { Overrides: {} } } };
|
|
244
|
+
expect(seam.resource(skill)).toMatchObject({ type: "Alexa::ASK::Skill", properties: { SkillPackage: { Overrides: {} } } });
|
|
245
|
+
expect(isImportableAwsType("Alexa::ASK::Skill", rows)).toBe(true);
|
|
246
|
+
// Not in the registry, or not a CloudFormation type at all: refused.
|
|
247
|
+
expect(seam.resource({ ...skill, kind: "Alexa::ASK::Other" })).toEqual({ unsupported: expect.stringMatching(/not a CloudFormation resource type/) });
|
|
248
|
+
expect(isImportableAwsType("AWS::S3", rows)).toBe(false);
|
|
249
|
+
// With no registry, the listed-type rule's shape check alone decides.
|
|
250
|
+
expect(isImportableAwsType("Alexa::ASK::Skill", new Map())).toBe(true);
|
|
251
|
+
expect(isImportableAwsType("not-a-type", new Map())).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("the plugin declares the seam", () => {
|
|
255
|
+
expect(awsPlugin.indexImport).toBeDefined();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The aws lexicon's index import seam (#4524, `chant import --index`).
|
|
3
|
+
*
|
|
4
|
+
* behold's lister reads AWS through Cloud Control, which returns each
|
|
5
|
+
* object's CloudFormation resource model, and #4521 normalizes it with this
|
|
6
|
+
* lexicon's deep hooks. So an indexed node's `attrs` already are
|
|
7
|
+
* CloudFormation properties, and the import IR is the one the CloudFormation
|
|
8
|
+
* template parser writes (`{ __intrinsic: "Ref" }` and so on), which
|
|
9
|
+
* `CFGenerator` turns into source.
|
|
10
|
+
*
|
|
11
|
+
* - Properties the schema lists in `readOnlyProperties` (the registry's
|
|
12
|
+
* `attrs`) are left out, because no declaration can set them. Tags whose
|
|
13
|
+
* key starts with `aws:` are left out too: CloudFormation sets them and
|
|
14
|
+
* refuses them in a template.
|
|
15
|
+
* - A value that names another imported resource becomes `Ref` when it is
|
|
16
|
+
* that resource's Cloud Control identifier (a single-part one; for the
|
|
17
|
+
* types the catalog joins, Ref returns that identifier), and
|
|
18
|
+
* `GetAtt(<id>, "Arn")` when it is the resource's ARN and the type has an
|
|
19
|
+
* `Arn` attribute. Anything else stays a literal.
|
|
20
|
+
* - A masked value becomes a `String` parameter with `NoEcho`.
|
|
21
|
+
*/
|
|
22
|
+
import { createRequire } from "module";
|
|
23
|
+
import { moduleSourceUrl } from "@intentius/chant/module-source";
|
|
24
|
+
import type { IRNode } from "@intentius/chant/graph-ir";
|
|
25
|
+
import type { IndexImportCodegen, IndexImportTarget } from "@intentius/chant/lifecycle/index-import";
|
|
26
|
+
import type { ParameterIR } from "@intentius/chant/import/parser";
|
|
27
|
+
import { awsKindForListedType } from "./listed-types";
|
|
28
|
+
|
|
29
|
+
const require = createRequire(moduleSourceUrl(import.meta.url));
|
|
30
|
+
|
|
31
|
+
/** One `lexicon-aws.json` entry, the fields this seam reads. */
|
|
32
|
+
export interface ImportManifestEntry {
|
|
33
|
+
resourceType: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
/** GetAtt name -> CloudFormation attribute: the schema's `readOnlyProperties`. */
|
|
36
|
+
attrs?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let cachedManifest: ReadonlyMap<string, ImportManifestEntry> | undefined;
|
|
40
|
+
|
|
41
|
+
/** The generated registry keyed by type, or an empty map in a checkout that has not generated. */
|
|
42
|
+
function defaultManifest(): ReadonlyMap<string, ImportManifestEntry> {
|
|
43
|
+
if (cachedManifest) return cachedManifest;
|
|
44
|
+
try {
|
|
45
|
+
const manifest = require("./generated/lexicon-aws.json") as Record<string, ImportManifestEntry>;
|
|
46
|
+
cachedManifest = new Map(Object.values(manifest).filter((e) => e.kind === "resource").map((e) => [e.resourceType, e]));
|
|
47
|
+
} catch {
|
|
48
|
+
cachedManifest = new Map();
|
|
49
|
+
}
|
|
50
|
+
return cachedManifest;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether `type` is a resource type this lexicon can write: the listed-type
|
|
55
|
+
* rule (./listed-types.ts) against the registry's kinds. The organization
|
|
56
|
+
* segment is not pinned to `AWS`, so `Alexa::ASK::Skill` imports. With no
|
|
57
|
+
* registry (a checkout that has not generated) every well-formed
|
|
58
|
+
* CloudFormation type does, as the listed-type mapping assumes.
|
|
59
|
+
*/
|
|
60
|
+
export function isImportableAwsType(type: string, manifest: ReadonlyMap<string, ImportManifestEntry> = defaultManifest()): boolean {
|
|
61
|
+
return awsKindForListedType(type, manifest.size > 0 ? manifestKinds(manifest) : null) !== undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const kindSets = new WeakMap<ReadonlyMap<string, ImportManifestEntry>, ReadonlySet<string>>();
|
|
65
|
+
|
|
66
|
+
function manifestKinds(manifest: ReadonlyMap<string, ImportManifestEntry>): ReadonlySet<string> {
|
|
67
|
+
let kinds = kindSets.get(manifest);
|
|
68
|
+
if (!kinds) kindSets.set(manifest, (kinds = new Set(manifest.keys())));
|
|
69
|
+
return kinds;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
73
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Tags without the `aws:` ones, in either shape CloudFormation uses (a Key/Value list or a map). */
|
|
77
|
+
function withoutAwsTags(tags: unknown): unknown {
|
|
78
|
+
if (Array.isArray(tags)) {
|
|
79
|
+
return tags.filter((t) => !(isRecord(t) && typeof t.Key === "string" && t.Key.startsWith("aws:")));
|
|
80
|
+
}
|
|
81
|
+
if (isRecord(tags)) {
|
|
82
|
+
return Object.fromEntries(Object.entries(tags).filter(([k]) => !k.startsWith("aws:")));
|
|
83
|
+
}
|
|
84
|
+
return tags;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The properties a declaration of `type` can hold, from an indexed node's attrs. */
|
|
88
|
+
export function awsImportProperties(
|
|
89
|
+
type: string,
|
|
90
|
+
attrs: Record<string, unknown>,
|
|
91
|
+
manifest: ReadonlyMap<string, ImportManifestEntry> = defaultManifest(),
|
|
92
|
+
): Record<string, unknown> {
|
|
93
|
+
const readOnly = new Set(Object.values(manifest.get(type)?.attrs ?? {}).map((a) => a.split(".")[0]));
|
|
94
|
+
const out: Record<string, unknown> = {};
|
|
95
|
+
for (const key of Object.keys(attrs).sort()) {
|
|
96
|
+
if (readOnly.has(key)) continue;
|
|
97
|
+
const value = key === "Tags" ? withoutAwsTags(attrs[key]) : attrs[key];
|
|
98
|
+
if (key === "Tags" && ((Array.isArray(value) && value.length === 0) || (isRecord(value) && Object.keys(value).length === 0))) continue;
|
|
99
|
+
out[key] = value;
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** True when `type` exposes `Arn` to GetAtt, or when there is no registry to ask. */
|
|
105
|
+
function hasArnAttribute(type: string, manifest: ReadonlyMap<string, ImportManifestEntry>): boolean {
|
|
106
|
+
if (manifest.size === 0) return true;
|
|
107
|
+
return Object.values(manifest.get(type)?.attrs ?? {}).includes("Arn");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `value` as a reference to `target`, or undefined. */
|
|
111
|
+
export function awsImportReference(
|
|
112
|
+
value: string,
|
|
113
|
+
target: IndexImportTarget,
|
|
114
|
+
manifest: ReadonlyMap<string, ImportManifestEntry> = defaultManifest(),
|
|
115
|
+
): unknown | undefined {
|
|
116
|
+
const node = target.node;
|
|
117
|
+
if (node.nativeId !== undefined && value === node.nativeId && !value.includes("|")) {
|
|
118
|
+
return { __intrinsic: "Ref", name: target.logicalId };
|
|
119
|
+
}
|
|
120
|
+
const isArn = (node.facts?.cloudIds ?? []).some((c) => c.kind === "arn" && c.value === value);
|
|
121
|
+
if (isArn && hasArnAttribute(node.kind, manifest)) {
|
|
122
|
+
return { __intrinsic: "GetAtt", logicalId: target.logicalId, attribute: "Arn" };
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The resource attributes `chant import --index` writes on every resource it imports (#4536). */
|
|
128
|
+
export const ADOPTED_RESOURCE_ATTRIBUTES: Readonly<Record<string, string>> = { DeletionPolicy: "Retain", UpdateReplacePolicy: "Retain" };
|
|
129
|
+
|
|
130
|
+
export function createAwsIndexImport(manifest?: ReadonlyMap<string, ImportManifestEntry>): IndexImportCodegen {
|
|
131
|
+
const m = () => manifest ?? defaultManifest();
|
|
132
|
+
return {
|
|
133
|
+
resource(node: IRNode) {
|
|
134
|
+
if (!isImportableAwsType(node.kind, m())) return { unsupported: `${node.kind} is not a CloudFormation resource type the aws lexicon generates` };
|
|
135
|
+
// Retain on every imported resource until a person changes it in source
|
|
136
|
+
// (#4536, ruled on choudoufu#2284 Q4): CloudFormation deletes at stack
|
|
137
|
+
// level and reads no per-resource marker, so an adopted object is never
|
|
138
|
+
// deleted on the stack's word alone. Import requires a DeletionPolicy.
|
|
139
|
+
return { type: node.kind, properties: awsImportProperties(node.kind, node.attrs ?? {}, m()), attributes: { ...ADOPTED_RESOURCE_ATTRIBUTES } };
|
|
140
|
+
},
|
|
141
|
+
reference: (value, target) => awsImportReference(value, target, m()),
|
|
142
|
+
secretParameter(name, context): ParameterIR {
|
|
143
|
+
return {
|
|
144
|
+
name,
|
|
145
|
+
type: "String",
|
|
146
|
+
description: `${context.path} of ${context.node.id}, masked in the index`,
|
|
147
|
+
constraints: { NoEcho: true },
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
parameterReference: (name) => ({ __intrinsic: "Ref", name }),
|
|
151
|
+
typeLabel(node) {
|
|
152
|
+
const last = node.kind.split("::").pop() ?? "Resource";
|
|
153
|
+
return last.charAt(0).toUpperCase() + last.slice(1);
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const awsIndexImport: IndexImportCodegen = createAwsIndexImport();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4525 on the aws lexicon: `chant search --index`'s join over the identity
|
|
3
|
+
* fixture (#4523's, ./testdata/indexed/identity.listing.json). A declared
|
|
4
|
+
* source with a bucket and a role made outside chant, a bucket that does not
|
|
5
|
+
* exist, a queue, an instance and a table outside the index's --types, joined
|
|
6
|
+
* through the aws lexicon's own index match. Each row gets one verdict, and
|
|
7
|
+
* the overlay carries what the index read onto the bound rows only.
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { describe, expect, test } from "vitest";
|
|
12
|
+
import type { GraphIR, IRNode } from "@intentius/chant/graph-ir";
|
|
13
|
+
import type { IndexIdentity } from "@intentius/chant/lifecycle/identity-match";
|
|
14
|
+
import { joinDeclaredToIndex } from "@intentius/chant/lifecycle/index-join";
|
|
15
|
+
import { typeListing, type ListingLexicon, type ListingResult } from "@intentius/chant/lifecycle/type-listing";
|
|
16
|
+
import { awsDeclaredIdentity, awsIndexIdentity, type IdentityManifestEntry } from "./index-identity";
|
|
17
|
+
import { awsKindForListedType } from "./listed-types";
|
|
18
|
+
import { awsPlugin } from "./plugin";
|
|
19
|
+
|
|
20
|
+
// The manifest rows these types generate, as index-identity.test.ts reads them.
|
|
21
|
+
const ROWS: IdentityManifestEntry[] = [
|
|
22
|
+
{ resourceType: "AWS::S3::Bucket", kind: "resource", primaryIdentifier: ["BucketName"], attrs: { Arn: "Arn", DomainName: "DomainName", RegionalDomainName: "RegionalDomainName", WebsiteURL: "WebsiteURL" } },
|
|
23
|
+
{ resourceType: "AWS::IAM::Role", kind: "resource", primaryIdentifier: ["RoleName"], attrs: { Arn: "Arn", RoleId: "RoleId" } },
|
|
24
|
+
{ resourceType: "AWS::SQS::Queue", kind: "resource", primaryIdentifier: ["QueueUrl"], attrs: { Arn: "Arn", QueueUrl: "QueueUrl" } },
|
|
25
|
+
{ resourceType: "AWS::EC2::Instance", kind: "resource", primaryIdentifier: ["InstanceId"], attrs: { InstanceId: "InstanceId", PrivateIp: "PrivateIp", PublicIp: "PublicIp" } },
|
|
26
|
+
{ resourceType: "AWS::DynamoDB::Table", kind: "resource", primaryIdentifier: ["TableName"], attrs: { Arn: "Arn", StreamArn: "StreamArn" } },
|
|
27
|
+
];
|
|
28
|
+
const MANIFEST: ReadonlyMap<string, IdentityManifestEntry> = new Map(ROWS.map((e) => [e.resourceType, e]));
|
|
29
|
+
const identity: IndexIdentity = { ...awsIndexIdentity, declaredIdentity: (t, p) => awsDeclaredIdentity(t, p, MANIFEST) };
|
|
30
|
+
const KINDS: ReadonlySet<string> = new Set(MANIFEST.keys());
|
|
31
|
+
const aws: ListingLexicon = {
|
|
32
|
+
name: awsPlugin.name,
|
|
33
|
+
deepNormalizationHooks: awsPlugin.deepNormalizationHooks,
|
|
34
|
+
listedTypes: { ...awsPlugin.listedTypes!, kindFor: (t) => awsKindForListedType(t, KINDS) },
|
|
35
|
+
};
|
|
36
|
+
const listing = JSON.parse(readFileSync(join(import.meta.dirname, "testdata", "indexed", "identity.listing.json"), "utf-8")) as ListingResult;
|
|
37
|
+
const doc = typeListing(listing, [aws]);
|
|
38
|
+
|
|
39
|
+
const node = (name: string, kind: string, attrs: Record<string, unknown>): IRNode => ({ id: `app::${name}`, kind, lexicon: "aws", attrs });
|
|
40
|
+
const declared: GraphIR = {
|
|
41
|
+
version: 1,
|
|
42
|
+
nodes: [
|
|
43
|
+
node("assets", "AWS::S3::Bucket", { BucketName: "cli-made-assets" }),
|
|
44
|
+
node("runner", "AWS::IAM::Role", { RoleName: "cli-made-role", AssumeRolePolicyDocument: {} }),
|
|
45
|
+
node("archive", "AWS::S3::Bucket", { BucketName: "never-made-archive" }),
|
|
46
|
+
node("jobs", "AWS::SQS::Queue", { QueueName: "cli-made-queue" }),
|
|
47
|
+
node("box", "AWS::EC2::Instance", { InstanceType: "t3.micro", ImageId: "ami-0abcdef1234567890" }),
|
|
48
|
+
node("carts", "AWS::DynamoDB::Table", { TableName: "carts" }),
|
|
49
|
+
],
|
|
50
|
+
edges: [],
|
|
51
|
+
groups: { byLexicon: {} },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
describe("search --index's join on the aws fixture", () => {
|
|
55
|
+
const { ir, joins } = joinDeclaredToIndex(declared, doc, [{ name: "aws", indexIdentity: identity }], { regionOf: () => "us-east-1" });
|
|
56
|
+
const row = (name: string) => ir.nodes.find((n) => n.id === `app::${name}`)!;
|
|
57
|
+
|
|
58
|
+
test("the bucket and role made outside chant are bound, with what the index read about them", () => {
|
|
59
|
+
expect(joins["app::assets"]).toMatchObject({ verdict: "bound", node: "aws/000000000000/us-east-1/AWS::S3::Bucket/cli-made-assets", nativeId: "cli-made-assets" });
|
|
60
|
+
expect(joins["app::runner"]).toMatchObject({ verdict: "bound", node: "aws/000000000000/global/AWS::IAM::Role/cli-made-role", location: "global" });
|
|
61
|
+
expect(row("assets").physicalId).toBe("cli-made-assets");
|
|
62
|
+
// The aws hooks prune read-only properties such as Arn from the indexed tree
|
|
63
|
+
// (#4521: an indexed tree has the shape an observed one has); the index
|
|
64
|
+
// carries the ARN as a cloud id in the node's facts.
|
|
65
|
+
expect(row("assets").attrs?.BucketName).toBe("cli-made-assets");
|
|
66
|
+
expect(row("assets").facts?.cloudIds).toContainEqual({ kind: "arn", value: "arn:aws:s3:::cli-made-assets" });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the bucket the index listed and did not find is absent", () => {
|
|
70
|
+
expect(joins["app::archive"]).toMatchObject({ verdict: "absent", identifier: "never-made-archive", location: "us-east-1" });
|
|
71
|
+
expect(row("archive").physicalId).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("the queue and the instance spell no identity: no-binding, though both are indexed", () => {
|
|
75
|
+
expect(joins["app::jobs"]).toMatchObject({ verdict: "no-binding", detail: expect.stringContaining("QueueUrl") });
|
|
76
|
+
expect(joins["app::box"]).toMatchObject({ verdict: "no-binding", detail: expect.stringContaining("InstanceId") });
|
|
77
|
+
expect(row("jobs").physicalId).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("the table outside --types is not observed, filtered", () => {
|
|
81
|
+
expect(joins["app::carts"]).toMatchObject({ verdict: "not-observed", reason: "filtered", listedType: "AWS::DynamoDB::Table" });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("only the declared rows are in the answer", () => {
|
|
85
|
+
expect(ir.nodes.map((n) => n.id).sort()).toEqual(declared.nodes.map((n) => n.id).sort());
|
|
86
|
+
});
|
|
87
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4521 on the aws lexicon: Cloud Control's type names mapped to kinds, a
|
|
3
|
+
* fixture listing typed into nodes, and a capability that answers the same
|
|
4
|
+
* over the indexed fixture as over the equivalent declared graph.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { describe, expect, it } from "vitest";
|
|
9
|
+
import type { GraphIR } from "@intentius/chant/graph-ir";
|
|
10
|
+
import { typeListing, type ListingLexicon, type ListingResult } from "@intentius/chant/lifecycle/type-listing";
|
|
11
|
+
import { CapabilityEngine } from "@intentius/chant/capabilities/matcher";
|
|
12
|
+
import { buildView, displayName } from "@intentius/chant/capabilities/view";
|
|
13
|
+
import { resolvePacks, shippedRules } from "@intentius/chant/capabilities/catalog";
|
|
14
|
+
import { MASKED } from "@intentius/chant/deep-observation";
|
|
15
|
+
import { awsCapabilityPack } from "./capabilities/pack";
|
|
16
|
+
import { awsKindForListedType, awsListedTypeForKind } from "./listed-types";
|
|
17
|
+
import { awsPlugin } from "./plugin";
|
|
18
|
+
|
|
19
|
+
const here = import.meta.dirname;
|
|
20
|
+
const surface = JSON.parse(readFileSync(join(here, "..", "surface.snapshot.json"), "utf-8")) as {
|
|
21
|
+
entries: Record<string, { kind: string; resourceType: string }>;
|
|
22
|
+
};
|
|
23
|
+
const KINDS: ReadonlySet<string> = new Set(
|
|
24
|
+
Object.values(surface.entries).filter((e) => e.kind === "resource").map((e) => e.resourceType),
|
|
25
|
+
);
|
|
26
|
+
const listing = JSON.parse(readFileSync(join(here, "testdata", "indexed", "listing.json"), "utf-8")) as ListingResult;
|
|
27
|
+
|
|
28
|
+
// The plugin's own hooks, with the kind set pinned to the checked-in surface so
|
|
29
|
+
// the test does not depend on whether `chant generate` has run.
|
|
30
|
+
const aws: ListingLexicon = {
|
|
31
|
+
name: awsPlugin.name,
|
|
32
|
+
deepNormalizationHooks: awsPlugin.deepNormalizationHooks,
|
|
33
|
+
listedTypes: { ...awsPlugin.listedTypes!, kindFor: (t) => awsKindForListedType(t, KINDS) },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe("Cloud Control types to aws kinds", () => {
|
|
37
|
+
it("every aws resource kind has a listed type that maps back to it", () => {
|
|
38
|
+
const missing = [...KINDS].filter((k) => awsKindForListedType(awsListedTypeForKind(k), KINDS) !== k);
|
|
39
|
+
expect(missing).toEqual([]);
|
|
40
|
+
expect(KINDS.size).toBeGreaterThan(1000);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("a type outside the lexicon, or not a CloudFormation name, has no kind", () => {
|
|
44
|
+
expect(awsKindForListedType("AWS::IoTFleetHub::Application", KINDS)).toBeUndefined();
|
|
45
|
+
expect(awsKindForListedType("aws_s3_bucket", KINDS)).toBeUndefined();
|
|
46
|
+
expect(awsKindForListedType("Alexa::ASK::Skill", KINDS)).toBe("Alexa::ASK::Skill");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("the plugin declares the mapping for the aws substrate", () => {
|
|
50
|
+
expect(awsPlugin.listedTypes?.substrate).toBe("aws");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("the aws fixture listing as typed nodes", () => {
|
|
55
|
+
const doc = typeListing(listing, [aws]);
|
|
56
|
+
|
|
57
|
+
it("produces a typed node per mapped object, and an unknown-kind node for the rest", () => {
|
|
58
|
+
expect(doc.graph.nodes.map((n) => [n.nativeId, n.kind, n.unmappedKind ?? false])).toEqual([
|
|
59
|
+
["vol-0a1b2c3d4e5f60718", "AWS::EC2::Volume", false],
|
|
60
|
+
["fleet-console", "AWS::IoTFleetHub::Application", true],
|
|
61
|
+
["orders-db", "AWS::RDS::DBInstance", false],
|
|
62
|
+
["reports-db", "AWS::RDS::DBInstance", false],
|
|
63
|
+
["shop-assets", "AWS::S3::Bucket", false],
|
|
64
|
+
]);
|
|
65
|
+
expect(doc.graph.nodes).toHaveLength(listing.resources.length);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("normalizes through the aws hooks: read-only properties pruned, secrets masked", () => {
|
|
69
|
+
const bucket = doc.graph.nodes.find((n) => n.nativeId === "shop-assets")!;
|
|
70
|
+
expect(bucket.attrs).toEqual({ BucketName: "shop-assets" });
|
|
71
|
+
const db = doc.graph.nodes.find((n) => n.nativeId === "orders-db")!;
|
|
72
|
+
expect(db.attrs.MasterUserPassword).toBe(MASKED);
|
|
73
|
+
expect(db.attrs.StorageEncrypted).toBe(true);
|
|
74
|
+
expect(db.facts?.markers).toEqual({ owner: "shop", encoding: "escaped", source: "live" });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("encrypted-at-rest matches the same resources over the index as over the declared graph", () => {
|
|
78
|
+
// The declared form of the same three resources, as source would carry them.
|
|
79
|
+
const declared: GraphIR = {
|
|
80
|
+
nodes: [
|
|
81
|
+
{ id: "orders-db", kind: "AWS::RDS::DBInstance", lexicon: "aws", attrs: { DBInstanceIdentifier: "orders-db", Engine: "postgres", StorageEncrypted: true } },
|
|
82
|
+
{ id: "reports-db", kind: "AWS::RDS::DBInstance", lexicon: "aws", attrs: { DBInstanceIdentifier: "reports-db", Engine: "postgres", StorageEncrypted: false } },
|
|
83
|
+
{ id: "vol-0a1b2c3d4e5f60718", kind: "AWS::EC2::Volume", lexicon: "aws", attrs: { AvailabilityZone: "us-east-1a", Size: 20, Encrypted: true } },
|
|
84
|
+
{ id: "shop-assets", kind: "AWS::S3::Bucket", lexicon: "aws", attrs: { BucketName: "shop-assets" } },
|
|
85
|
+
],
|
|
86
|
+
edges: [],
|
|
87
|
+
groups: {},
|
|
88
|
+
};
|
|
89
|
+
const answer = (g: GraphIR) => {
|
|
90
|
+
const e = new CapabilityEngine(buildView(g, resolvePacks([awsCapabilityPack])), shippedRules().rules);
|
|
91
|
+
return [...e.set("encrypted-at-rest", e.bind("encrypted-at-rest", [] as never)).keys()].map(displayName).sort();
|
|
92
|
+
};
|
|
93
|
+
// aws.paths: S3 buckets are always encrypted at rest; the unencrypted database is the one left out.
|
|
94
|
+
expect(answer(declared)).toEqual(["orders-db", "shop-assets", "vol-0a1b2c3d4e5f60718"]);
|
|
95
|
+
expect(answer(doc.graph)).toEqual(answer(declared));
|
|
96
|
+
});
|
|
97
|
+
});
|