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

Custom Headers Update automation #1234

Open
wants to merge 2 commits into
base: modularize
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion module/Entra/config/moduleMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"New-EntraOauth2PermissionGrant": "SignIns",
"New-EntraConditionalAccessPolicy": "SignIns",
"New-EntraIdentityProvider": "SignIns",
"New-EntraInvitation": "Invitations",
"New-EntraInvitation": "SignIns",
"New-EntraPermissionGrantConditionSet": "SignIns",
"New-EntraPermissionGrantPolicy": "SignIns",
"Remove-EntraConditionalAccessPolicy": "SignIns",
Expand All @@ -189,6 +189,7 @@
"Set-EntraTenantDetail": "DirectoryManagement",
"Add-EntraScopedRoleMembership": "DirectoryManagement",
"Get-EntraUser": "Users",
"Get-EntraUserAuthenticationMethod":"SignIns",
"Get-EntraUserAppRoleAssignment": "Users",
"Get-EntraUserCreatedObject": "Users",
"Get-EntraUserDirectReport": "Users",
Expand Down
36 changes: 33 additions & 3 deletions src/EntraModuleSplitter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,44 @@ class EntraModuleSplitter {
}


[void] AddFunctionsToAllDirectories([string]$moduleOutputDirectory, [PSCustomObject[]]$functionContents) {
[void] AddFunctionsToAllDirectories([string]$moduleOutputDirectory, [PSCustomObject[]]$functionContents, [string]$Module = 'Entra') {
# Validate the module parameter
if ($Module -notin @('Entra', 'EntraBeta')) {
Write-Error "Invalid module specified. Please provide either 'Entra' or 'EntraBeta'."
return
}

# Get all directories under the module output directory
$subDirectories = Get-ChildItem -Path $moduleOutputDirectory -Directory

foreach ($subDir in $subDirectories) {
foreach ($functionContent in $functionContents) {
# Construct the full path for the function file
$functionName = $functionContent.Name
$headerPs1Content = $this.Header + "`n" + $functionContent.Content+ "`n"+"`n"
$headerPs1Content = $this.Header + "`n" + $functionContent.Content + "`n" + "`n"

# If the function is 'New-EntraCustomHeaders', modify the version line
if ($functionName -eq "New-EntraCustomHeaders") {
$currentSubDirName = $subDir.Name

# Search for the line containing the version line
if ($Module -eq 'Entra') {
# For Entra module, look for 'Microsoft.Graph.Entra' in the version line
if ($headerPs1Content -match "Microsoft.Graph.Entra") {
# Replace 'Microsoft.Graph.Entra' with 'Microsoft.Entra.<SubDirectoryName>'
$headerPs1Content = $headerPs1Content -replace "Microsoft.Graph.Entra", "Microsoft.Entra.$currentSubDirName"
}
}
elseif ($Module -eq 'EntraBeta') {
# For EntraBeta module, look for 'Microsoft.Graph.Entra.Beta' in the version line
if ($headerPs1Content -match "Microsoft.Graph.Entra.Beta") {
# Replace 'Microsoft.Graph.Entra.Beta' with 'Microsoft.Entra.Beta.<SubDirectoryName>'
$headerPs1Content = $headerPs1Content -replace "Microsoft.Graph.Entra.Beta", "Microsoft.Entra.Beta.$currentSubDirName"
}
}
}

# Construct the function file path
$functionFilePath = Join-Path -Path $subDir.FullName -ChildPath "$functionName.ps1"

# Write the function to the specified file
Expand All @@ -139,6 +168,7 @@ class EntraModuleSplitter {
}
}


[string] GetModuleName([string] $Module="Entra"){
if ($Module -eq 'Entra') {
return "Microsoft.Entra"
Expand Down Expand Up @@ -189,7 +219,7 @@ class EntraModuleSplitter {
}

# Call the new method to add functions to all directories
$this.AddFunctionsToAllDirectories($moduleOutputDirectory, $functionContents)
$this.AddFunctionsToAllDirectories($moduleOutputDirectory, $functionContents,$Module)

Log-Message "[EntraModuleSplitter] Splitting and organizing complete." -Level 'SUCCESS'
}
Expand Down