Skip to content

Commit 7483979

Browse files
authored
Merge pull request #43 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5a83257 + 2b369db commit 7483979

19 files changed

Lines changed: 141 additions & 116 deletions

Modules/CIPPCore/Public/Assert-CippVersion.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function Assert-CippVersion {
1313
param($CIPPVersion)
1414
$APIVersion = (Get-Content -Path (Join-Path $env:CIPPRootPath 'version_latest.txt')).trim()
1515

16-
$RemoteAPIVersion = (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/KelvinTegelaar/CIPP-API/master/version_latest.txt').trim()
17-
$RemoteCIPPVersion = (Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/KelvinTegelaar/CIPP/main/public/version.json').version
16+
$RemoteAPIVersion = (Invoke-CIPPRestMethod -Uri 'https://raw.githubusercontent.com/KelvinTegelaar/CIPP-API/master/version_latest.txt').trim()
17+
$RemoteCIPPVersion = (Invoke-CIPPRestMethod -Uri 'https://raw.githubusercontent.com/KelvinTegelaar/CIPP/main/public/version.json').version
1818

1919
[PSCustomObject]@{
2020
LocalCIPPVersion = $CIPPVersion

Modules/CIPPCore/Public/Authentication/Get-CIPPAzIdentityToken.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Get-CIPPAzIdentityToken {
5555
'X-IDENTITY-HEADER' = $Secret
5656
}
5757

58-
$TokenResponse = Invoke-RestMethod -Method Get -Headers $Headers -Uri $TokenUri -ErrorAction Stop
58+
$TokenResponse = Invoke-CIPPRestMethod -Method Get -Headers $Headers -Uri $TokenUri -ErrorAction Stop
5959

6060
# Calculate expiration time
6161
$ExpiresOn = [int](Get-Date -UFormat %s -Millisecond 0) + $TokenResponse.expires_in

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-CIPPStatsTimer.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ function Start-CIPPStatsTimer {
5454
GitHub = $RawExt.GitHub.Enabled
5555
} | ConvertTo-Json
5656
try {
57-
Invoke-RestMethod -Uri 'https://management.cipp.app/api/stats' -Method POST -Body $SendingObject -ContentType 'application/json'
57+
Invoke-CIPPRestMethod -Uri 'https://management.cipp.app/api/stats' -Method POST -Body $SendingObject -ContentType 'application/json'
5858
} catch {
5959
$rand = Get-Random -Minimum 0.5 -Maximum 5.5
6060
Start-Sleep -Seconds $rand
61-
Invoke-RestMethod -Uri 'https://management.cipp.app/api/stats' -Method POST -Body $SendingObject -ContentType 'application/json'
61+
Invoke-CIPPRestMethod -Uri 'https://management.cipp.app/api/stats' -Method POST -Body $SendingObject -ContentType 'application/json'
6262
}
6363
}
6464
}

Modules/CIPPCore/Public/Get-ApplicationInsightsQuery.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Get-ApplicationInsightsQuery {
3232
$headerParams = @{'Authorization' = "Bearer $Token" }
3333
$logAnalyticsBaseURI = 'https://api.loganalytics.io/v1'
3434

35-
$result = Invoke-RestMethod -Method POST -Uri "$($logAnalyticsBaseURI)/$AppInsightsQuery" -Headers $headerParams -Body $Body -ContentType 'application/json' -ErrorAction Stop
35+
$result = Invoke-CIPPRestMethod -Method POST -Uri "$($logAnalyticsBaseURI)/$AppInsightsQuery" -Headers $headerParams -Body $Body -ContentType 'application/json' -ErrorAction Stop
3636

3737
# Format Result to PSObject
3838
$headerRow = $null

Modules/CIPPCore/Public/Get-CIPPGeoIPLocation.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Get-CIPPGeoIPLocation {
1111
if ($GeoIP) {
1212
return ($GeoIP.Data | ConvertFrom-Json)
1313
}
14-
$location = Invoke-RestMethod "https://geoipdb.azurewebsites.net/api/GetIPInfo?IP=$IP"
14+
$location = Invoke-CIPPRestMethod -Uri "https://geoipdb.azurewebsites.net/api/GetIPInfo?IP=$IP"
1515
if ($location.status -eq 'FAIL') { throw "Could not get location for $IP" }
1616
$CacheGeo = @{
1717
PartitionKey = 'IP'

Modules/CIPPCore/Public/Get-CIPPPartnerAzSubscriptions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function Get-CIPPPartnerAzSubscriptions {
66

77
try {
88
if ($variable -notmatch '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}') {
9-
$TenantFilter = (Invoke-RestMethod -Method GET "https://login.windows.net/$TenantFilter/.well-known/openid-configuration").token_endpoint.Split('/')[3]
9+
$TenantFilter = (Invoke-CIPPRestMethod -Method GET -Uri "https://login.windows.net/$TenantFilter/.well-known/openid-configuration").token_endpoint.Split('/')[3]
1010
}
1111
} catch {
1212
throw "Tenant $($TenantFilter) could not be found"

Modules/CIPPCore/Public/Get-CippKeyVaultSecret.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function Get-CippKeyVaultSecret {
5555

5656
for ($i = 0; $i -lt $maxRetries; $i++) {
5757
try {
58-
$response = Invoke-RestMethod -Uri $uri -Headers @{
58+
$response = Invoke-CIPPRestMethod -Uri $uri -Headers @{
5959
Authorization = "Bearer $token"
6060
} -Method Get -ErrorAction Stop
6161
break

Modules/CIPPCore/Public/Get-TenantIdFromSubscriptionId.ps1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ function Get-TenantIdFromSubscriptionId {
66

77
# Full credit goes to Jos Lieben
88
# https://www.lieben.nu/liebensraum/2020/08/get-tenant-id-using-azure-subscription-id/
9-
10-
try {
11-
Invoke-WebRequest -UseBasicParsing -Uri "https://management.azure.com/subscriptions/$($SubscriptionId)`?api-version=2015-01-01" -ErrorAction Stop
12-
} catch {
13-
# The error response contains the WWW-Authenticate header with the tenant ID
14-
$response = $_.Exception.Response
15-
}
16-
17-
# Extract tenant ID from WWW-Authenticate header
18-
$authHeader = $response.Headers.GetValues("WWW-Authenticate")[0]
19-
9+
10+
# An unauthenticated request to ARM returns 401 with a WWW-Authenticate
11+
# header that embeds the tenant ID. SkipHttpErrorCheck keeps the response
12+
# flowing so we can read the header off the result.
13+
$null = Invoke-CIPPRestMethod -Uri "https://management.azure.com/subscriptions/$($SubscriptionId)`?api-version=2015-01-01" -Method Get -SkipHttpErrorCheck -ResponseHeadersVariable 'AuthResponseHeaders' -ErrorAction SilentlyContinue
14+
15+
$authHeaderValue = $AuthResponseHeaders['WWW-Authenticate']
16+
if ($authHeaderValue -is [array]) { $authHeaderValue = $authHeaderValue[0] }
17+
2018
# Use regex to extract the tenant ID
21-
if ($authHeader -match "login\.windows\.net\/([0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})") {
19+
if ($authHeaderValue -match 'login\.windows\.net\/([0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})') {
2220
return $matches[1]
2321
}
24-
22+
2523
return $null
2624
}

Modules/CIPPCore/Public/GraphHelper/Get-ClassicAPIToken.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Get-ClassicAPIToken($tenantID, $Resource) {
1919
}
2020
try {
2121
if (!$script:classictoken) { $script:classictoken = [HashTable]::Synchronized(@{}) }
22-
$script:classictoken.$TokenKey = Invoke-RestMethod $uri -Body $body -ContentType 'application/x-www-form-urlencoded' -ErrorAction SilentlyContinue -Method post
22+
$script:classictoken.$TokenKey = Invoke-CIPPRestMethod -Uri $uri -Body $body -ContentType 'application/x-www-form-urlencoded' -ErrorAction SilentlyContinue -Method post
2323
return $script:classictoken.$TokenKey
2424
} catch {
2525
# Track consecutive Graph API failures

Modules/CIPPCore/Public/GraphHelper/Get-GraphTokenFromCert.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function Get-GraphTokenFromCert {
109109
}
110110

111111
try {
112-
return Invoke-RestMethod @PostSplat
112+
return Invoke-CIPPRestMethod @PostSplat
113113
} catch {
114114
Write-Error $_
115115
}

0 commit comments

Comments
 (0)