listKeys for Azure功能应用

时间:2017-12-27 01:36:21

标签: azure azure-functions azure-cli

如何使用listKeys ARM功能列出azure功能应用的键?

我的模板:

az group deployment create -g my-rg --template-file ./arm.json --mode incremental

然后运行:

No route registered for '/api/functions/my-function/listkeys?api-version=2016-08-01'

错误:

id

2 个答案:

答案 0 :(得分:4)

尝试以下模板。

  "outputs": {
    "FunctionAppName": {
        "type": "string",
        "value": "[parameters('functionName')]"
    },
    "Key": {
        "type": "string",
        "value": "[listsecrets(resourceId('Microsoft.Web/sites/functions', parameters('existingFunctionAppName'), parameters('functionName')),'2015-08-01').key]"
    },        
    "Url": {
        "type": "string",
        "value": "[listsecrets(resourceId('Microsoft.Web/sites/functions', parameters('existingFunctionAppName'), parameters('functionName')),'2015-08-01').trigger_url]"
    }        
}

有关此问题的详情,请参阅此question

您也可以使用Function App Api列出此内容。

GET /admin/functions/{functionname}/keys

如果使用bash shell,则可以使用以下示例。

TENANT=""
CLIENT_ID=""
CLIENT_SECRET=""
SUBSCRIPTION_ID=""
RESOURCE_GROUP="shuiapp"
FUNCTION_APP_NAME="shuifunction"
API_URL="https://$FUNCTION_APP_NAME.scm.azurewebsites.net/api/functions/admin/token"
SITE_URL="https://$FUNCTION_APP_NAME.azurewebsites.net/admin/functions/HttpTriggerPowerShell1/keys"

### Grab a fresh bearer access token.
ACCESS_TOKEN=$(curl -s -X POST -F grant_type=client_credentials -F resource=https://management.azure.com/ -F client_id=$CLIENT_ID -F client_secret=$CLIENT_SECRET https://login.microsoftonline.com/$TENANT/oauth2/token | jq '.access_token' -r)

### Grab the publish data for the Funciton App and output it to an XML file.
PUBLISH_DATA=$(curl -s -X POST -H "Content-Length: 0" -H "Authorization: Bearer $ACCESS_TOKEN" https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Web/sites/$FUNCTION_APP_NAME/publishxml?api-version=2016-08-01)
echo $PUBLISH_DATA > publish_data.xml

### Grab the Kudu username and password from the publish data XML file.
USER_NAME=$(xmlstarlet sel -t -v "//publishProfile[@profileName='$FUNCTION_APP_NAME - Web Deploy']/@userName" publish_data.xml)
USER_PASSWORD=$(xmlstarlet sel -t -v "//publishProfile[@profileName='$FUNCTION_APP_NAME - Web Deploy']/@userPWD" publish_data.xml)

### Generate a JWT that can be used with the Functions Key API.
JWT=$(curl -s -X GET -u $USER_NAME:$USER_PASSWORD $API_URL | tr -d '"')

### Grab the '_master' key from the Functions Key API.
KEY=$(curl -s -X GET -H "Authorization: Bearer $JWT" $SITE_URL | jq -r '.value')

答案 1 :(得分:0)

根据Azure Wiki上的公告,现在这种检索密钥的方法似乎是一个问题。

我很幸运使用脚本化版本,该版本基于类似于以下的调用构建:

az rest --method post --uri "/subscriptions/%subscriptionId%/resourceGroups/%resourceGroup%/providers/Microsoft.Web/sites/%webAppName%/host/default/listKeys?api-version=2018-11-01" --query functionKeys.default --output tsv

我从中获得此信息的原始博客帖子是here