Skip to content

Commit 4fa6c67

Browse files
authored
Merge pull request #13 from Zacgoose/copilot/investigate-me-endpoint-issues
Optimize HTTP function loading by splitting Standards into separate module with lazy-loading
2 parents d31530a + 08bbd82 commit 4fa6c67

File tree

684 files changed

+266
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

684 files changed

+266
-144
lines changed

.github/workflows/dev_api.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,83 @@ jobs:
2626
with:
2727
persist-credentials: false
2828

29+
- name: Setup PowerShell module cache
30+
id: cacher
31+
uses: actions/cache@v3
32+
with:
33+
path: "~/.local/share/powershell/Modules"
34+
key: ${{ runner.os }}-ModuleBuilder
35+
36+
- name: Install ModuleBuilder
37+
if: steps.cacher.outputs.cache-hit != 'true'
38+
shell: pwsh
39+
run: |
40+
Set-PSRepository PSGallery -InstallationPolicy Trusted
41+
Install-Module ModuleBuilder -AllowClobber -Force
42+
43+
- name: Build CIPPCore Module
44+
shell: pwsh
45+
run: |
46+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPCore"
47+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
48+
49+
Write-Host "Building module from: $ModulePath"
50+
Write-Host "Output directory: $OutputPath"
51+
52+
# Build the module using ModuleBuilder
53+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
54+
55+
# Replace the source module with the built module
56+
Remove-Item -Path $ModulePath -Recurse -Force
57+
Copy-Item -Path (Join-Path $OutputPath "CIPPCore") -Destination $ModulePath -Recurse -Force
58+
59+
Write-Host "Module built and replaced successfully"
60+
61+
# Clean up output directory
62+
Remove-Item -Path $OutputPath -Recurse -Force
63+
64+
- name: Build CippExtensions Module
65+
shell: pwsh
66+
run: |
67+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CippExtensions"
68+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
69+
70+
Write-Host "Building module from: $ModulePath"
71+
Write-Host "Output directory: $OutputPath"
72+
73+
# Build the module using ModuleBuilder
74+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
75+
76+
# Replace the source module with the built module
77+
Remove-Item -Path $ModulePath -Recurse -Force
78+
Copy-Item -Path (Join-Path $OutputPath "CippExtensions") -Destination $ModulePath -Recurse -Force
79+
80+
Write-Host "Module built and replaced successfully"
81+
82+
# Clean up output directory
83+
Remove-Item -Path $OutputPath -Recurse -Force
84+
85+
- name: Build CIPPStandardsAlerts Module
86+
shell: pwsh
87+
run: |
88+
$ModulePath = Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPStandardsAlerts"
89+
$OutputPath = Join-Path $env:GITHUB_WORKSPACE "Output"
90+
91+
Write-Host "Building module from: $ModulePath"
92+
Write-Host "Output directory: $OutputPath"
93+
94+
# Build the module using ModuleBuilder
95+
Build-Module -SourcePath $ModulePath -OutputDirectory $OutputPath -Verbose
96+
97+
# Replace the source module with the built module
98+
Remove-Item -Path $ModulePath -Recurse -Force
99+
Copy-Item -Path (Join-Path $OutputPath "CIPPStandardsAlerts") -Destination $ModulePath -Recurse -Force
100+
101+
Write-Host "Module built and replaced successfully"
102+
103+
# Clean up output directory
104+
Remove-Item -Path $OutputPath -Recurse -Force
105+
29106
- name: Login to Azure
30107
uses: azure/login@v2
31108
with:

