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

后端 未结 5 1271
伪装坚强ぢ
伪装坚强ぢ 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:21

    Nuget: Microsoft.Azure.Management.Fluent API can now manage the keys:

    using Microsoft.Azure.Management.AppService.Fluent;
        
    var functionApp = AzureInstance.AppServices.FunctionApps.GetByResourceGroup(resourceGroupName, functionAppName);
    foreach (var function in functionApp.ListFunctions())
    {
        var functionName = function.Name.Split('/')[1];
        var functionKeys = functionApp.ListFunctionKeys(functionName);
    
        functionKeys.TryGetValue(keyName, out string functionKey);
        dict.Add(functionName, functionKey);
    
    }
    

    you can also set new keys: (pass null as secret for auto-generated key)

    foreach (var function in functionApp.ListFunctions())
    {
        var functionName = function.Name.Split('/')[1];
        var nameValue = functionApp.AddFunctionKey(functionName, keyName,null);
    }
    

    Caveat: To make this work in production, the FunctionApp Identity must have the RBAC Owner Role of the Function App. This is set on the Access Control(IAM) Blade.

提交回复
热议问题