Created
July 19, 2018 10:05
-
-
Save RichieBzzzt/42961de995e2eff8fb9b61fcfcdd0918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[parameter(Mandatory = $true)] [string]$functionName, | |
[parameter(Mandatory = $true)] [string]$appName, | |
[parameter(Mandatory = $true)] [string]$resourceGroup | |
) | |
function Get-KuduCredentials($appName, $resourceGroup) { | |
[xml]$x = Get-AzureRmWebAppPublishingProfile -ResourceGroupName $resourceGroup -Name $appName | |
$user = $x.publishData.publishProfile[1].userName.Split("\") | Select-Object -Last 1 | |
$pass = $x.publishData.publishProfile[1].userPWD | |
$pair = "$($user):$($pass)" | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
return $encodedCreds | |
} | |
function Get-FunctionKey([string]$appName, [string]$functionName, [string]$encodedCreds) { | |
$jwt = Invoke-RestMethod -Uri "https://$($appName).scm.azurewebsites.net/api/functions/admin/token" -Headers @{Authorization = ("Basic {0}" -f $encodedCreds)} -Method GET | |
$keys = Invoke-RestMethod -Method GET -Headers @{Authorization = ("Bearer {0}" -f $jwt)} ` | |
-Uri "https://$appName.azurewebsites.net/admin/functions/$functionName/keys/adf" | |
$code = $keys.value | |
return $code | |
} | |
if ([string]::IsNullOrEmpty($(Get-AzureRmContext).Account)) { | |
Login-AzureRmAccount | |
} | |
Function Invoke-AzureFunction { | |
[parameter(Mandatory = $true)] [string]$functionName, | |
[parameter(Mandatory = $true)] [string]$appName, | |
[parameter(Mandatory = $true)] [string]$code | |
try { | |
$funcUri = "https://$($appName).azurewebsites.net/api/$($functionName)?code=$($code)" | |
Write-Host $funcUri | |
Invoke-RestMethod -Method POST -Uri $funcUri | |
} | |
catch { | |
throw $_.Exception | |
} | |
} | |
$kuduCreds = Get-KuduCredentials $appName $resourceGroup | |
$code = Get-FunctionKey $appName $functionName $kuduCreds | |
Invoke-AzureFunction $functionName $appName $code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment