in src/Cli/func/Kubernetes/KubernetesHelper.cs [297:384]
internal static async Task PrintFunctionsInfo(DeploymentV1Apps deployment, ServiceV1 service, IDictionary<string, string> funcKeys, TriggersPayload triggers, bool showServiceFqdn)
{
if (funcKeys?.Any() == false || triggers == null)
{
return;
}
var httpFunctions = triggers.FunctionsJson
.Where(b => b.Value["bindings"]?.Any(e => e?["type"].ToString().IndexOf("httpTrigger", StringComparison.OrdinalIgnoreCase) != -1) == true)
.Select(item => item.Key);
var localPort = NetworkHelpers.GetAvailablePort();
Process proxy = null;
try
{
proxy = await KubectlHelper.RunKubectlProxy(
deployment,
service.Spec.Ports.FirstOrDefault()?.Port ?? 80,
localPort);
string baseAddress;
if (showServiceFqdn)
{
baseAddress = $"{service.Metadata.Name}.{service.Metadata.Namespace}.svc.cluster.local";
}
else
{
baseAddress = await GetServiceIp(service);
}
var masterKey = funcKeys["host.master"];
if (httpFunctions?.Any() == true)
{
foreach (var functionName in httpFunctions)
{
var getFunctionAdminUri = $"http://127.0.0.1:{localPort}/admin/functions/{functionName}?code={masterKey}";
var httpResponseMessage = await GetHttpResponse(new HttpRequestMessage(HttpMethod.Get, getFunctionAdminUri), 20);
httpResponseMessage.EnsureSuccessStatusCode();
var responseContent = await httpResponseMessage.Content.ReadAsStringAsync();
var functionsInfo = JsonConvert.DeserializeObject<FunctionInfo>(responseContent);
var trigger = functionsInfo
.Config?["bindings"]
?.FirstOrDefault(o => o["type"]?.ToString().IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) != -1)
?["type"];
trigger = trigger ?? "No Trigger Found";
var showFunctionKey = true;
var authLevel = functionsInfo
.Config?["bindings"]
?.FirstOrDefault(o => !string.IsNullOrEmpty(o["authLevel"]?.ToString()))
?["authLevel"];
if (authLevel != null && authLevel.ToString().Equals("anonymous", StringComparison.OrdinalIgnoreCase))
{
showFunctionKey = false;
}
ColoredConsole.WriteLine($"\t{functionName} - [{VerboseColor(trigger.ToString())}]");
if (!string.IsNullOrEmpty(functionsInfo.InvokeUrlTemplate))
{
var url = new Uri(new Uri($"http://{baseAddress}"), new Uri(functionsInfo.InvokeUrlTemplate).PathAndQuery).ToString();
if (showFunctionKey)
{
ColoredConsole.WriteLine($"\tInvoke url: {VerboseColor($"{url}?code={funcKeys[$"functions.{functionName.ToLower()}.default"]}")}");
}
else
{
ColoredConsole.WriteLine($"\tInvoke url: {VerboseColor(url)}");
}
}
ColoredConsole.WriteLine();
}
}
}
finally
{
if (proxy != null && !proxy.HasExited)
{
proxy.Kill();
}
}
// Print the master key as well for the user
ColoredConsole.WriteLine($"\tMaster key: {VerboseColor($"{funcKeys["host.master"]}")}");
}