Repository navigation
fix(azure_policy): follow-ups to sub-resource array rewrapping - #989
Open
snehabandla wants to merge 1 commit into
Open
snehabandla wants to merge 1 commit into
snehabandla wants to merge 1 commit into
Conversation
Address review comments left open when microsoft#958 merged: - Record a plain alias's write only when it succeeds, so a write refused by an array on the way does not hide the arrays there from rewrapping. - Track rewrap targets and writes by the keys as written. Plain aliases whose ARM keys differ only in case write different arrays, and both are rewrapped. Lookups try the exact key first. - Keep a wrapped field's ARM name inside `properties` even when an unwrapped field's short name is the same. - When an array rename supplies a plain alias's value (its ARM key has different casing), read the alias's own ARM value instead of the renamed one, so each wrapper is flattened once, arrays that are sub-resource arrays only under the source name keep their wrappers, and the source name's remaps do not leak into the alias. Then apply the remaps rooted at the alias. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved alias-handling defects can drop ARM-named keys, select stale ancestor writes or case-distinct siblings, and incorrectly rename or wrap output fields.
4 open issues
What changed in this PR
Refines Azure Policy normalization and denormalization after #958, focusing on sub-resource array wrappers and plain-alias handling.
Changes:
- Records only successful alias writes and preserves case-distinct destinations.
- Adjusts envelope classification and mixed-case alias fallback resolution.
- Adds regression cases and documents the fixes.
| File | Description |
|---|---|
tests/azure_policy/normalization/cases/normalize_sub_resources.yaml |
Adds wrapper, casing, and alias-remapping regression cases. |
tests/azure_policy/normalization/cases/data_plane_sub_resources.yaml |
Covers refused alias writes at the resource root. |
src/languages/azure_policy/aliases/obj_map.rs |
Returns success status from nested setters. |
src/languages/azure_policy/aliases/normalizer/alias_resolution.rs |
Resolves fallback aliases from raw values and applies alias-specific remaps. |
src/languages/azure_policy/aliases/denormalizer/sub_resource.rs |
Updates write tracking, destination lookup, and envelope classification. |
src/languages/azure_policy/aliases/denormalizer/mod.rs |
Records alias writes only when they succeed. |
CHANGELOG.md |
Documents the Azure Policy fixes. |
Review effort: Max
Comment on lines
+76
to
+77
| let (_, written, source) = last_write(|dest, key| dest == key) | ||
| .or_else(|| last_write(|dest, key| dest.eq_ignore_ascii_case(key)))?; |
Comment on lines
+186
to
+188
| Some(Value::Object(obj)) => find_key_ci_btree(obj, key).and_then(|k| { | ||
| let name = String::from(val_str(&k)?); | ||
| Some((name, obj.get(&k)?)) |
Comment on lines
+330
to
+331
| envelope.retain(|field| { | ||
| !wrapped.contains(field) || ELEMENT_ENVELOPE_FIELDS.contains(&field.as_str()) |
| continue; | ||
| }; | ||
| obj_insert(result, target_lc, val); | ||
| obj_insert(result, target_lc, resolved); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Follow-ups to #958 (sub-resource array names include unwrapped outer arrays), which merged with five review comments open. Four of them describe regressions #958 introduced; the fifth is older. All five were reproduced, and two more bugs found while fixing them are fixed here too.
Changes
A refused write is not recorded. A plain alias whose destination runs through an array or scalar (for example
b→properties.x.ywhilexis an array) cannot be written. It used to be recorded as the value written there, so the sub-resource arrays underx.ywere not re-wrapped.set_nested_verbatim(and the setters it uses) now return whether the write succeeded, and the denormalizer records the alias only then, underpropertiesand at the resource root.Destinations that differ only in case stay separate. With
a→properties.Itemsandb→properties.items, both arrays are written, but rewrap targets and the write log keyed them case-insensitively, so one array was left without itspropertieswrappers. Targets and writes now use the keys as written. Lookups try the exact key first and fall back to a case-insensitive match.Wrapped ARM names stay inside
properties. An unwrapped field's short name (for examplerules[*].rawstatus) could add a name to the element envelope that a wrapped alias also uses (rules[*].other→…properties.rawstatus).{properties: {rawstatus: 1}}then came back as{rawstatus: 1}. Wrapped ARM names are now removed from the whole envelope set. The standard fields (name,type,id,etag) stay at the element root.The plain-alias fallback reads the alias's own value. When the input key's casing differs from the plain alias's ARM path (
Itemsfora→properties.items), the alias step misses it and the array rename supplies the value. That value had been flattened and remapped for the ARM name, not the alias, so:propertiesout;x[*].y[*].zstayedrawz; this one is older than fix(azure-policy): sub-resource array names include unwrapped outer arrays #958).The fallback now reads the alias's ARM path from the input (exact key first, then a case-insensitive match), normalizes it the same way the alias step does, and applies the remaps rooted at the alias. The output matches input whose key casing matches the ARM path.
Testing
New cases in
normalize_sub_resources.yaml. Each fails before this change and passes after:Items/itemsdestinations, both top-level and nested, plus a non-array write to the other-cased key;Items/itemsround trip;rawstatusenvelope (round trip and normalized output);New case in
data_plane_sub_resources.yaml: a refused write at the resource root.Unchanged-behaviour check: a wrapped
namefield stays at the element root.The two existing mixed-case cases now also check
expected_normalized.Results:
cargo test --features azure_policy --test mod: 384 passed.--lib azure_policy: 291 passed.scripts/pre-commit: passes.Not in this PR
x[*].z→properties.items[*].rawz, with no plain aliasx) still keeps the ARM leaf name. This is older than fix(azure-policy): sub-resource array names include unwrapped outer arrays #958; follow-up.x[*].state→rawStatetogether withx[*].foo→properties.stateloses a value. This is also older; follow-up.