Skip to content

Commit c3ae8fc

Browse files
committed
Add User-Agent header with CIPP version to Graph requests
Set a default User-Agent header including the CIPP version for both GET and POST Graph API requests. The CIPP version is now stored globally in profile.ps1. Also, removed hardcoded User-Agent from Invoke-CIPPStandardAddDMARCToMOERA to use the new default behavior.
1 parent 671853f commit c3ae8fc

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ function New-GraphGetRequest {
4747
$headers[$key] = $extraHeaders[$key]
4848
}
4949
}
50+
51+
if (!$headers['User-Agent']) {
52+
$headers['User-Agent'] = "CIPP/$($global:CippVersion ?? '1.0')"
53+
}
54+
5055
# Track consecutive Graph API failures
5156
$TenantsTable = Get-CippTable -tablename Tenants
5257
$Filter = "PartitionKey eq 'Tenants' and (defaultDomainName eq '{0}' or customerId eq '{0}')" -f $tenantid

Modules/CIPPCore/Public/GraphHelper/New-GraphPOSTRequest.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function New-GraphPOSTRequest {
2828
}
2929
}
3030

31+
if (!$headers['User-Agent']) {
32+
$headers['User-Agent'] = "CIPP/$($global:CippVersion ?? '1.0')"
33+
}
34+
3135
if (!$contentType) {
3236
$contentType = 'application/json; charset=utf-8'
3337
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAddDMARCToMOERA.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Invoke-CIPPStandardAddDMARCToMOERA {
5151

5252
$CurrentInfo = $Domains | ForEach-Object {
5353
# Get current DNS records that matches _dmarc hostname and TXT type
54-
$RecordsResponse = New-GraphGetRequest -scope 'https://admin.microsoft.com/.default' -TenantID $Tenant -Uri "https://admin.microsoft.com/admin/api/Domains/Records?domainName=$($_.Name)" -extraHeaders @{'User-Agent' = 'CIPP/1.0' }
54+
$RecordsResponse = New-GraphGetRequest -scope 'https://admin.microsoft.com/.default' -TenantID $Tenant -Uri "https://admin.microsoft.com/admin/api/Domains/Records?domainName=$($_.Name)"
5555
$AllRecords = $RecordsResponse | Select-Object -ExpandProperty DnsRecords
5656
$CurrentRecords = $AllRecords | Where-Object { $_.HostName -eq '_dmarc' -and $_.Type -eq 'TXT' }
5757
Write-Information "Found $($CurrentRecords.count) DMARC records for domain $($_.Name)"

profile.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Set-Location -Path $PSScriptRoot
7777
$CurrentVersion = (Get-Content .\version_latest.txt).trim()
7878
$Table = Get-CippTable -tablename 'Version'
7979
Write-Information "Function App: $($env:WEBSITE_SITE_NAME) | API Version: $CurrentVersion | PS Version: $($PSVersionTable.PSVersion)"
80+
$global:CippVersion = $CurrentVersion
81+
8082
$LastStartup = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'Version' and RowKey eq '$($env:WEBSITE_SITE_NAME)'"
8183
if (!$LastStartup -or $CurrentVersion -ne $LastStartup.Version) {
8284
Write-Information "Version has changed from $($LastStartup.Version ?? 'None') to $CurrentVersion"

0 commit comments

Comments
 (0)