Skip to content

Commit

Permalink
Add ability to buy licenses too
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Dec 23, 2024
1 parent 8b6f84c commit 393968b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ExecCSPLicense.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using namespace System.Net

Function Invoke-ExecCSPLicense {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
Tenant.Directory.Read
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'


# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'

# Interact with query parameters or the body of the request.
$TenantFilter = $Request.body.TenantFilter
$Action = $Request.body.Action

try {
if ($Action -eq 'Add') {
$GraphRequest = Set-SherwebSubscription -tenantFilter $TenantFilter -SKU $Request.body.sku -add $Request.body.Add
}

if ($Action -eq 'Remove') {
$GraphRequest = Set-SherwebSubscription -tenantFilter $TenantFilter -SKU $Request.body.sku -remove $Request.body.Remove
}

if ($Action -eq 'NewSub') {
$GraphRequest = Set-SherwebSubscription -tenantFilter $TenantFilter -SKU $Request.body.sku -Quantity $Request.body.Quantity
}
$Message = 'License change executed successfully.'
} catch {
$Message = "Failed to execute license change. Error: $_"
}
#If #GraphRequest is a GUID, the subscription was edited succesfully, and return that its done.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $Message
}) -Clobber

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Set-SherwebSubscription {
}
}
$AuthHeader = Get-SherwebAuthentication
$ExistingSubscription = Get-CurrentSherwebSubscription -ClientId $ClientId -ClientSecret $ClientSecret -SubscriptionKey $SubscriptionKey -CustomerId $CustomerId -SKU $SKU
$ExistingSubscription = Get-SherwebCurrentSubscription -CustomerId $CustomerId -SKU $SKU

if (-not $ExistingSubscription) {
if ($Add -or $Remove) {
Expand Down

0 comments on commit 393968b

Please sign in to comment.