Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#398 from johnduprey/dev
Browse files Browse the repository at this point in the history
API updates
  • Loading branch information
KelvinTegelaar authored Jul 31, 2023
2 parents 5c89831 + 564c0b0 commit c0fed11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions ExecBackendURLs/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ using namespace System.Net
param($Request, $TriggerMetadata)

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

$Subscription = ($ENV:WEBSITE_OWNER_NAME).split('+') | Select-Object -First 1
$SWAName = $ENV:Website_SITE_NAME -replace "cipp", "CIPP-SWA-"
$SWAName = $ENV:Website_SITE_NAME -replace 'cipp', 'CIPP-SWA-'
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
Write-Host 'PowerShell HTTP trigger function processed a request.'

$results = [PSCustomObject]@{
ResourceGroup = "https://portal.azure.com/#@Go/resource/subscriptions/$Subscription/resourceGroups/$ENV:Website_Resource_Group/overview"
Expand All @@ -19,10 +19,14 @@ $results = [PSCustomObject]@{
FunctionDeployment = "https://portal.azure.com/#@Go/resource/subscriptions/$Subscription/resourceGroups/$ENV:Website_Resource_Group/providers/Microsoft.Web/sites/$($ENV:WEBSITE_SITE_NAME)/vstscd"
SWADomains = "https://portal.azure.com/#@Go/resource/subscriptions/$Subscription/resourceGroups/$ENV:Website_Resource_Group/providers/Microsoft.Web/staticSites/$SWAName/customDomains"
SWARoles = "https://portal.azure.com/#@Go/resource/subscriptions/$Subscription/resourceGroups/$ENV:Website_Resource_Group/providers/Microsoft.Web/staticSites/$SWAName/Roles"
Subscription = $Subscription
RGName = $ENV:Website_Resource_Group
FunctionName = $ENV:WEBSITE_SITE_NAME
SWAName = $SWAName
}


$body = @{Results = $Results }
$body = @{Results = $Results }

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Expand Down
8 changes: 4 additions & 4 deletions Modules/CIPPCore/Public/New-CIPPAPIConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function New-CIPPAPIConfig {

try {
if ($currentapp) {
$APIApp = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/applications(appid='$($currentapp)')" -NoAuthCheck $true
$APIApp = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/applications(appid='$($currentapp)')" -NoAuthCheck $true
}
else {
$CreateBody = @"
Expand All @@ -32,7 +32,7 @@ function New-CIPPAPIConfig {
Write-Host "Removing all old passwords"
$RemovePasswords = New-GraphPOSTRequest -type Patch -uri "https://graph.microsoft.com/v1.0/applications/$($APIApp.id)/" -body '{"passwordCredentials":[]}' -NoAuthCheck $true
$passwordDate = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
$APIPassword = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/applications/$($APIApp.id)/addPassword" -NoAuthCheck $true -type POST -body "{`"passwordCredential`":{`"displayName`":`"Generated by API Setup`",`"startDateTime`":`"$passwordDate`",`"endDateTime`":`"2033-07-20T12:47:59.217Z`"}}"
$APIPassword = New-GraphPOSTRequest -uri "https://graph.microsoft.com/v1.0/applications/$($APIApp.id)/addPassword" -NoAuthCheck $true -type POST -body "{`"passwordCredential`":{`"displayName`":`"Generated by API Setup`"}}"
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant 'None '-message "Reset CIPP API Password." -Sev "info"
}
else {
Expand All @@ -58,13 +58,13 @@ function New-CIPPAPIConfig {
ApplicationSecret = $APIPassword.secretText
Results = "API Enabled. Your API URL is https://$($ENV:Website_hostname). Your Application ID is $($APIApp.AppId) and your Application Secret is $($APIPassword.secretText) - Copy these keys, they are only shown once."
}

}
catch {
Write-LogMessage -user $ExecutingUser -API $APINAME -tenant 'None' -message "Failed to setup CIPP-API Access: $($_.Exception.Message) Linenumber: $($_.InvocationInfo.ScriptLineNumber)" -Sev "Error"
return @{
Results = " but could not set API configuration: $($_.Exception.Message)"
}

}
}

0 comments on commit c0fed11

Please sign in to comment.