Support Metadata.json body for PIM activation request#5
Support Metadata.json body for PIM activation request#5akhilsmokie3-ops wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55fb519f43
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| if (Test-Path -Path $metadataPath) { | ||
| Write-Host " Found Metadata.json. Using JSON body for request." -ForegroundColor DarkGray | ||
| $params = Get-Content -Raw -Path $metadataPath | ConvertFrom-Json -AsHashtable |
There was a problem hiding this comment.
Preserve PowerShell 5.1 compatibility when parsing Metadata.json
The new ConvertFrom-Json -AsHashtable call is only available in PowerShell Core (6+), but this script still declares support for "PowerShell 5.1+"; on Windows PowerShell 5.1, activating via Metadata.json will fail at parameter binding before the Graph request is sent. This creates a runtime regression specifically for 5.1 users whenever Metadata.json is present, so the JSON parsing path should avoid -AsHashtable (or gate it by PS version) to keep the documented compatibility.
Useful? React with 👍 / 👎.
Motivation
Metadata.jsonpayload structure that the script can consume.Description
entra-pim-self-activate.ps1to check the current working directory forMetadata.jsonand, when present, load it usingGet-Content -Raw | ConvertFrom-Json -AsHashtableand use it as the-BodyParameterforNew-MgRoleManagementDirectoryRoleAssignmentScheduleRequest.Metadata.jsonis not found so existing usage remains unchanged.Metadata.jsonfile that demonstrates the expected request payload fields (action,principalId,roleDefinitionId,directoryScopeId,scheduleInfo, andticketInfo).Testing
Metadata.jsonis valid JSON usingpython -m json.tool Metadata.json, which returned success.Metadata.jsondetection and parsing logic by searching code patterns withrgand inspecting the modified region withnl/sed, both showing the new conditional branch.paramsvariable which is then passed toNew-MgRoleManagementDirectoryRoleAssignmentScheduleRequest -BodyParameter, by reviewing the runtime insertion point in the script.Codex Task