Hi @Tiwari, Vivek K Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.
As you stated in the question, there are no libraries available to extract this information directly. The documentation on Obtaining the function access keys provides couple of approaches to achieve this. I have tested the following .Net code to extract the function name and the keys for it under a function app by calling the Azure CLI commands from the code
Updated code using the API endpoint
using System;
using System.Diagnostics;
using Azure.Identity;
using Azure.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ConsoleApp
{
internal class Program
{
static async Task Main(string[] args)
{
// Replace these values with your own
// Replace these values with your own
string resourceGroupName = "<resourcegroupname>";
string functionAppName = "<functionappname>";
// Create a new instance of DefaultAzureCredential
var credential = new DefaultAzureCredential();
//Read using the API
string subscriptionId = "<subscriptionID>";
string apiVersion = "2023-12-01";
var token = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { "https://management.azure.com/.default" }));
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token.Token);
//End point to list all functions under a function app
var url = $"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions?api-version={apiVersion}";
var response = await client.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();
var jsonDoc = JObject.Parse(content);
JToken apiResult = jsonDoc["value"];
//End point to obtain the Master Key of the hosting function app
url = $"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/host/default/listkeys?api-version={apiVersion}";
response = await client.PostAsync(url, null);
var masterKeys = await response.Content.ReadAsStringAsync();
jsonDoc = JObject.Parse(masterKeys);
JToken funcappKey = jsonDoc["masterKey"];
Console.WriteLine($"Funcation app master key is {funcappKey.ToString()}");
//var masterKey = functionAppKeys.MasterKey;
//Console.WriteLine(masterKey);
foreach (var funcs in apiResult)
{
var config = funcs["properties"]["config"];
string funcname = (config["name"]).ToString();
string bindingtype = config["bindings"][0]["type"].ToString();
Console.WriteLine("Function name is " + funcname + " and trigger type is " + bindingtype);
//End point to return the function keys
url = $"https://{functionAppName}.azurewebsites.net/admin/functions/{funcname}/keys";
client.DefaultRequestHeaders.Add("x-functions-key", funcappKey.ToString());
response = await client.GetAsync(url);
content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
}
The above code extracts the function name and the type of the Trigger associated with it from the returned result set and uses the name to extract the keys. Below is the sample output from the above code
Hoper this helps! Please let us know if you have any additional questions or need further assitance.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.