Skip to content

Commit 1f8e485

Browse files
committed
tweaks
1 parent 539f061 commit 1f8e485

File tree

3 files changed

+19
-134
lines changed

3 files changed

+19
-134
lines changed

.github/workflows/dev_api.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ jobs:
4040
Set-PSRepository PSGallery -InstallationPolicy Trusted
4141
Install-Module ModuleBuilder -AllowClobber -Force
4242
43+
- name: Build Permissions and Functions Caches
44+
shell: pwsh
45+
run: |
46+
Write-Host "Building Permission Cache"
47+
# Build the Permission Cache
48+
$ScriptPath = Join-Path $env:GITHUB_WORKSPACE "Tools/Build-PermissionsCache.ps1"
49+
& $ScriptPath -SourcePath (Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPHTTP") -OutputPath (Join-Path $env:GITHUB_WORKSPACE "Config/function-metadata.psd1")
50+
51+
Write-Host "Building Function Cache"
52+
# Build the Function Cache
53+
$ScriptPath = Join-Path $env:GITHUB_WORKSPACE "Tools/Build-FunctionParametersCache.ps1"
54+
& $ScriptPath -SourcePath (Join-Path $env:GITHUB_WORKSPACE "Modules/CIPPHTTP") -OutputPath (Join-Path $env:GITHUB_WORKSPACE "Config/function-parameters.json")
55+
4356
- name: Build CIPPCore Module
4457
shell: pwsh
4558
run: |

Tools/Build-FunctionParametersCache.ps1

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,6 @@ Write-Host "Validating generated file..." -ForegroundColor Cyan
186186
try {
187187
$test = Get-Content $OutputPath -Raw | ConvertFrom-Json
188188
Write-Host "✓ Validation successful!" -ForegroundColor Green
189-
Write-Host " Functions: $($test.Functions.PSObject.Properties.Count)" -ForegroundColor Gray
190-
191-
# Test a function with parameters
192-
$sampleFunc = $test.Functions.PSObject.Properties |
193-
Where-Object { $_.Value.Parameters } |
194-
Select-Object -First 1
195-
196-
if ($sampleFunc) {
197-
Write-Host " Sample function '$($sampleFunc.Name)' has $($sampleFunc.Value.Parameters.Count) parameters (type: $($sampleFunc.Value.Parameters.GetType().Name))" -ForegroundColor Gray
198-
}
199189
} catch {
200190
Write-Error "Validation failed: $_"
201191
exit 1
Lines changed: 6 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<#
22
.SYNOPSIS
3-
Generates function metadata cache for CIPP module
3+
Generates function permission cache for modules
44
.PARAMETER ModuleName
5-
Name of the module (used in output filename and metadata)
5+
Name of the module (used in output filename and cache)
66
#>
77
[CmdletBinding()]
88
param(
@@ -15,18 +15,12 @@ param(
1515
[Parameter()]
1616
[string]$ModuleName,
1717

18-
[string]$FunctionPattern = '*.ps1',
19-
20-
[switch]$IncludeParameters,
21-
22-
[switch]$IncludeHelp,
23-
24-
[switch]$IncludeAll
18+
[string]$FunctionPattern = '*.ps1'
2519
)
2620

2721
Write-Host "Starting metadata generation..." -ForegroundColor Cyan
2822
Write-Host "Module: $(if($ModuleName){$ModuleName}else{'Not Specified'})" -ForegroundColor Cyan
29-
Write-Host "Mode: $(if($IncludeAll){'Full'}elseif($IncludeParameters -and $IncludeHelp){'Parameters + Help'}elseif($IncludeParameters){'Parameters Only'}elseif($IncludeHelp){'Help Only'}else{'Minimal (Role/Functionality)'})" -ForegroundColor Cyan
23+
Write-Host "Mode: Minimal (Role/Functionality)" -ForegroundColor Cyan
3024

3125
$metadata = @{
3226
ModuleName = if ($ModuleName) { $ModuleName } else { 'Unknown' }
@@ -40,13 +34,7 @@ Write-Host "Found $($functionFiles.Count) function files to process" -Foreground
4034

4135
$parseErrors = @()
4236
$processed = 0
43-
$stats = @{
44-
Role = 0
45-
Functionality = 0
46-
Synopsis = 0
47-
Description = 0
48-
Parameters = 0
49-
}
37+
$stats = @{ Role = 0; Functionality = 0 }
5038

5139
foreach ($file in $functionFiles) {
5240
$processed++
@@ -84,115 +72,16 @@ foreach ($file in $functionFiles) {
8472
# Extract help content
8573
$help = $functionDef.GetHelpContent()
8674

87-
# Build function metadata
75+
# Build function metadata (only Role and Functionality)
8876
$funcMeta = [ordered]@{}
89-
90-
# Always include Role and Functionality
9177
if ($help.Role) {
9278
$funcMeta.Role = $help.Role.Trim()
9379
$stats.Role++
9480
}
95-
9681
if ($help.Functionality) {
9782
$funcMeta.Functionality = $help.Functionality.Trim()
9883
$stats.Functionality++
9984
}
100-
101-
# Include help content if requested
102-
if ($IncludeHelp -or $IncludeAll) {
103-
if ($help.Synopsis) {
104-
$funcMeta.Synopsis = $help.Synopsis.Trim()
105-
$stats.Synopsis++
106-
}
107-
108-
if ($help.Description.Text) {
109-
$funcMeta.Description = $help.Description.Text.Trim()
110-
$stats.Description++
111-
}
112-
}
113-
114-
# Include parameters if requested
115-
if ($IncludeParameters -or $IncludeAll) {
116-
$parameters = [ordered]@{}
117-
118-
foreach ($param in $functionDef.Parameters) {
119-
$paramName = $param.Name.VariablePath.UserPath
120-
121-
$paramType = if ($param.StaticType) {
122-
$param.StaticType.Name
123-
} else {
124-
'Object'
125-
}
126-
127-
$mandatory = $false
128-
$validateSet = $null
129-
$validateRange = $null
130-
$validatePattern = $null
131-
$paramHelp = $null
132-
133-
foreach ($attribute in $param.Attributes) {
134-
$attrTypeName = $attribute.TypeName.Name
135-
136-
if ($attrTypeName -eq 'Parameter') {
137-
$mandatoryArg = $attribute.NamedArguments | Where-Object { $_.ArgumentName -eq 'Mandatory' }
138-
if ($mandatoryArg) {
139-
$mandatory = $mandatoryArg.Argument.Value
140-
}
141-
}
142-
143-
if ($attrTypeName -eq 'ValidateSet') {
144-
$validateSet = @($attribute.PositionalArguments.Value)
145-
}
146-
147-
if ($attrTypeName -eq 'ValidateRange') {
148-
$validateRange = @{
149-
Min = $attribute.PositionalArguments[0].Value
150-
Max = $attribute.PositionalArguments[1].Value
151-
}
152-
}
153-
154-
if ($attrTypeName -eq 'ValidatePattern') {
155-
$validatePattern = $attribute.PositionalArguments[0].Value
156-
}
157-
}
158-
159-
if ($help.Parameters) {
160-
$paramHelp = $help.Parameters.Parameter | Where-Object { $_.Name -eq $paramName } | Select-Object -First 1
161-
}
162-
163-
$paramInfo = [ordered]@{
164-
Type = $paramType
165-
}
166-
167-
if ($mandatory) {
168-
$paramInfo.Mandatory = $mandatory
169-
}
170-
171-
if ($validateSet) {
172-
$paramInfo.ValidateSet = $validateSet
173-
}
174-
175-
if ($validateRange) {
176-
$paramInfo.ValidateRange = $validateRange
177-
}
178-
179-
if ($validatePattern) {
180-
$paramInfo.ValidatePattern = $validatePattern
181-
}
182-
183-
if ($paramHelp -and $paramHelp.Description.Text) {
184-
$paramInfo.Description = $paramHelp.Description.Text.Trim()
185-
}
186-
187-
$parameters[$paramName] = $paramInfo
188-
}
189-
190-
if ($parameters.Count -gt 0) {
191-
$funcMeta.Parameters = $parameters
192-
$stats.Parameters++
193-
}
194-
}
195-
19685
if ($funcMeta.Count -gt 0) {
19786
$metadata.Functions[$functionName] = $funcMeta
19887
}
@@ -309,13 +198,6 @@ Write-Host "Functions processed: $($metadata.Functions.Count)" -ForegroundColor
309198
Write-Host "`nMetadata Statistics:" -ForegroundColor Cyan
310199
Write-Host " Functions with Role: $($stats.Role)" -ForegroundColor Gray
311200
Write-Host " Functions with Functionality: $($stats.Functionality)" -ForegroundColor Gray
312-
if ($IncludeHelp -or $IncludeAll) {
313-
Write-Host " Functions with Synopsis: $($stats.Synopsis)" -ForegroundColor Gray
314-
Write-Host " Functions with Description: $($stats.Description)" -ForegroundColor Gray
315-
}
316-
if ($IncludeParameters -or $IncludeAll) {
317-
Write-Host " Functions with Parameters: $($stats.Parameters)" -ForegroundColor Gray
318-
}
319201

320202
if ($parseErrors) {
321203
Write-Warning "`nParse errors encountered in $($parseErrors.Count) files:"

0 commit comments

Comments
 (0)