Skip to content

[Change Safety] Generator: emit static -AcquirePolicyToken/-ChangeReference on write cmdlets (Stage D)#1549

Draft
YangAn-microsoft wants to merge 4 commits into
Azure:mainfrom
YangAn-microsoft:feature/change-safety-generator-static
Draft

[Change Safety] Generator: emit static -AcquirePolicyToken/-ChangeReference on write cmdlets (Stage D)#1549
YangAn-microsoft wants to merge 4 commits into
Azure:mainfrom
YangAn-microsoft:feature/change-safety-generator-static

Conversation

@YangAn-microsoft

@YangAn-microsoft YangAn-microsoft commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Emits the Change Safety opt-in parameters -AcquirePolicyToken (SwitchParameter) and -ChangeReference (string) as static [Parameter] properties on generated Azure management-plane write-verb cmdlets, for modules that opt in via a change-safety config flag. Their values flow through the cmdlet's BoundParameters to the module-level pipeline step in Az.Accounts (Azure/azure-powershell#29840), which calls acquirePolicyToken and stamps the x-ms-policy-external-evaluations header.

Replaces #1548. That PR surfaced the parameters via a runtime-wired VTable GetDynamicParameters delegate + generated IDynamicParameters. Per review feedback the approach moved to codegen-owned static parameters — simpler, self-contained in the generated cmdlet, and with no cross-repo runtime coupling. Design write-up: Azure/CLIPS#408.

What it does

  • New implementChangeSafetyParameters() in cmdlets/class.ts, invoked from init().
  • Opt-in flag: a change-safety config value (default false), read into Project.changeSafety in internal/project.ts. Nothing is emitted unless a module sets change-safety: true in its readme. This keeps the ~180-module rollout deliberate (a module opts in alongside bumping its Az.Accounts minimum) rather than triggered by any unrelated regeneration.
  • Gates (all must hold to emit): change-safety: truestate.project.azurenot data-plane (endpointResourceIdKeyName, matching module-class.ts's isDataPlane) → HTTP verb ∈ {PUT, POST, DELETE, PATCH}.
  • Parameter names + help text are reused verbatim from azure-powershell-common's ChangeSafetyParameters, so SDK and AutoRest cmdlets present identically to users.
  • No IDynamicParameters, no Module.cs/.psm1 wiring, no module-class.ts / powershell-declarations.ts changes.

Scope

Two files: powershell/cmdlets/class.ts and powershell/internal/project.ts. With the flag off (the default), every module is a zero diff. With the flag on, read cmdlets (Get/List/Show/Test), data-plane cmdlets, and non-azure projects still get a zero diff.

Verification

  • npm run build + npm run eslint: clean.
  • Smoke-gen of an azure management-plane spec (get/delete/put/patch): flag off → 0 params emitted; flag on → all 4 write cmdlets get both parameters (category Azure, ChangeReference with ValidateNotNull), the read (Get) cmdlet gets none.
  • tests-sdk1-support (-AllowList -SkipCsharp): 52 × Equal — unaffected. That suite compares the shared SDK/model layer; cmdlets are PowerShell-only and out of scope.

Dependencies / release order

… to VTable dynamic-parameter delegate)

Emit -AcquirePolicyToken (switch) and -ChangeReference (string) as static [Parameter] properties on azure write-verb cmdlets, categorized Azure. No IDynamicParameters, no Module.cs/VTable delegate wiring; the module-level HTTP pipeline step reads the values from BoundParameters by name.
…eters

Gate implementChangeSafetyParameters on !endpointResourceIdKeyName (the generator's canonical data-plane signal, matching isDataPlane in module-class.ts), so only management-plane (ARM) write-verb cmdlets get -AcquirePolicyToken/-ChangeReference.
…meters)

Use the exact parameter names and help messages defined in azure-powershell-common ChangeSafetyParameters so AutoRest and SDK cmdlets present identically to users.
…flag

Add a change-safety project flag (default false) read from the module readme. implementChangeSafetyParameters only emits -AcquirePolicyToken/-ChangeReference when it is true, so the ~180-module rollout is deliberate (a module opts in alongside bumping its Az.Accounts minimum) rather than triggered by any unrelated regeneration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant