Get Azure Function keys from an Azure Function at deployment time?

后端 未结 5 1340
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 14:41

I\'m sending an email in Azure Functions using the SendGrid bindings. As part of the contents of that email, I\'d like to include a link to one of the HTTP methods in the Azure

5条回答
  •  野的像风
    2021-02-06 15:18

    You can get master and function keys via HTTP using Kudu:

    Example (in Powershell):

    $RSGROUP="mygroup"
    $WEBAPPNAME="myfunctionsapp"
    $function="myfunction"
    
    $DeploymentUrl = Get-AzWebAppContainerContinuousDeploymentUrl -ResourceGroupName $RSGROUP -Name $WEBAPPNAME
    
    $userpass = $DeploymentUrl.split("@")[0].Replace("https://","")
    $kuduCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($userpass))
    
    $jwt = Invoke-RestMethod -Uri "https://$WEBAPPNAME.scm.azurewebsites.net/api/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $kuduCreds)} -Method GET
    
    $masterkey=(Invoke-RestMethod "https://$WEBAPPNAME.azurewebsites.net/admin/host/systemkeys/_master" -Headers @{Authorization="Bearer $jwt"}).value
    $functionkey=(Invoke-RestMethod "https://$WEBAPPNAME.azurewebsites.net/admin/functions/$function/keys" -Headers @{Authorization="Bearer $jwt"}).keys[0].value
    
    echo $masterkey
    echo $functionkey
    

提交回复
热议问题