Modules/CIPPCore/CIPPCore.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ModuleBuilder will concatenate all function files into this module
22
# This block is only used when running from source (not built)
33
if (Test-Path (Join-Path $PSScriptRoot 'Public')) {
4+
# Load Public and Private functions
45
$Public = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public\*.ps1') -Recurse -ErrorAction SilentlyContinue)
56
$Private = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private\*.ps1') -Recurse -ErrorAction SilentlyContinue)
67
$Functions = $Public + $Private

Modules/CIPPCore/Public/Authentication/Test-CIPPAccess.ps1

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,15 @@ function Test-CIPPAccess {
1212
# Get function help
1313
$FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint
1414

15-
$SwPermissions = [System.Diagnostics.Stopwatch]::StartNew()
16-
if (-not $global:CIPPFunctionPermissions) {
17-
$CIPPCoreModule = Get-Module -Name CIPPCore
18-
if ($CIPPCoreModule) {
19-
$PermissionsFileJson = Join-Path $CIPPCoreModule.ModuleBase 'lib' 'data' 'function-permissions.json'
20-
21-
if (Test-Path $PermissionsFileJson) {
22-
try {
23-
$jsonData = Get-Content -Path $PermissionsFileJson -Raw | ConvertFrom-Json -AsHashtable
24-
$global:CIPPFunctionPermissions = [System.Collections.Hashtable]::new([StringComparer]::OrdinalIgnoreCase)
25-
foreach ($key in $jsonData.Keys) {
26-
$global:CIPPFunctionPermissions[$key] = $jsonData[$key]
27-
}
28-
Write-Information "Loaded $($global:CIPPFunctionPermissions.Count) function permissions from JSON cache"
29-
} catch {
30-
Write-Warning "Failed to load function permissions from JSON: $($_.Exception.Message)"
31-
}
32-
}
33-
}
34-
}
35-
$SwPermissions.Stop()
36-
$AccessTimings['FunctionPermissions'] = $SwPermissions.Elapsed.TotalMilliseconds
37-
3815
if ($FunctionName -ne 'Invoke-me') {
3916
$swHelp = [System.Diagnostics.Stopwatch]::StartNew()
40-
if ($global:CIPPFunctionPermissions -and $global:CIPPFunctionPermissions.ContainsKey($FunctionName)) {
41-
$PermissionData = $global:CIPPFunctionPermissions[$FunctionName]
42-
$APIRole = $PermissionData['Role']
43-
$Functionality = $PermissionData['Functionality']
44-
Write-Information "Loaded function permission data from cache for '$FunctionName': Role='$APIRole', Functionality='$Functionality'"
45-
} else {
46-
try {
47-
$Help = Get-Help $FunctionName -ErrorAction Stop
48-
$APIRole = $Help.Role
49-
$Functionality = $Help.Functionality
50-
Write-Information "Loaded function permission data via Get-Help for '$FunctionName': Role='$APIRole', Functionality='$Functionality'"
51-
} catch {
52-
Write-Warning "Function '$FunctionName' not found"
53-
}
17+
try {
18+
$Help = Get-Help $FunctionName -ErrorAction Stop
19+
$APIRole = $Help.Role
20+
$Functionality = $Help.Functionality
21+
Write-Debug "Loaded function permission data via Get-Help for '$FunctionName': Role='$APIRole', Functionality='$Functionality'"
22+
} catch {
23+
Write-Warning "Function '$FunctionName' not found"
5424
}
5525
$swHelp.Stop()
5626
$AccessTimings['GetHelp'] = $swHelp.Elapsed.TotalMilliseconds

Modules/CIPPHTTP/CIPPHTTP.psd1

8.48 KB
Binary file not shown.

Modules/CIPPHTTP/CIPPHTTP.psm1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ModuleBuilder will concatenate all function files into this module
2+
# This block is only used when running from source (not built)
3+
if (Test-Path (Join-Path $PSScriptRoot 'Public')) {
4+
# Load Public and Private functions
5+
$Public = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public\*.ps1') -Recurse -ErrorAction SilentlyContinue)
6+
$Private = @(Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private\*.ps1') -Recurse -ErrorAction SilentlyContinue)
7+
$Functions = $Public + $Private
8+
foreach ($import in @($Functions)) {
9+
try {
10+
. $import.FullName
11+
} catch {
12+
Write-Error -Message "Failed to import function $($import.FullName): $_"
13+
}
14+
}
15+
16+
Export-ModuleMember -Function $Public.BaseName
17+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAddAlert.ps1 renamed to Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAddAlert.ps1

File renamed without changes.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAppInsightsQuery.ps1 renamed to Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAppInsightsQuery.ps1

File renamed without changes.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAzBobbyTables.ps1 renamed to Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAzBobbyTables.ps1

File renamed without changes.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecCPVRefresh.ps1 renamed to Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecCPVRefresh.ps1

File renamed without changes.

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecCippFunction.ps1 renamed to Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecCippFunction.ps1

File renamed without changes.

0 commit comments

Comments
 (0)