Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/StackHCI/StackHCI.Autorest/custom/stackhci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ $AuthorityAzureLocal = "https://login.$DOMAINFQDNMACRO"
$BillingServiceApiScopeAzureLocal = "https://dp.aszrp.$DOMAINFQDNMACRO/.default"
$GraphServiceApiScopeAzureLocal = "https://graph.$DOMAINFQDNMACRO"

$DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default"
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GUID 1322e676-dee7-41ee-a874-ac923822781c is the Azure Stack HCI Usage Service first-party app ID (defined on line 148 as $UsageServiceFirstPartyAppId). Consider using the existing variable for consistency: $DefaultBillingServiceApiScope = \"$UsageServiceFirstPartyAppId/.default\" or add a comment explaining this is intentionally duplicated.

Suggested change
$DefaultBillingServiceApiScope = "1322e676-dee7-41ee-a874-ac923822781c/.default"
$DefaultBillingServiceApiScope = "$UsageServiceFirstPartyAppId/.default"

Copilot uses AI. Check for mistakes.

$RPAPIVersion = "2025-09-15-preview";
$HCIArcAPIVersion = "2025-09-15-preview"
$HCIArcExtensionAPIVersion = "2025-09-15-preview"
Expand Down Expand Up @@ -719,6 +721,10 @@ $registerArcScript = {
{
$managementUrl = 'https://management.usgovcloudapi.net'
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
Comment on lines +724 to +726
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error if ResourceManagerUrl property is null. The code checks if the environment exists with $null -ne (Get-AzEnvironment -Name $EnvironmentName) but doesn't validate that the returned object has a non-null ResourceManagerUrl property. Consider adding a null check: $env = Get-AzEnvironment -Name $EnvironmentName; if ($null -ne $env -and $null -ne $env.ResourceManagerUrl) { ... }

Suggested change
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
elseif ($null -ne ($environment = Get-AzEnvironment -Name $EnvironmentName) -and $null -ne $environment.ResourceManagerUrl)
{
$managementUrl = $environment.ResourceManagerUrl

Copilot uses AI. Check for mistakes.
}
else
{
throw 'Invalid Azure Environment name'
Expand Down Expand Up @@ -1018,6 +1024,10 @@ function Get-ManagementUrl {
{
$managementUrl = 'https://management.usgovcloudapi.net'
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
}
else
{
throw "Invalid Azure Environment name"
Comment on lines +1027 to 1033
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error if ResourceManagerUrl property is null. Same issue as in the registerArcScript - the environment object's properties may be null even when the environment exists. Add proper null validation before accessing the property.

Suggested change
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
$managementUrl = (Get-AzEnvironment -Name $EnvironmentName).ResourceManagerUrl
}
else
{
throw "Invalid Azure Environment name"
else
{
$environment = Get-AzEnvironment -Name $EnvironmentName
if ($null -ne $environment -and $null -ne $environment.ResourceManagerUrl)
{
$managementUrl = $environment.ResourceManagerUrl
}
else
{
throw "Invalid Azure Environment name"
}

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -1208,6 +1218,10 @@ param(
{
return $AzureLocalPortalDomain;
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
return (Get-AzEnvironment -Name $EnvironmentName).ManagementPortalUrl
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error if ManagementPortalUrl property is null. Custom Azure Environments may not have this property configured. Consider adding validation and a meaningful error message or default value.

Copilot uses AI. Check for mistakes.
}
}

function Get-DefaultRegion{
Expand Down Expand Up @@ -1320,6 +1334,13 @@ param(
$BillingServiceApiScope.Value = $BillingServiceApiScopeAzureLocal
$GraphServiceApiScope.Value = $GraphServiceApiScopeAzureLocal
}
elseif ($null -ne (Get-AzEnvironment -Name $EnvironmentName))
{
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded value 'https://doesnotmatter/' is unclear and potentially confusing. Add a comment explaining why this placeholder URL is used and whether it's actually utilized in the custom environment scenario.

Suggested change
{
{
# Use a dummy URL for custom Az environments. The Stack HCI service endpoint is not
# resolved from this value in this code path; only the authority and scopes taken
# from Get-AzEnvironment are used for authentication, so the exact URL does not matter.

Copilot uses AI. Check for mistakes.
$ServiceEndpoint.Value = "https://doesnotmatter/"
$Authority.Value = (Get-AzEnvironment -Name $EnvironmentName).ActiveDirectoryAuthority
$BillingServiceApiScope.Value = $DefaultBillingServiceApiScope
$GraphServiceApiScope.Value = (Get-AzEnvironment -Name $EnvironmentName).GraphEndpointResourceId + "/.default"
Comment on lines +1339 to +1342
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference errors if ActiveDirectoryAuthority or GraphEndpointResourceId properties are null. Custom environments may not have these properties configured. Add null checks and provide meaningful error messages if critical properties are missing.

Suggested change
$ServiceEndpoint.Value = "https://doesnotmatter/"
$Authority.Value = (Get-AzEnvironment -Name $EnvironmentName).ActiveDirectoryAuthority
$BillingServiceApiScope.Value = $DefaultBillingServiceApiScope
$GraphServiceApiScope.Value = (Get-AzEnvironment -Name $EnvironmentName).GraphEndpointResourceId + "/.default"
$environment = Get-AzEnvironment -Name $EnvironmentName
if (-not $environment.ActiveDirectoryAuthority)
{
throw "The ActiveDirectoryAuthority endpoint is not configured for Azure environment '$EnvironmentName'. Configure this property for the environment and try again."
}
if (-not $environment.GraphEndpointResourceId)
{
throw "The GraphEndpointResourceId endpoint is not configured for Azure environment '$EnvironmentName'. Configure this property for the environment and try again."
}
$ServiceEndpoint.Value = "https://doesnotmatter/"
$Authority.Value = $environment.ActiveDirectoryAuthority
$BillingServiceApiScope.Value = $DefaultBillingServiceApiScope
$GraphServiceApiScope.Value = $environment.GraphEndpointResourceId + "/.default"

Copilot uses AI. Check for mistakes.
}
}


Expand Down
1 change: 1 addition & 0 deletions src/StackHCI/StackHCI/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Upcoming Release
* Improved cloud deployment detection during Azure Arc repair operations to prevent duplicate enablement attempts and ensure smoother deployment experiences.
* Added ability to register in custom Azure Environments
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog entry should reference the cmdlet affected and explain the impact to users more clearly. According to ChangeLog guidelines (CodingGuidelineID: 1000002), entries should be written from the user's perspective. Consider: 'Added support for registering Stack HCI clusters in custom Azure Environments configured via Add-AzEnvironment'

Copilot generated this review using guidance from repository custom instructions.

## Version 2.6.5
* ARC Enablement of Nodes Before Triggering Registration in New Registration Flow.
Expand Down
Loading