Unable to retrieve API keys for a Function App using ListWebAppFunctionKeysArgs

157 views Asked by At

How can I retrieve API keys for a function app in Azure using ListWebAppFunctionKeysArgs?

I have the following method:

public static Output<Dictionary<string, string>?> Get(string resourceGroupName, FunctionApp functionApp)
    {
        var output =
            Output.Tuple(functionApp.Name, functionApp.Name)
                  .Apply(async tuple => {

                      var current        = Pulumi.Azure.Core.GetClientConfig.InvokeAsync().Result;
                      var subscriptionId = current.SubscriptionId;
                      var appName        = tuple.Item1;

                      var httpClient = new HttpClient();
                      httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthToken.Value);

                      var url    = $"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}/functions?api-version=2022-03-01";
                      var result = await httpClient.GetAsync(url);

                      if (!result.IsSuccessStatusCode) throw new Exception($"Error: Failed to retrive Azure function names from {appName}");

                      var json = await result.Content.ReadAsStringAsync();
                      var root = JsonConvert.DeserializeObject<JsonSupport.AzureFunctionItems.Root>(json);
                      var items = root.value.Select(async v => {

                          var data = await ListWebAppFunctionKeys.InvokeAsync(new ListWebAppFunctionKeysArgs {
                              Name = appName,
                              FunctionName = v.properties.name,
                              ResourceGroupName = resourceGroupName
                          });

                          return data.Properties;
                      });
                      
                      var data = items.SelectMany(v => v.Result).ToList();
                      return new Dictionary<string, string>(data);
                  });

        return output;
    }

Here's the code that I'm struggling with:

  var json = await result.Content.ReadAsStringAsync();
  var root = JsonConvert.DeserializeObject<JsonSupport.AzureFunctionItems.Root>(json);
  var items = root.value.Select(async v => {

      var data = await ListWebAppFunctionKeys.InvokeAsync(new ListWebAppFunctionKeysArgs {
          Name = appName,
          FunctionName = v.properties.name,
          ResourceGroupName = resourceGroupName
      });

      return data.Properties; // Property values are null
  });

Here's the result:

enter image description here

In conclusion, how do I acquire API keys for a function app?

0

There are 0 answers