Skip to content
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

Handling null valued quotaId #256

Merged
merged 3 commits into from
Sep 19, 2024
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ The [Azure Governance Visualizer accelerator](https://github.com/Azure/Azure-Gov

## Release history

**Changes** (2024-August-28 / 6.5.2 Patch)
**Changes** (2024-September-17 / 6.5.3 Patch)

- AAD -> EntraId
- fix stop error for subscriptions with null valued quotaId. the function detailSubscription uses `.startsWith()` method to check for `AAD_` but cannot validate when a null-valued `.quotaId` occurs.

[Full release history](history.md)

Expand Down
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Azure Governance Visualizer version 6

**Changes** (2024-September-17 / 6.5.3 Patch)

- fix stop error for subscriptions with null valued quotaId. the function detailSubscription uses `.startsWith()` method to check for `AAD_` but cannot validate when a null-valued `.quotaId` occurs.

**Changes** (2024-August-28 / 6.5.2 Patch)

- AAD -> EntraId
Expand Down
96 changes: 54 additions & 42 deletions pwsh/AzGovVizParallel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
$Product = 'AzGovViz',

[string]
$ProductVersion = '6.5.2',
$ProductVersion = '6.5.3',

[string]
$GithubRepository = 'aka.ms/AzGovViz',
Expand Down Expand Up @@ -2435,63 +2435,75 @@
foreach ($childrenSubscription in $childrenSubscriptions) {

$sub = $htAllSubscriptionsFromAPI.($childrenSubscription.name)
if ($sub.subDetails.subscriptionPolicies.quotaId.startswith('AAD_', 'CurrentCultureIgnoreCase') -or $sub.subDetails.state -ne 'Enabled') {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith('AAD_', 'CurrentCultureIgnoreCase')) {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: AAD_ (State: $($sub.subDetails.state))"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.state -ne 'Enabled') {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "State: $($sub.subDetails.state)"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.subscriptionPolicies.quotaId -eq $null) {

Check warning

Code scanning / PSScriptAnalyzer

$null should be on the left side of equality comparisons. Warning

$null should be on the left side of equality comparisons.
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = 'QuotaId: null'
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
else {
if ($SubscriptionQuotaIdWhitelist[0] -ne 'undefined') {
$whitelistMatched = 'unknown'
foreach ($subscriptionQuotaIdWhitelistQuotaId in $SubscriptionQuotaIdWhitelist) {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith($subscriptionQuotaIdWhitelistQuotaId, 'CurrentCultureIgnoreCase')) {
$whitelistMatched = 'inWhitelist'
}
}

if ($whitelistMatched -eq 'inWhitelist') {
#write-host "$($childrenSubscription.properties.displayName) in whitelist"
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
if ($sub.subDetails.subscriptionPolicies.quotaId.startswith('AAD_', 'CurrentCultureIgnoreCase') -or $sub.subDetails.state -ne 'Enabled') {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith('AAD_', 'CurrentCultureIgnoreCase')) {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
outOfScopeReason = "QuotaId: AAD_ (State: $($sub.subDetails.state))"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
else {
#Write-Host " preCustomDataCollection: $($childrenSubscription.properties.displayName) ($($childrenSubscription.name)) Subscription Quota Id: $($sub.subDetails.subscriptionPolicies.quotaId) is out of scope for Azure Governance Visualizer (not in Whitelist)"
if ($sub.subDetails.state -ne 'Enabled') {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: '$($sub.subDetails.subscriptionPolicies.quotaId)' not in Whitelist"
outOfScopeReason = "State: $($sub.subDetails.state)"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
}
else {
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
if ($SubscriptionQuotaIdWhitelist[0] -ne 'undefined') {
$whitelistMatched = 'unknown'
foreach ($subscriptionQuotaIdWhitelistQuotaId in $SubscriptionQuotaIdWhitelist) {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith($subscriptionQuotaIdWhitelistQuotaId, 'CurrentCultureIgnoreCase')) {
$whitelistMatched = 'inWhitelist'
}
}

if ($whitelistMatched -eq 'inWhitelist') {
#write-host "$($childrenSubscription.properties.displayName) in whitelist"
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
}
else {
#Write-Host " preCustomDataCollection: $($childrenSubscription.properties.displayName) ($($childrenSubscription.name)) Subscription Quota Id: $($sub.subDetails.subscriptionPolicies.quotaId) is out of scope for Azure Governance Visualizer (not in Whitelist)"
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: '$($sub.subDetails.subscriptionPolicies.quotaId)' not in Whitelist"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
}
else {
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pwsh/dev/devAzGovVizParallel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Param
$Product = 'AzGovViz',

[string]
$ProductVersion = '6.5.2',
$ProductVersion = '6.5.3',

[string]
$GithubRepository = 'aka.ms/AzGovViz',
Expand Down
94 changes: 53 additions & 41 deletions pwsh/dev/functions/detailSubscriptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,63 +37,75 @@
foreach ($childrenSubscription in $childrenSubscriptions) {

$sub = $htAllSubscriptionsFromAPI.($childrenSubscription.name)
if ($sub.subDetails.subscriptionPolicies.quotaId.startswith('AAD_', 'CurrentCultureIgnoreCase') -or $sub.subDetails.state -ne 'Enabled') {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith('AAD_', 'CurrentCultureIgnoreCase')) {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: AAD_ (State: $($sub.subDetails.state))"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.state -ne 'Enabled') {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "State: $($sub.subDetails.state)"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
if ($sub.subDetails.subscriptionPolicies.quotaId -eq $null) {

Check warning

Code scanning / PSScriptAnalyzer

$null should be on the left side of equality comparisons. Warning

$null should be on the left side of equality comparisons.
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = 'QuotaId: null'
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
else {
if ($SubscriptionQuotaIdWhitelist[0] -ne 'undefined') {
$whitelistMatched = 'unknown'
foreach ($subscriptionQuotaIdWhitelistQuotaId in $SubscriptionQuotaIdWhitelist) {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith($subscriptionQuotaIdWhitelistQuotaId, 'CurrentCultureIgnoreCase')) {
$whitelistMatched = 'inWhitelist'
}
}

if ($whitelistMatched -eq 'inWhitelist') {
#write-host "$($childrenSubscription.properties.displayName) in whitelist"
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
if ($sub.subDetails.subscriptionPolicies.quotaId.startswith('AAD_', 'CurrentCultureIgnoreCase') -or $sub.subDetails.state -ne 'Enabled') {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith('AAD_', 'CurrentCultureIgnoreCase')) {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
outOfScopeReason = "QuotaId: AAD_ (State: $($sub.subDetails.state))"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
else {
#Write-Host " preCustomDataCollection: $($childrenSubscription.properties.displayName) ($($childrenSubscription.name)) Subscription Quota Id: $($sub.subDetails.subscriptionPolicies.quotaId) is out of scope for Azure Governance Visualizer (not in Whitelist)"
if ($sub.subDetails.state -ne 'Enabled') {
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: '$($sub.subDetails.subscriptionPolicies.quotaId)' not in Whitelist"
outOfScopeReason = "State: $($sub.subDetails.state)"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
}
else {
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
if ($SubscriptionQuotaIdWhitelist[0] -ne 'undefined') {
$whitelistMatched = 'unknown'
foreach ($subscriptionQuotaIdWhitelistQuotaId in $SubscriptionQuotaIdWhitelist) {
if (($sub.subDetails.subscriptionPolicies.quotaId).startswith($subscriptionQuotaIdWhitelistQuotaId, 'CurrentCultureIgnoreCase')) {
$whitelistMatched = 'inWhitelist'
}
}

if ($whitelistMatched -eq 'inWhitelist') {
#write-host "$($childrenSubscription.properties.displayName) in whitelist"
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
}
else {
#Write-Host " preCustomDataCollection: $($childrenSubscription.properties.displayName) ($($childrenSubscription.name)) Subscription Quota Id: $($sub.subDetails.subscriptionPolicies.quotaId) is out of scope for Azure Governance Visualizer (not in Whitelist)"
$null = $script:outOfScopeSubscriptions.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
outOfScopeReason = "QuotaId: '$($sub.subDetails.subscriptionPolicies.quotaId)' not in Whitelist"
ManagementGroupId = $htSubscriptionsMgPath.($childrenSubscription.name).Parent
ManagementGroupName = $htSubscriptionsMgPath.($childrenSubscription.name).ParentName
Level = $htSubscriptionsMgPath.($childrenSubscription.name).level
})
}
}
else {
$null = $script:subsToProcessInCustomDataCollection.Add([PSCustomObject]@{
subscriptionId = $childrenSubscription.name
subscriptionName = $childrenSubscription.properties.displayName
subscriptionQuotaId = $sub.subDetails.subscriptionPolicies.quotaId
})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ProductVersion": "6.5.2"
"ProductVersion": "6.5.3"
}
Loading