Skip to content

Commit bec3cbe

Browse files
committed
fix: sherweb tenant filtering
1 parent edc12dc commit bec3cbe

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

Modules/CIPPCore/Public/Entrypoints/Invoke-ListCSPsku.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ Function Invoke-ListCSPsku {
1414
Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1515
$TenantFilter = $Request.Query.tenantFilter
1616

17-
if ($Request.Query.currentSkuOnly) {
18-
$GraphRequest = Get-SherwebCurrentSubscription -TenantFilter $TenantFilter
19-
} else {
20-
$GraphRequest = Get-SherwebCatalog -TenantFilter $TenantFilter
17+
try {
18+
if ($Request.Query.currentSkuOnly) {
19+
$GraphRequest = Get-SherwebCurrentSubscription -TenantFilter $TenantFilter
20+
} else {
21+
$GraphRequest = Get-SherwebCatalog -TenantFilter $TenantFilter
22+
}
23+
} catch {
24+
$GraphRequest = [PSCustomObject]@{
25+
name = @(@{value = 'Error getting catalog' })
26+
sku = $_.Exception.Message
27+
}
2128
}
2229

23-
2430
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
2531
StatusCode = [HttpStatusCode]::OK
2632
Body = @($GraphRequest)

Modules/CippExtensions/Public/Sherweb/Get-SherwebCatalog.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ function Get-SherwebCatalog {
44
[string]$CustomerId,
55
[string]$TenantFilter
66
)
7+
78
if ($TenantFilter) {
8-
Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | ForEach-Object {
9-
Write-Host "Extracted customer id from tenant filter - It's $($_.IntegrationId)"
10-
$CustomerId = $_.IntegrationId
11-
}
9+
$TenantFilter = (Get-Tenants -TenantFilter $TenantFilter).customerId
10+
$CustomerId = Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | Select-Object -ExpandProperty IntegrationId
11+
}
12+
13+
if (![string]::IsNullOrEmpty($CustomerId)) {
14+
Write-Information "Getting catalog for $CustomerId"
15+
$AuthHeader = Get-SherwebAuthentication
16+
$SubscriptionsList = Invoke-RestMethod -Uri "https://api.sherweb.com/service-provider/v1/customer-catalogs/$CustomerId" -Method GET -Headers $AuthHeader
17+
return $SubscriptionsList.catalogItems
18+
} else {
19+
throw 'No Sherweb mapping found'
1220
}
13-
$AuthHeader = Get-SherwebAuthentication
14-
$SubscriptionsList = Invoke-RestMethod -Uri "https://api.sherweb.com/service-provider/v1/customer-catalogs/$CustomerId" -Method GET -Headers $AuthHeader
15-
return $SubscriptionsList.catalogItems
1621
}

Modules/CippExtensions/Public/Sherweb/Get-SherwebCurrentSubscription.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Get-SherwebCurrentSubscription {
1111
$CustomerId = Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | Select-Object -ExpandProperty IntegrationId
1212
}
1313

14+
Write-Information "Getting current subscription for $CustomerId"
1415
$AuthHeader = Get-SherwebAuthentication
1516
$Uri = "https://api.sherweb.com/service-provider/v1/billing/subscriptions/details?customerId=$CustomerId"
1617
$SubscriptionDetails = Invoke-RestMethod -Uri $Uri -Method GET -Headers $AuthHeader

Modules/CippExtensions/Public/Sherweb/Get-SherwebCustomerConfiguration.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ function Get-SherwebCustomerConfiguration {
55
[string]$TenantFilter
66
)
77
if ($TenantFilter) {
8-
Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | ForEach-Object {
9-
Write-Host "Extracted customer id from tenant filter - It's $($_.IntegrationId)"
10-
$CustomerId = $_.IntegrationId
11-
}
8+
$TenantFilter = (Get-Tenants -TenantFilter $TenantFilter).customerId
9+
$CustomerId = Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | Select-Object -ExpandProperty IntegrationId
1210
}
1311
$AuthHeader = Get-SherwebAuthentication
1412
$Uri = "https://api.sherweb.com/service-provider/v1/customers/$($CustomerId)/platforms-configurations/"

Modules/CippExtensions/Public/Sherweb/Remove-SherwebSubscription.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ function Remove-SherwebSubscription {
77
[string]$TenantFilter
88
)
99
if ($TenantFilter) {
10-
Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | ForEach-Object {
11-
Write-Host "Extracted customer id from tenant filter - It's $($_.IntegrationId)"
12-
$CustomerId = $_.IntegrationId
13-
}
10+
$TenantFilter = (Get-Tenants -TenantFilter $TenantFilter).customerId
11+
$CustomerId = Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | Select-Object -ExpandProperty IntegrationId
1412
}
1513
$AuthHeader = Get-SherwebAuthentication
1614
$Body = ConvertTo-Json -Depth 10 -InputObject @{

Modules/CippExtensions/Public/Sherweb/Set-SherwebSubscription.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ function Set-SherwebSubscription {
1010
[string]$TenantFilter
1111
)
1212
if ($TenantFilter) {
13-
Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | ForEach-Object {
14-
Write-Host "Extracted customer id from tenant filter - It's $($_.IntegrationId)"
15-
$CustomerId = $_.IntegrationId
16-
}
13+
$TenantFilter = (Get-Tenants -TenantFilter $TenantFilter).customerId
14+
$CustomerId = Get-ExtensionMapping -Extension 'Sherweb' | Where-Object { $_.RowKey -eq $TenantFilter } | Select-Object -ExpandProperty IntegrationId
1715
}
1816
$AuthHeader = Get-SherwebAuthentication
1917
$ExistingSubscription = Get-SherwebCurrentSubscription -CustomerId $CustomerId -SKU $SKU

0 commit comments

Comments
 (0)