-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance token management and add Disconnect-AzResourceGraph function #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves token management and adds a new cmdlet to disconnect from Azure Resource Graph by clearing cached tokens.
- Introduces
Disconnect-AzResourceGraphto reset in-memory session state. - Enhances
Connect-AzResourceGraphwith aManagementEndpointparameter, token cache configuration, and user identity handling. - Refactors token expiry/scope checks in
Test-AzureTokenand tweaks the interactive path inAssert-AzureConnection.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Public/Disconnect-AzResourceGraph.tests.ps1 | Adds tests validating that Disconnect-AzResourceGraph clears session state. |
| CHANGELOG.md | Updates version history; adds a fixed section and reorganizes releases. |
| AzResourceGraph/Public/Disconnect-AzResourceGraph.ps1 | Implements new Disconnect-AzResourceGraph cmdlet. |
| AzResourceGraph/Public/Connect-AzResourceGraph.ps1 | Adds ManagementEndpoint parameter and enriches token splatting logic. |
| AzResourceGraph/Private/Test-AzureToken.ps1 | Switches to UTC comparisons and includes scope fallback in token checks. |
| AzResourceGraph/Private/Assert-AzureConnection.ps1 | Removes extra parameters on interactive reauthorization. |
Comments suppressed due to low confidence (6)
AzResourceGraph/Public/Connect-AzResourceGraph.ps1:96
- The new
ManagementEndpointparameter lacks a type annotation (e.g.[string]) and no Parameter attribute for Mandatory or Position. Consider declaring a[string]type and adding appropriate[Parameter(...)]attributes for each ParameterSet to enforce valid input.
$ManagementEndpoint = 'https://management.azure.com'
AzResourceGraph/Public/Connect-AzResourceGraph.ps1:36
- [nitpick] Consider adding a
ValidateSetattribute to theManagementEndpointparameter to restrict values to known Azure cloud endpoints (e.g., global, China, USGov). This prevents typos and improves discoverability.
Endpoint used for management. This is used for the Audience claim when authenticating to Azure.
AzResourceGraph/Public/Disconnect-AzResourceGraph.ps1:2
- [nitpick] The synopsis mentions clearing the cached access token in memory but omits that
TokenSourceis reset to 'Global'. Consider updating the help text to list all module-scoped variables that this cmdlet resets.
.SYNOPSIS
tests/Unit/Public/Disconnect-AzResourceGraph.tests.ps1:23
- Add an assertion to verify that
$script:TokenSourceis reset (e.g., to 'Global') after callingDisconnect-AzResourceGraphto ensure full state clearance.
$script:TokenSplat.Keys.Count | Should -be 0
CHANGELOG.md:11
- The changelog entry for 0.1.1 omits the new
Disconnect-AzResourceGraphaddition under 'Added' and reuses the same date as 0.1.0. Please include the new function in the 'Added' section and correct the release date sequencing.
## [0.1.1] - 2025-05-14
AzResourceGraph/Private/Assert-AzureConnection.ps1:68
- Removing
ClientIdwhenInteractiveis present may drop needed identity info for token renewals. Verify whether this removal is intentional or if a different key (e.g.,UserName) should be pruned instead.
$LocalTokenSplat.Remove('ClientId')
Improve token handling by refining parameter management and adding a new function to disconnect from Azure Resource Graph, clearing cached tokens.