@intentius/chant-lexicon-azure 0.124.34 → 0.124.36
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/read-client.d.ts.map +1 -1
- package/dist/api/read-client.js +2 -1
- package/dist/arm-type.d.ts +21 -0
- package/dist/arm-type.d.ts.map +1 -0
- package/dist/arm-type.js +31 -0
- package/dist/deep-observe.d.ts +9 -0
- package/dist/deep-observe.d.ts.map +1 -1
- package/dist/deep-observe.js +42 -0
- package/dist/graph-edges.d.ts +21 -0
- package/dist/graph-edges.d.ts.map +1 -0
- package/dist/graph-edges.js +71 -0
- package/dist/integrity.json +3 -3
- package/dist/lint/post-synth/arm-refs.d.ts +2 -0
- package/dist/lint/post-synth/arm-refs.d.ts.map +1 -1
- package/dist/lint/post-synth/arm-refs.js +6 -1
- package/dist/manifest.json +1 -1
- package/dist/op/activities/az-apply.d.ts +22 -2
- package/dist/op/activities/az-apply.d.ts.map +1 -1
- package/dist/op/activities/az-apply.js +49 -17
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/rules/arm-refs.ts +6 -1
- package/dist/serializer.d.ts +9 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +20 -6
- package/package.json +2 -2
- package/src/api/read-client.ts +2 -1
- package/src/arm-type.test.ts +47 -0
- package/src/arm-type.ts +31 -0
- package/src/deep-observe.test.ts +56 -1
- package/src/deep-observe.ts +41 -0
- package/src/graph-edges.test.ts +94 -0
- package/src/graph-edges.ts +72 -0
- package/src/lint/post-synth/arm-refs.ts +6 -1
- package/src/op/activities/az-apply.test.ts +81 -0
- package/src/op/activities/az-apply.ts +55 -13
- package/src/plugin.ts +3 -0
- package/src/serializer.ts +21 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-client.d.ts","sourceRoot":"","sources":["../../src/api/read-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG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AC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAgB/F;AAED,8FAA8F;AAC9F,wBAAsB,eAAe,CACnC,OAAO,EAAE,sBAAsB,EAC/B,EAAE,EAAE,MAAM,EACV,UAAU,SAAsB,GAC/B,OAAO,CAAC,eAAe,CAAC,CAc1B;AAED,sHAAsH;AACtH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,eAAe,CAAC,CAa1B"}
|
package/dist/api/read-client.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* wants a bearer token. The `az` CLI path remains for a signed read until
|
|
19
19
|
* token acquisition lands here.
|
|
20
20
|
*/
|
|
21
|
+
import { armResourcePath } from "../arm-type.js";
|
|
21
22
|
/** Default ARM host, matching the applier's. */
|
|
22
23
|
const DEFAULT_ENDPOINT = "https://management.azure.com";
|
|
23
24
|
/** floci-az's fixed local subscription, matching the applier's. */
|
|
@@ -53,7 +54,7 @@ const defaultHttp = async (method, url, body, signal) => {
|
|
|
53
54
|
export function armResourceReadUrl(options, type, name, apiVersion = DEFAULT_API_VERSION) {
|
|
54
55
|
const base = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/$/, "");
|
|
55
56
|
const subscription = options.subscriptionId ?? DEFAULT_SUBSCRIPTION;
|
|
56
|
-
return `${base}/subscriptions/${subscription}/resourceGroups/${options.resourceGroup}/providers/${type
|
|
57
|
+
return `${base}/subscriptions/${subscription}/resourceGroups/${options.resourceGroup}/providers/${armResourcePath(type, name)}?api-version=${apiVersion}`;
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
59
60
|
* ARM's error envelope is `{ error: { code, message } }`. Reading the code
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARM resource types as ARM spells them (#4230).
|
|
3
|
+
*
|
|
4
|
+
* The lexicon's entity types come from the ARM schema ids, which join a child
|
|
5
|
+
* type to its parent with `_` (`Microsoft.Network/virtualNetworks_subnets`).
|
|
6
|
+
* ARM itself joins them with `/` (`Microsoft.Network/virtualNetworks/subnets`),
|
|
7
|
+
* in a template's `type`, in `resourceId()` and in the resource URL. Resource
|
|
8
|
+
* type segments never contain `_`, so every `_` after the namespace is a
|
|
9
|
+
* child separator.
|
|
10
|
+
*/
|
|
11
|
+
/** `Microsoft.Network/virtualNetworks_subnets` → `Microsoft.Network/virtualNetworks/subnets`. Idempotent. */
|
|
12
|
+
export declare function armType(entityType: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* The provider-relative path of one resource: each type segment followed by
|
|
15
|
+
* its name segment, as ARM's `resourceId()` builds it.
|
|
16
|
+
* `('Microsoft.Network/virtualNetworks/subnets', 'vnet/apps')` →
|
|
17
|
+
* `Microsoft.Network/virtualNetworks/vnet/subnets/apps`. A name with fewer
|
|
18
|
+
* segments than the type has kinds is joined as given.
|
|
19
|
+
*/
|
|
20
|
+
export declare function armResourcePath(type: string, name: string): string;
|
|
21
|
+
//# sourceMappingURL=arm-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arm-type.d.ts","sourceRoot":"","sources":["../src/arm-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6GAA6G;AAC7G,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKlE"}
|
package/dist/arm-type.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARM resource types as ARM spells them (#4230).
|
|
3
|
+
*
|
|
4
|
+
* The lexicon's entity types come from the ARM schema ids, which join a child
|
|
5
|
+
* type to its parent with `_` (`Microsoft.Network/virtualNetworks_subnets`).
|
|
6
|
+
* ARM itself joins them with `/` (`Microsoft.Network/virtualNetworks/subnets`),
|
|
7
|
+
* in a template's `type`, in `resourceId()` and in the resource URL. Resource
|
|
8
|
+
* type segments never contain `_`, so every `_` after the namespace is a
|
|
9
|
+
* child separator.
|
|
10
|
+
*/
|
|
11
|
+
/** `Microsoft.Network/virtualNetworks_subnets` → `Microsoft.Network/virtualNetworks/subnets`. Idempotent. */
|
|
12
|
+
export function armType(entityType) {
|
|
13
|
+
const slash = entityType.indexOf("/");
|
|
14
|
+
if (slash < 0)
|
|
15
|
+
return entityType;
|
|
16
|
+
return entityType.slice(0, slash + 1) + entityType.slice(slash + 1).replace(/_/g, "/");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The provider-relative path of one resource: each type segment followed by
|
|
20
|
+
* its name segment, as ARM's `resourceId()` builds it.
|
|
21
|
+
* `('Microsoft.Network/virtualNetworks/subnets', 'vnet/apps')` →
|
|
22
|
+
* `Microsoft.Network/virtualNetworks/vnet/subnets/apps`. A name with fewer
|
|
23
|
+
* segments than the type has kinds is joined as given.
|
|
24
|
+
*/
|
|
25
|
+
export function armResourcePath(type, name) {
|
|
26
|
+
const [namespace, ...kinds] = armType(type).split("/");
|
|
27
|
+
const names = name.split("/");
|
|
28
|
+
if (kinds.length <= 1 || names.length !== kinds.length)
|
|
29
|
+
return `${armType(type)}/${name}`;
|
|
30
|
+
return [namespace, ...kinds.flatMap((kind, i) => [kind, names[i]])].join("/");
|
|
31
|
+
}
|
package/dist/deep-observe.d.ts
CHANGED
|
@@ -79,6 +79,15 @@ export declare const AZURE_SERVER_COMPUTED_NAMES: ReadonlySet<string>;
|
|
|
79
79
|
* additive and needs no contract change.
|
|
80
80
|
*/
|
|
81
81
|
export declare const AZURE_SERVICE_DEFAULTS: Record<string, Record<string, unknown>>;
|
|
82
|
+
/**
|
|
83
|
+
* The canonical key for one entry of `identity.userAssignedIdentities`
|
|
84
|
+
* (#4231): `<type>/<name>` lowercased, from either spelling. Source keys the
|
|
85
|
+
* map by `[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities',
|
|
86
|
+
* 'appId')]`; ARM answers with the evaluated id, `/subscriptions/.../providers/
|
|
87
|
+
* Microsoft.ManagedIdentity/userAssignedIdentities/appId`, in whatever case it
|
|
88
|
+
* stored. A key in neither form is left as it is.
|
|
89
|
+
*/
|
|
90
|
+
export declare function userAssignedIdentityKey(key: string): string;
|
|
82
91
|
/**
|
|
83
92
|
* The azure lexicon's noise rules. Three classes, same as AWS: server-
|
|
84
93
|
* populated fields (by name, unconditional), controller-injected boilerplate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-observe.d.ts","sourceRoot":"","sources":["../src/deep-observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAIH,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EAGV,sBAAsB,EACtB,qBAAqB,EAGtB,MAAM,0BAA0B,CAAC;AA+DlC;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CASpD,CAAC;AAUH;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAI1D,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI1E,CAAC;AA+DF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,EAAE,
|
|
1
|
+
{"version":3,"file":"deep-observe.d.ts","sourceRoot":"","sources":["../src/deep-observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAIH,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EAGV,sBAAsB,EACtB,qBAAqB,EAGtB,MAAM,0BAA0B,CAAC;AA+DlC;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,MAAM,CASpD,CAAC;AAUH;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAI1D,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI1E,CAAC;AA+DF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM3D;AAyBD;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,EAAE,sBA2EzC,CAAC;AAIF,MAAM,WAAW,uBAAuB;IACtC,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CAC/E;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAkEhC"}
|
package/dist/deep-observe.js
CHANGED
|
@@ -203,6 +203,47 @@ function lastSegment(pattern) {
|
|
|
203
203
|
const dot = withoutIndex.lastIndexOf(".");
|
|
204
204
|
return dot === -1 ? withoutIndex : withoutIndex.slice(dot + 1);
|
|
205
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* The canonical key for one entry of `identity.userAssignedIdentities`
|
|
208
|
+
* (#4231): `<type>/<name>` lowercased, from either spelling. Source keys the
|
|
209
|
+
* map by `[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities',
|
|
210
|
+
* 'appId')]`; ARM answers with the evaluated id, `/subscriptions/.../providers/
|
|
211
|
+
* Microsoft.ManagedIdentity/userAssignedIdentities/appId`, in whatever case it
|
|
212
|
+
* stored. A key in neither form is left as it is.
|
|
213
|
+
*/
|
|
214
|
+
export function userAssignedIdentityKey(key) {
|
|
215
|
+
const expr = /^\[\s*resourceId\(\s*'([^']+)'\s*,\s*'([^']+)'\s*\)\s*\]$/.exec(key);
|
|
216
|
+
if (expr)
|
|
217
|
+
return `${expr[1]}/${expr[2]}`.toLowerCase();
|
|
218
|
+
const at = key.toLowerCase().lastIndexOf("/providers/");
|
|
219
|
+
if (at !== -1 && key.startsWith("/subscriptions/"))
|
|
220
|
+
return key.slice(at + "/providers/".length).toLowerCase();
|
|
221
|
+
return key;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Rekey `identity.userAssignedIdentities` by {@link userAssignedIdentityKey},
|
|
225
|
+
* on a copy, and drop the `principalId` and `clientId` ARM fills in on each
|
|
226
|
+
* entry. Nobody declares them, and pruning them later would leave the live
|
|
227
|
+
* entry empty and gone, where source declares `{}`.
|
|
228
|
+
*/
|
|
229
|
+
function rekeyUserAssignedIdentities(tree) {
|
|
230
|
+
const identity = tree.identity;
|
|
231
|
+
if (!identity || typeof identity !== "object" || Array.isArray(identity))
|
|
232
|
+
return tree;
|
|
233
|
+
const assigned = identity.userAssignedIdentities;
|
|
234
|
+
if (!assigned || typeof assigned !== "object" || Array.isArray(assigned))
|
|
235
|
+
return tree;
|
|
236
|
+
const rekeyed = {};
|
|
237
|
+
for (const [k, v] of Object.entries(assigned)) {
|
|
238
|
+
let entry = v;
|
|
239
|
+
if (entry && typeof entry === "object" && !Array.isArray(entry)) {
|
|
240
|
+
const { principalId: _p, clientId: _c, ...rest } = entry;
|
|
241
|
+
entry = rest;
|
|
242
|
+
}
|
|
243
|
+
rekeyed[userAssignedIdentityKey(k)] = entry;
|
|
244
|
+
}
|
|
245
|
+
return { ...tree, identity: { ...identity, userAssignedIdentities: rekeyed } };
|
|
246
|
+
}
|
|
206
247
|
/**
|
|
207
248
|
* The azure lexicon's noise rules. Three classes, same as AWS: server-
|
|
208
249
|
* populated fields (by name, unconditional), controller-injected boilerplate
|
|
@@ -213,6 +254,7 @@ function lastSegment(pattern) {
|
|
|
213
254
|
* since it is a plain object; only the *default empty map* needs a rule here).
|
|
214
255
|
*/
|
|
215
256
|
export const azureDeepNormalizationHooks = {
|
|
257
|
+
prepare: (tree) => rekeyUserAssignedIdentities(tree),
|
|
216
258
|
prune(node) {
|
|
217
259
|
const name = lastSegment(node.pattern);
|
|
218
260
|
if (AZURE_READ_ONLY_NAMES.has(name) || AZURE_UNCONDITIONAL_PRUNE_NAMES.has(name))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* References written as ARM expressions, as graph edges (#4232).
|
|
3
|
+
*
|
|
4
|
+
* `chant graph` draws an edge for every `AttrRef` it finds in props, but an
|
|
5
|
+
* Azure reference is often an expression instead: `reference(resourceId(...))
|
|
6
|
+
* .customerId` and `listKeys(...)` for a value the resource has no attribute
|
|
7
|
+
* for, or a `resourceId(...)` used as an object key, which is how
|
|
8
|
+
* `identity.userAssignedIdentities` names an identity. The serializer already
|
|
9
|
+
* reads these to write `dependsOn` (./serializer.ts), with
|
|
10
|
+
* `findArmResourceRefs` (./lint/post-synth/arm-refs.ts). This module runs the
|
|
11
|
+
* same extraction over each prop as the template writes it and reports each
|
|
12
|
+
* reference to a declared resource through the plugin's `graphEdges` hook.
|
|
13
|
+
*
|
|
14
|
+
* A reference matches by resource name, never by type, as the serializer's
|
|
15
|
+
* inference does. A name nothing in the project declares is left out: it is
|
|
16
|
+
* an existing resource the template reads, not a dangling reference.
|
|
17
|
+
*/
|
|
18
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
19
|
+
import type { LexiconGraphEdges } from "@intentius/chant/graph-ir";
|
|
20
|
+
export declare function azureGraphEdges(entities: ReadonlyMap<string, Declarable>): LexiconGraphEdges | undefined;
|
|
21
|
+
//# sourceMappingURL=graph-edges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-edges.d.ts","sourceRoot":"","sources":["../src/graph-edges.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAyB,MAAM,2BAA2B,CAAC;AAQ1F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,iBAAiB,GAAG,SAAS,CA2CxG"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* References written as ARM expressions, as graph edges (#4232).
|
|
3
|
+
*
|
|
4
|
+
* `chant graph` draws an edge for every `AttrRef` it finds in props, but an
|
|
5
|
+
* Azure reference is often an expression instead: `reference(resourceId(...))
|
|
6
|
+
* .customerId` and `listKeys(...)` for a value the resource has no attribute
|
|
7
|
+
* for, or a `resourceId(...)` used as an object key, which is how
|
|
8
|
+
* `identity.userAssignedIdentities` names an identity. The serializer already
|
|
9
|
+
* reads these to write `dependsOn` (./serializer.ts), with
|
|
10
|
+
* `findArmResourceRefs` (./lint/post-synth/arm-refs.ts). This module runs the
|
|
11
|
+
* same extraction over each prop as the template writes it and reports each
|
|
12
|
+
* reference to a declared resource through the plugin's `graphEdges` hook.
|
|
13
|
+
*
|
|
14
|
+
* A reference matches by resource name, never by type, as the serializer's
|
|
15
|
+
* inference does. A name nothing in the project declares is left out: it is
|
|
16
|
+
* an existing resource the template reads, not a dangling reference.
|
|
17
|
+
*/
|
|
18
|
+
import { isPropertyDeclarable, isResourceDeclarable } from "@intentius/chant/declarable";
|
|
19
|
+
import { findArmResourceRefs } from "./lint/post-synth/arm-refs.js";
|
|
20
|
+
import { armResourceName, toArmValue } from "./serializer.js";
|
|
21
|
+
function isAzureResource(entity) {
|
|
22
|
+
return entity.lexicon === "azure" && isResourceDeclarable(entity) && !isPropertyDeclarable(entity);
|
|
23
|
+
}
|
|
24
|
+
export function azureGraphEdges(entities) {
|
|
25
|
+
const entityNames = new Map();
|
|
26
|
+
for (const [key, entity] of entities)
|
|
27
|
+
entityNames.set(entity, key);
|
|
28
|
+
// Template name -> entity key, for the resources whose name is a literal.
|
|
29
|
+
const byArmName = new Map();
|
|
30
|
+
for (const [key, entity] of entities) {
|
|
31
|
+
if (!isAzureResource(entity))
|
|
32
|
+
continue;
|
|
33
|
+
const name = armResourceName(entity, key, entityNames);
|
|
34
|
+
if (typeof name === "string")
|
|
35
|
+
byArmName.set(name, key);
|
|
36
|
+
}
|
|
37
|
+
if (byArmName.size === 0)
|
|
38
|
+
return undefined;
|
|
39
|
+
const references = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
const add = (from, to, viaAttr) => {
|
|
42
|
+
if (!to || to === from)
|
|
43
|
+
return;
|
|
44
|
+
const id = `${from}\0${to}\0${viaAttr}`;
|
|
45
|
+
if (seen.has(id))
|
|
46
|
+
return;
|
|
47
|
+
seen.add(id);
|
|
48
|
+
references.push({ from, to, kind: "ref", viaAttr });
|
|
49
|
+
};
|
|
50
|
+
for (const [key, entity] of entities) {
|
|
51
|
+
if (!isAzureResource(entity))
|
|
52
|
+
continue;
|
|
53
|
+
const props = entity.props;
|
|
54
|
+
if (props && typeof props === "object") {
|
|
55
|
+
for (const [attr, value] of Object.entries(props)) {
|
|
56
|
+
if (value === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
for (const ref of findArmResourceRefs(toArmValue(value, entityNames))) {
|
|
59
|
+
add(key, byArmName.get(ref), attr);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// A child resource named "vnet/subnet" depends on "vnet", as the
|
|
64
|
+
// serializer infers for dependsOn.
|
|
65
|
+
const name = armResourceName(entity, key, entityNames);
|
|
66
|
+
if (typeof name === "string" && name.includes("/")) {
|
|
67
|
+
add(key, byArmName.get(name.split("/")[0]), "name");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return references.length > 0 ? { references } : undefined;
|
|
71
|
+
}
|
package/dist/integrity.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"algorithm": "sha256",
|
|
3
3
|
"artifacts": {
|
|
4
|
-
"manifest.json": "
|
|
4
|
+
"manifest.json": "36de6ef8e05614017db514e3079f85c0ee351a10d531295139153e90c28e7f16",
|
|
5
5
|
"meta.json": "d2521221ed616d882ded4296f0071685bd74e4b645d55dabc9685733c37dc419",
|
|
6
6
|
"types/index.d.ts": "29631032bda9533849178968290e65d72250eab0b8bab424f2d9ef9b4e8546a4",
|
|
7
7
|
"rules/hardcoded-location.ts": "0b895449c8c94066e81721c46be24249231029fe13b471477456df5c4e45b8bf",
|
|
8
8
|
"rules/nsg-wildcard.ts": "8f9d44833ba364778c05731f84c20f00734bb0d40d9fd0d91645965d18a258ae",
|
|
9
9
|
"rules/storage-https.ts": "d340ba970bd9b35304bd7d288a9e99610a7677e6c56af4846305a98d4df0fbbc",
|
|
10
|
-
"rules/arm-refs.ts": "
|
|
10
|
+
"rules/arm-refs.ts": "56521a730d566538cebd21037b7a291f4cdb909fa0d7213c80cac2633f154501",
|
|
11
11
|
"rules/azr010.ts": "c61da411a3b325d49f2f790030f11aa4d518a671a23ff3d13be5206e2ddfedab",
|
|
12
12
|
"rules/azr011.ts": "81b05ecaaf6e90a8afc692cd203d28eddf6126a3d7d9d4d4955e4aa6f2c7fa4c",
|
|
13
13
|
"rules/azr012.ts": "e59ddbab64c0bddd2d65bd5cb66e976f858d86216825a18837653d14224a321e",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"skills/chant-azure-patterns.md": "1a3bacfac612826b77332d2692a59195638db9f1b5e8ea2eda7579621d25f603",
|
|
38
38
|
"skills/chant-azure-aks.md": "2d4e0098c1a22b54ffadd410564d9df0f3a04cb4eb7c6261f20ae33106e7aca8"
|
|
39
39
|
},
|
|
40
|
-
"composite": "
|
|
40
|
+
"composite": "afff685e577b82053fbad1e626d8078471c1deb87047216fc0cfd7a7166d6eaa"
|
|
41
41
|
}
|
|
@@ -43,6 +43,8 @@ export declare function parseArmTemplate(output: string | {
|
|
|
43
43
|
* - [reference('myStorage')]
|
|
44
44
|
* - [reference('myStorage').primaryEndpoints.blob]
|
|
45
45
|
*
|
|
46
|
+
* Object keys are read as well as values.
|
|
47
|
+
*
|
|
46
48
|
* Returns the set of resource names found in these references.
|
|
47
49
|
*/
|
|
48
50
|
export declare function findArmResourceRefs(value: unknown): Set<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arm-refs.d.ts","sourceRoot":"","sources":["../../../src/lint/post-synth/arm-refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,EAAE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AAI,CAWzF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAI/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBhE"}
|
|
@@ -32,6 +32,8 @@ export function parseArmTemplate(output) {
|
|
|
32
32
|
* - [reference('myStorage')]
|
|
33
33
|
* - [reference('myStorage').primaryEndpoints.blob]
|
|
34
34
|
*
|
|
35
|
+
* Object keys are read as well as values.
|
|
36
|
+
*
|
|
35
37
|
* Returns the set of resource names found in these references.
|
|
36
38
|
*/
|
|
37
39
|
export function findArmResourceRefs(value) {
|
|
@@ -89,7 +91,10 @@ function walkArmValue(value, refs) {
|
|
|
89
91
|
}
|
|
90
92
|
if (typeof value === "object") {
|
|
91
93
|
const obj = value;
|
|
92
|
-
for (const val of Object.
|
|
94
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
95
|
+
// A key can be an expression too: a user-assigned identity is named by
|
|
96
|
+
// its resource ID as the key of identity.userAssignedIdentities.
|
|
97
|
+
walkArmValue(key, refs);
|
|
93
98
|
walkArmValue(val, refs);
|
|
94
99
|
}
|
|
95
100
|
}
|
package/dist/manifest.json
CHANGED
|
@@ -9,6 +9,11 @@ export interface ArmResource {
|
|
|
9
9
|
sku?: unknown;
|
|
10
10
|
kind?: unknown;
|
|
11
11
|
tags?: Record<string, string>;
|
|
12
|
+
identity?: unknown;
|
|
13
|
+
zones?: unknown;
|
|
14
|
+
plan?: unknown;
|
|
15
|
+
extendedLocation?: unknown;
|
|
16
|
+
managedBy?: unknown;
|
|
12
17
|
dependsOn?: unknown;
|
|
13
18
|
}
|
|
14
19
|
/** Injectable HTTP client — mirrors the GCP applier so tests avoid the network. */
|
|
@@ -31,9 +36,24 @@ export interface ArmEvalCtx {
|
|
|
31
36
|
base: string;
|
|
32
37
|
signal?: AbortSignal;
|
|
33
38
|
}
|
|
39
|
+
/** The ARM resource id of a resource in the context's group. */
|
|
40
|
+
export declare function armResourceIdOf(ctx: Pick<ArmEvalCtx, "subscriptionId" | "resourceGroup">, type: string, name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Record an applied resource's response so `reference()` resolves it by name
|
|
43
|
+
* and by resource id (#4243). Ids are case-insensitive in ARM, so they are
|
|
44
|
+
* stored lowercased, under both the id chant derives and the one the
|
|
45
|
+
* response reports.
|
|
46
|
+
*/
|
|
47
|
+
export declare function rememberDeployed(ctx: ArmEvalCtx, type: string, name: string, body: unknown): void;
|
|
48
|
+
/** An applied resource by the name or the resource id a `reference()` names. */
|
|
49
|
+
export declare function lookupDeployed(ctx: ArmEvalCtx, ref: string): unknown;
|
|
34
50
|
/** Evaluate an ARM expression string (`"[...]"`); a plain string is returned as-is. */
|
|
35
51
|
export declare function evalArmString(s: string, ctx: ArmEvalCtx): Promise<unknown>;
|
|
36
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Recursively evaluate every string in a value against the ARM context,
|
|
54
|
+
* object keys included: ARM evaluates a property name too, and
|
|
55
|
+
* `identity.userAssignedIdentities` is keyed by `[resourceId(...)]` (#4231).
|
|
56
|
+
*/
|
|
37
57
|
export declare function evalArm(value: unknown, ctx: ArmEvalCtx): Promise<unknown>;
|
|
38
58
|
/** Resource names this resource references via `resourceId('type','name')` / `reference('name')`. Pure. */
|
|
39
59
|
export declare function armDependencies(resource: ArmResource, names: Set<string>): string[];
|
|
@@ -45,7 +65,7 @@ export declare function armDependencies(resource: ArmResource, names: Set<string
|
|
|
45
65
|
export declare function orderArmResources(resources: ArmResource[]): ArmResource[];
|
|
46
66
|
/** The ARM resource-ID PUT URL for a resource (name expression evaluated). */
|
|
47
67
|
export declare function armResourceUrl(resource: ArmResource, ctx: ArmEvalCtx): Promise<string>;
|
|
48
|
-
/** The ARM resource PUT body
|
|
68
|
+
/** The ARM resource PUT body: `location` and {@link ARM_BODY_FIELDS}, expressions evaluated. */
|
|
49
69
|
export declare function armResourceBody(resource: ArmResource, ctx: ArmEvalCtx): Promise<Record<string, unknown>>;
|
|
50
70
|
export interface AzApplyArgs {
|
|
51
71
|
/** Path to a built ARM template (`deploymentTemplate.json`). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"az-apply.d.ts","sourceRoot":"","sources":["../../../src/op/activities/az-apply.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"az-apply.d.ts","sourceRoot":"","sources":["../../../src/op/activities/az-apply.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,WAAW,EAGjB,MAAM,wBAAwB,CAAC;AAMhC,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,mFAAmF;AACnF,MAAM,MAAM,MAAM,GAAG,CACnB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,WAAW,KACjB,OAAO,CAAC;IAAE,MAAM,EAAE,MAA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|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { armResourcePath } from "../../arm-type.js";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
3
4
|
import { hasOwnershipMarker, OWNERSHIP_MANAGED_BY_VALUE } from "@intentius/chant/ownership";
|
|
4
5
|
import { AZURE_TAG_OWNERSHIP_KEYS } from "../../ownership.js";
|
|
@@ -17,6 +18,27 @@ const defaultHttp = async (method, url, body, signal) => {
|
|
|
17
18
|
});
|
|
18
19
|
return { status: res.status, text: await res.text() };
|
|
19
20
|
};
|
|
21
|
+
/** The ARM resource id of a resource in the context's group. */
|
|
22
|
+
export function armResourceIdOf(ctx, type, name) {
|
|
23
|
+
return `/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${armResourcePath(type, name)}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Record an applied resource's response so `reference()` resolves it by name
|
|
27
|
+
* and by resource id (#4243). Ids are case-insensitive in ARM, so they are
|
|
28
|
+
* stored lowercased, under both the id chant derives and the one the
|
|
29
|
+
* response reports.
|
|
30
|
+
*/
|
|
31
|
+
export function rememberDeployed(ctx, type, name, body) {
|
|
32
|
+
ctx.deployed.set(name, body);
|
|
33
|
+
ctx.deployed.set(armResourceIdOf(ctx, type, name).toLowerCase(), body);
|
|
34
|
+
const id = body?.id;
|
|
35
|
+
if (typeof id === "string")
|
|
36
|
+
ctx.deployed.set(id.toLowerCase(), body);
|
|
37
|
+
}
|
|
38
|
+
/** An applied resource by the name or the resource id a `reference()` names. */
|
|
39
|
+
export function lookupDeployed(ctx, ref) {
|
|
40
|
+
return ctx.deployed.get(ref) ?? (ref.startsWith("/") ? ctx.deployed.get(ref.toLowerCase()) : undefined);
|
|
41
|
+
}
|
|
20
42
|
/** Evaluate an ARM expression string (`"[...]"`); a plain string is returned as-is. */
|
|
21
43
|
export async function evalArmString(s, ctx) {
|
|
22
44
|
if (!(s.startsWith("[") && s.endsWith("]")))
|
|
@@ -25,7 +47,11 @@ export async function evalArmString(s, ctx) {
|
|
|
25
47
|
return s.slice(1); // escaped literal "["
|
|
26
48
|
return new ArmExpr(s.slice(1, -1), ctx).parse();
|
|
27
49
|
}
|
|
28
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Recursively evaluate every string in a value against the ARM context,
|
|
52
|
+
* object keys included: ARM evaluates a property name too, and
|
|
53
|
+
* `identity.userAssignedIdentities` is keyed by `[resourceId(...)]` (#4231).
|
|
54
|
+
*/
|
|
29
55
|
export async function evalArm(value, ctx) {
|
|
30
56
|
if (typeof value === "string")
|
|
31
57
|
return evalArmString(value, ctx);
|
|
@@ -34,7 +60,7 @@ export async function evalArm(value, ctx) {
|
|
|
34
60
|
if (value && typeof value === "object") {
|
|
35
61
|
const out = {};
|
|
36
62
|
for (const [k, v] of Object.entries(value))
|
|
37
|
-
out[k] = await evalArm(v, ctx);
|
|
63
|
+
out[String(await evalArmString(k, ctx))] = await evalArm(v, ctx);
|
|
38
64
|
return out;
|
|
39
65
|
}
|
|
40
66
|
return value;
|
|
@@ -108,10 +134,14 @@ class ArmExpr {
|
|
|
108
134
|
return { subscriptionId: this.ctx.subscriptionId, id: `/subscriptions/${this.ctx.subscriptionId}` };
|
|
109
135
|
case "resourceId":
|
|
110
136
|
// resourceId('Microsoft.X/y', 'name'[, 'child']) → the resource-id path.
|
|
111
|
-
return
|
|
137
|
+
return armResourceIdOf(this.ctx, String(args[0]), args.slice(1).map(String).join("/"));
|
|
112
138
|
case "reference": {
|
|
113
|
-
// reference('name'
|
|
114
|
-
|
|
139
|
+
// reference('name' | resourceId(...)[, apiVersion[, 'Full']]) → the
|
|
140
|
+
// runtime `properties` of an already-applied resource, or its whole
|
|
141
|
+
// body with 'Full' (#4243).
|
|
142
|
+
const dep = lookupDeployed(this.ctx, String(args[0]));
|
|
143
|
+
if (String(args[2] ?? "").toLowerCase() === "full")
|
|
144
|
+
return dep;
|
|
115
145
|
return dep?.properties ?? dep;
|
|
116
146
|
}
|
|
117
147
|
case "listKeys": {
|
|
@@ -224,21 +254,23 @@ export function orderArmResources(resources) {
|
|
|
224
254
|
/** The ARM resource-ID PUT URL for a resource (name expression evaluated). */
|
|
225
255
|
export async function armResourceUrl(resource, ctx) {
|
|
226
256
|
const name = await evalArmString(resource.name, ctx);
|
|
227
|
-
return `${ctx.base}/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${resource.type
|
|
257
|
+
return `${ctx.base}/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${armResourcePath(resource.type, String(name))}?api-version=${resource.apiVersion}`;
|
|
228
258
|
}
|
|
229
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* The top-level ARM resource fields a PUT takes beside `location` (#4231). A
|
|
261
|
+
* field missing here is dropped from the body, which is how a declared
|
|
262
|
+
* `identity` came back absent.
|
|
263
|
+
*/
|
|
264
|
+
const ARM_BODY_FIELDS = ["properties", "sku", "kind", "tags", "identity", "zones", "plan", "extendedLocation", "managedBy"];
|
|
265
|
+
/** The ARM resource PUT body: `location` and {@link ARM_BODY_FIELDS}, expressions evaluated. */
|
|
230
266
|
export async function armResourceBody(resource, ctx) {
|
|
231
267
|
const body = {};
|
|
232
268
|
if (resource.location)
|
|
233
269
|
body.location = await evalArmString(resource.location, ctx);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (resource.kind !== undefined)
|
|
239
|
-
body.kind = await evalArm(resource.kind, ctx);
|
|
240
|
-
if (resource.tags !== undefined)
|
|
241
|
-
body.tags = await evalArm(resource.tags, ctx);
|
|
270
|
+
for (const field of ARM_BODY_FIELDS) {
|
|
271
|
+
if (resource[field] !== undefined)
|
|
272
|
+
body[field] = await evalArm(resource[field], ctx);
|
|
273
|
+
}
|
|
242
274
|
return body;
|
|
243
275
|
}
|
|
244
276
|
/**
|
|
@@ -277,7 +309,7 @@ export async function azApply(args, signal, http = defaultHttp) {
|
|
|
277
309
|
}
|
|
278
310
|
// Capture the applied resource so later reference()/dependents resolve.
|
|
279
311
|
try {
|
|
280
|
-
ctx.
|
|
312
|
+
rememberDeployed(ctx, resource.type, name, JSON.parse(res.text));
|
|
281
313
|
}
|
|
282
314
|
catch {
|
|
283
315
|
// non-JSON response — reference() to this resource resolves to undefined
|
|
@@ -366,7 +398,7 @@ export async function listGroupResources(ctx, http = defaultHttp, signal) {
|
|
|
366
398
|
}
|
|
367
399
|
/** Idempotently delete one ARM resource by type/name/apiVersion. A 404 means it is already gone. */
|
|
368
400
|
export async function deleteArmResource(type, name, apiVersion, ctx, http = defaultHttp, signal) {
|
|
369
|
-
const url = `${ctx.base}/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${type
|
|
401
|
+
const url = `${ctx.base}/subscriptions/${ctx.subscriptionId}/resourceGroups/${ctx.resourceGroup}/providers/${armResourcePath(type, name)}?api-version=${apiVersion}`;
|
|
370
402
|
const res = await http("DELETE", url, undefined, signal);
|
|
371
403
|
if (res.status === 404)
|
|
372
404
|
return { type, name, deleted: false };
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AA2B5E;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,aA8dzB,CAAC"}
|
package/dist/plugin.js
CHANGED
|
@@ -9,6 +9,7 @@ import { join, dirname } from "path";
|
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { moduleSourceDir } from "@intentius/chant/module-source";
|
|
11
11
|
import { azureSerializer } from "./serializer.js";
|
|
12
|
+
import { azureGraphEdges } from "./graph-edges.js";
|
|
12
13
|
import { hardcodedLocationRule } from "./lint/rules/hardcoded-location.js";
|
|
13
14
|
import { storageHttpsRule } from "./lint/rules/storage-https.js";
|
|
14
15
|
import { nsgWildcardRule } from "./lint/rules/nsg-wildcard.js";
|
|
@@ -30,6 +31,8 @@ export const azurePlugin = {
|
|
|
30
31
|
emulator: FLOCI_AZ_EMULATOR,
|
|
31
32
|
auditCatalog: () => azureAuditCatalog,
|
|
32
33
|
serializer: azureSerializer,
|
|
34
|
+
// References written as ARM expressions (resourceId, reference, listKeys) as graph edges (#4232).
|
|
35
|
+
graphEdges: (entities) => azureGraphEdges(entities),
|
|
33
36
|
lintRules() {
|
|
34
37
|
return [hardcodedLocationRule, storageHttpsRule, nsgWildcardRule];
|
|
35
38
|
},
|
package/dist/rules/arm-refs.ts
CHANGED
|
@@ -56,6 +56,8 @@ export function parseArmTemplate(output: string | { primary: string }): ArmTempl
|
|
|
56
56
|
* - [reference('myStorage')]
|
|
57
57
|
* - [reference('myStorage').primaryEndpoints.blob]
|
|
58
58
|
*
|
|
59
|
+
* Object keys are read as well as values.
|
|
60
|
+
*
|
|
59
61
|
* Returns the set of resource names found in these references.
|
|
60
62
|
*/
|
|
61
63
|
export function findArmResourceRefs(value: unknown): Set<string> {
|
|
@@ -121,7 +123,10 @@ function walkArmValue(value: unknown, refs: Set<string>): void {
|
|
|
121
123
|
|
|
122
124
|
if (typeof value === "object") {
|
|
123
125
|
const obj = value as Record<string, unknown>;
|
|
124
|
-
for (const val of Object.
|
|
126
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
127
|
+
// A key can be an expression too: a user-assigned identity is named by
|
|
128
|
+
// its resource ID as the key of identity.userAssignedIdentities.
|
|
129
|
+
walkArmValue(key, refs);
|
|
125
130
|
walkArmValue(val, refs);
|
|
126
131
|
}
|
|
127
132
|
}
|
package/dist/serializer.d.ts
CHANGED
|
@@ -31,6 +31,15 @@ export declare function getApiVersion(resourceType: string): string;
|
|
|
31
31
|
* reads `reference()` by the ARM name.
|
|
32
32
|
*/
|
|
33
33
|
export declare function armAttrExpression(entityNames: Map<Declarable, string>, name: string, attr: string): string;
|
|
34
|
+
/** A prop value as the template writes it: references become bracket expressions. */
|
|
35
|
+
export declare function toArmValue(value: unknown, entityNames: Map<Declarable, string>): unknown;
|
|
36
|
+
/**
|
|
37
|
+
* The name a resource takes in the template: its `name` prop, or the entity
|
|
38
|
+
* key when it sets none. `findArmResourceRefs` reports references by this
|
|
39
|
+
* name, so the dependsOn inference below and the graph edges
|
|
40
|
+
* (./graph-edges.ts) both resolve a reference through it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function armResourceName(entity: Declarable, key: string, entityNames: Map<Declarable, string>): unknown;
|
|
34
43
|
/**
|
|
35
44
|
* Azure ARM template serializer implementation.
|
|
36
45
|
*/
|
package/dist/serializer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,6BAA6B,CAAC;AAE7E,OAAO,KAAK,EAAE,UAAU,EAAsC,MAAM,6BAA6B,CAAC;AA8ElG,wBAAgB,4BAA4B,CAAC,GAAG,GAAE,MAAqB,GAAG,MAAM,EAAE,CAKjF;AAED,wBAAgB,eAAe,CAAC,UAAU,GAAE,MAAM,EAAmC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAwB1G;AAcD,yEAAyE;AACzE,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAWzE;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAO1D;AA6BD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK1G;AAoDD,qFAAqF;AACrF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,OAAO,CAExF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,OAAO,CAK9G;AA2SD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,UA+C7B,CAAC"}
|