Skip to content

Commit 7a99763

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents 3bd06d4 + 185a7f9 commit 7a99763

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Get-CIPPAzIdentityToken {
2+
<#
3+
.SYNOPSIS
4+
Get the Azure Identity token for Managed Identity
5+
.DESCRIPTION
6+
This function retrieves the Azure Identity token using the Managed Identity endpoint
7+
.EXAMPLE
8+
Get-CIPPAzIdentityToken
9+
#>
10+
[CmdletBinding()]
11+
param()
12+
13+
$Endpoint = $env:IDENTITY_ENDPOINT
14+
$Secret = $env:IDENTITY_HEADER
15+
$ResourceURI = 'https://management.azure.com/'
16+
17+
if (-not $Endpoint -or -not $Secret) {
18+
throw 'Managed Identity environment variables (IDENTITY_ENDPOINT/IDENTITY_HEADER) not found. Is Managed Identity enabled on the Function App?'
19+
}
20+
21+
$TokenUri = "$($Endpoint)?resource=$($ResourceURI)&api-version=2019-08-01"
22+
$Headers = @{
23+
'X-IDENTITY-HEADER' = $Secret
24+
}
25+
26+
$TokenResponse = Invoke-RestMethod -Method Get -Headers $Headers -Uri $TokenUri
27+
return $TokenResponse.access_token
28+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListNewUserDefaults.ps1

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ function Invoke-ListNewUserDefaults {
1212

1313
# Get the TenantFilter from query parameters
1414
$TenantFilter = $Request.Query.TenantFilter
15-
Write-Host "TenantFilter from request: $TenantFilter"
16-
15+
1716
# Get the includeAllTenants flag from query or body parameters (defaults to true)
1817
$IncludeAllTenants = if ($Request.Query.includeAllTenants -eq 'false' -or $Request.Body.includeAllTenants -eq 'false') {
1918
$false
2019
} else {
2120
$true
2221
}
23-
Write-Host "IncludeAllTenants: $IncludeAllTenants"
2422

2523
# Get the templates table
2624
$Table = Get-CippTable -tablename 'templates'
@@ -33,15 +31,12 @@ function Invoke-ListNewUserDefaults {
3331
$data = $row.JSON | ConvertFrom-Json -Depth 100 -ErrorAction Stop
3432
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $row.GUID -Force
3533
$data | Add-Member -NotePropertyName 'RowKey' -NotePropertyValue $row.RowKey -Force
36-
Write-Host "Template found: $($data.templateName), tenantFilter: $($data.tenantFilter)"
3734
$data
3835
} catch {
3936
Write-Warning "Failed to process User Default template: $($row.RowKey) - $($_.Exception.Message)"
4037
}
4138
}
4239

43-
Write-Host "Total templates before filtering: $($Templates.Count)"
44-
4540
# Filter by tenant if TenantFilter is provided
4641
if ($TenantFilter) {
4742
if ($TenantFilter -eq 'AllTenants') {
@@ -57,7 +52,6 @@ function Invoke-ListNewUserDefaults {
5752
$Templates = $Templates | Where-Object -Property tenantFilter -eq $TenantFilter
5853
}
5954
}
60-
Write-Host "Templates after filtering: $($Templates.Count)"
6155
}
6256

6357
# Sort by template name

profile.ps1

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@ Write-Information '#### CIPP-API Start ####'
44
Set-Location -Path $PSScriptRoot
55
try {
66
$AppInsightsDllPath = Join-Path $PSScriptRoot 'Shared\AppInsights\Microsoft.ApplicationInsights.dll'
7-
if (Test-Path $AppInsightsDllPath) {
8-
[Reflection.Assembly]::LoadFile($AppInsightsDllPath) | Out-Null
9-
Write-Information 'Application Insights SDK loaded successfully'
10-
} else {
11-
Write-Warning "Application Insights DLL not found at: $AppInsightsDllPath"
12-
}
7+
$null = [Reflection.Assembly]::LoadFile($AppInsightsDllPath)
8+
Write-Information 'Application Insights SDK loaded successfully'
139
} catch {
1410
Write-Warning "Failed to load Application Insights SDK: $($_.Exception.Message)"
1511
}
1612

1713
# Import modules
18-
@('CIPPCore', 'CippExtensions', 'Az.KeyVault', 'Az.Accounts', 'AzBobbyTables') | ForEach-Object {
14+
$ModulesPath = Join-Path $PSScriptRoot 'Modules'
15+
$Modules = @('CIPPCore', 'CippExtensions', 'Az.Accounts', 'Az.KeyVault', 'AzBobbyTables')
16+
foreach ($Module in $Modules) {
1917
try {
20-
$Module = $_
21-
Import-Module -Name $_ -ErrorAction Stop
18+
Import-Module -Name (Join-Path $ModulesPath $Module) -ErrorAction Stop
2219
} catch {
2320
Write-LogMessage -message "Failed to import module - $Module" -LogData (Get-CippException -Exception $_) -Sev 'debug'
24-
$_.Exception.Message
21+
Write-Error $_.Exception.Message
2522
}
2623
}
2724

@@ -61,7 +58,7 @@ if ($env:ExternalDurablePowerShellSDK -eq $true) {
6158
}
6259

6360
try {
64-
Disable-AzContextAutosave -Scope Process | Out-Null
61+
$null = Disable-AzContextAutosave -Scope Process
6562
} catch {}
6663

6764
try {
@@ -73,8 +70,7 @@ try {
7370
Write-LogMessage -message 'Could not retrieve keys from Keyvault' -LogData (Get-CippException -Exception $_) -Sev 'debug'
7471
}
7572

76-
Set-Location -Path $PSScriptRoot
77-
$CurrentVersion = (Get-Content .\version_latest.txt).trim()
73+
$CurrentVersion = (Get-Content -Path (Join-Path $PSScriptRoot 'version_latest.txt') -Raw).Trim()
7874
$Table = Get-CippTable -tablename 'Version'
7975
Write-Information "Function App: $($env:WEBSITE_SITE_NAME) | API Version: $CurrentVersion | PS Version: $($PSVersionTable.PSVersion)"
8076
$global:CippVersion = $CurrentVersion
@@ -84,7 +80,7 @@ if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
8480
Write-Information "Version has changed from $($LastStartup.Version ?? 'None') to $CurrentVersion"
8581
if ($LastStartup) {
8682
$LastStartup.Version = $CurrentVersion
87-
$LastStartup | Add-Member -MemberType NoteProperty -Name 'PSVersion' -Value $PSVersionTable.PSVersion.ToString() -Force
83+
Add-Member -InputObject $LastStartup -MemberType NoteProperty -Name 'PSVersion' -Value $PSVersionTable.PSVersion.ToString() -Force
8884
} else {
8985
$LastStartup = [PSCustomObject]@{
9086
PartitionKey = 'Version'

requirements.psd1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# This file enables modules to be automatically managed by the Functions service.
22
# See https://aka.ms/functionsmanageddependency for additional information.
33
#
4-
@{
5-
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
6-
# To use the Az module in your function app, please uncomment the line below.
7-
'Az.accounts' = '2.*'
8-
'Az.Keyvault' = '3.*'
9-
'AzBobbyTables' = '2.*'
10-
}
4+
# CIPP bundles all modules locally in the Modules folder and imports them explicitly.
5+
# managedDependency is disabled in host.json - this file is intentionally empty.
6+
@{}

0 commit comments

Comments
 (0)