Skip to content

Commit

Permalink
Update Code Improvement (#828)
Browse files Browse the repository at this point in the history
* Update

* Update to Checkout v4

* Remove ARMAzOpsSetup.ps1
  • Loading branch information
Jefajers authored Nov 13, 2023
1 parent e1b4db3 commit a57b415
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Configure"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: "Configure"
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

# Checkout
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:

# Checkout
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wiki-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.wiki_source_repo }}
path: ${{ env.wiki_source_repo }}

- name: Checkout Wiki Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.wiki_target_repo }}
path: ${{ env.wiki_target_repo }}
Expand Down
205 changes: 0 additions & 205 deletions scripts/ARMAzOpsSetup.ps1

This file was deleted.

12 changes: 6 additions & 6 deletions scripts/Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ param (
# Development Modules
Set-PSRepository -Name $Repository -InstallationPolicy Trusted
$modules = @("Pester", "PSModuleDevelopment", "PSScriptAnalyzer")
Write-Host "Installing development modules"
Write-Output "Installing development modules"
foreach ($module in $modules) {
Write-Host "Installing: $module"
Write-Output "Installing: $module"
Install-Module $module -Repository $Repository -Force
}
# Runtime Modules
$data = Import-PowerShellDataFile -Path "$PSScriptRoot/../src/AzOps.psd1"
Write-Host "Installing runtime modules"
Write-Output "Installing runtime modules"
foreach ($dependency in $data.RequiredModules) {
$module = Get-Module -Name $dependency.ModuleName -ListAvailable
if ($module) {
foreach ($item in $module) {
Write-Host "Cleanup of: $($item.Name)"
Uninstall-Module -Name $item.Name -Force
Write-Output "Cleanup of: $($item.Name)"
Uninstall-Module -Name $item.Name -Force
}
}
Write-Host "Installing: $($dependency.ModuleName) $($dependency.RequiredVersion)"
Write-Output "Installing: $($dependency.ModuleName) $($dependency.RequiredVersion)"
Install-Module -Name $dependency.ModuleName -RequiredVersion $dependency.RequiredVersion -Repository $Repository
}
# Download and add bicep to PATH
Expand Down
6 changes: 3 additions & 3 deletions scripts/Remove-AzOpsTestsDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

process {
if ($CleanupEnvironment) {
function Remove-ManagementGroups {
function Remove-ManagementGroup {

param (
[Parameter()]
Expand All @@ -40,7 +40,7 @@
if ($_.Type -eq "Microsoft.Management/managementGroups") {
# Invoke function again with Child resources
Write-PSFMessage -Level Verbose -Message "Nested Management Group: $($DisplayName)" -FunctionName "Remove-AzOpsTestsDeployment"
Remove-ManagementGroups -DisplayName $_.DisplayName -Name $_.Name -RootName $RootName
Remove-ManagementGroup -DisplayName $_.DisplayName -Name $_.Name -RootName $RootName
}
if ($_.Type -eq '/subscriptions') {
# Move Subscription resource to Tenant Root Group
Expand All @@ -60,7 +60,7 @@
# Cleanup managementGroups
$script:managementGroups = Get-AzManagementGroup -ErrorAction SilentlyContinue | Where-Object {$_.DisplayName -eq "Test" -or $_.DisplayName -eq "AzOpsMGMTName"} -ErrorAction SilentlyContinue
foreach ($script:mgclean in $script:managementGroups) {
Remove-ManagementGroups -DisplayName $script:mgclean.DisplayName -Name $script:mgclean.Name -RootName (Get-AzTenant).TenantId
Remove-ManagementGroup -DisplayName $script:mgclean.DisplayName -Name $script:mgclean.Name -RootName (Get-AzTenant).TenantId
}
# Collect resources to cleanup
Get-AzResourceLock | Remove-AzResourceLock -Force
Expand Down
11 changes: 8 additions & 3 deletions src/internal/functions/Get-AzOpsManagementGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidateScript( { Get-AzManagementGroup -GroupId $_ -WarningAction SilentlyContinue })]
$ManagementGroup,

[switch]
$PartialDiscovery
)

process {
$groupObject = Get-AzManagementGroup -GroupId $ManagementGroup -Expand -WarningAction SilentlyContinue
try {
$groupObject = Get-AzManagementGroup -GroupId $ManagementGroup -Expand -WarningAction SilentlyContinue
}
catch {
Write-PSFMessage -Level Error -String 'Get-AzOpsManagementGroup.Failed' -StringValues $ManagementGroup
throw
}
if ($PartialDiscovery) {
if ($groupObject.ParentId -and -not (Get-AzManagementGroup -GroupId $groupObject.ParentName -ErrorAction Ignore -WarningAction SilentlyContinue)) {
$script:AzOpsPartialRoot += $groupObject
Expand All @@ -50,7 +55,7 @@
}
}
}
$groupObject
return $groupObject
}

}
2 changes: 1 addition & 1 deletion src/internal/functions/Get-AzOpsSubscription.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$TenantId,

[string]
$ApiVersion = '2020-01-01'
$ApiVersion = '2022-12-01'
)

process {
Expand Down
2 changes: 2 additions & 0 deletions src/localized/en-us/Strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
'Get-AzOpsCurrentPrincipal.AccountType' = 'Current AccountType is {0}' #$AzContext.Account.Type
'Get-AzOpsCurrentPrincipal.PrincipalId' = 'Current PrincipalId is {0}' #$principalObject.id

'Get-AzOpsManagementGroup.Failed' = 'Get-AzManagementGroup -GroupId {0} failed' #$ManagementGroup

'Get-AzOpsPolicyAssignment.ManagementGroup' = 'Retrieving Policy Assignment for Management Group {0} ({1})' # $ScopeObject.ManagementGroupDisplayName, $ScopeObject.ManagementGroup
'Get-AzOpsPolicyAssignment.ResourceGroup' = 'Retrieving Policy Assignment for Resource Group in {0} Subscription objects' # $Subscription.count
'Get-AzOpsPolicyAssignment.Subscription' = 'Retrieving Policy Assignment for {0} Subscription objects' # $Subscription.count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ try {
$script:mgmt = Get-AzManagementGroup
$script:testManagementGroup = ($script:mgmt | Where-Object Name -eq "AzOpsMGMTID")

if ($script:testManagementGroup -ne $null) {
if ($null -ne $script:testManagementGroup) {
$script:mgmtRun = "Done"
}
else {
Expand Down

0 comments on commit a57b415

Please sign in to comment.