-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
73fbde7
commit a920cf6
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/Azure.Functions.Cli/Actions/AzureActions/ListFunctionsActions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Functions.Cli.Arm; | ||
using Colors.Net; | ||
using static Azure.Functions.Cli.Common.OutputTheme; | ||
using Azure.Functions.Cli.Helpers; | ||
using System.Net.Http; | ||
using Azure.Functions.Cli.Common; | ||
using Azure.Functions.Cli.Interfaces; | ||
using Azure.Functions.Cli.Arm.Models; | ||
|
||
namespace Azure.Functions.Cli.Actions.AzureActions | ||
{ | ||
[Action(Name = "list-functions", Context = Context.Azure, SubContext = Context.FunctionApp, HelpText = "List functions in a given function app on azure.")] | ||
internal class ListFunctionsActions : BaseFunctionAppAction | ||
{ | ||
private readonly ISettings _settings; | ||
|
||
public ListFunctionsActions(IArmManager armManager, ISettings settings) : base(armManager) | ||
{ | ||
_settings = settings; | ||
} | ||
|
||
public override async Task RunAsync() | ||
{ | ||
var functionApp = await _armManager.GetFunctionAppAsync(FunctionAppName); | ||
if (functionApp != null) | ||
{ | ||
await RetryHelper.Retry(async () => | ||
{ | ||
using (var client = new HttpClient() { BaseAddress = new Uri($"https://{functionApp.ScmUri}") }) | ||
{ | ||
client.DefaultRequestHeaders.Authorization = await _armManager.GetAuthenticationHeader(_settings.CurrentSubscription); | ||
|
||
var response = await client.GetAsync(new Uri("api/functions", UriKind.Relative)); | ||
|
||
if (!response.IsSuccessStatusCode) | ||
{ | ||
throw new CliException($"Error trying to retrieve list of functions ({response.StatusCode})."); | ||
} | ||
|
||
var functions = await response.Content.ReadAsAsync<IEnumerable<FunctionInfo>>(); | ||
|
||
ColoredConsole.WriteLine(TitleColor($"Functions in {FunctionAppName}:")); | ||
foreach (var function in functions) | ||
{ | ||
var trigger = function | ||
.Config?["bindings"] | ||
?.FirstOrDefault(o => o["type"]?.ToString().IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) != -1) | ||
?["type"]; | ||
|
||
trigger = trigger ?? "No Trigger Found"; | ||
|
||
ColoredConsole.WriteLine($" {function.Name} - [{VerboseColor(trigger.ToString())}]"); | ||
} | ||
} | ||
}, 2); | ||
} | ||
else | ||
{ | ||
ColoredConsole.Error.WriteLine(ErrorColor($"Can't find function app by name {FunctionAppName}")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Azure.Functions.Cli.Arm.Models | ||
{ | ||
// https://github.com/projectkudu/kudu/blob/master/Kudu.Contracts/Functions/FunctionEnvelope.cs | ||
internal class FunctionInfo | ||
{ | ||
[JsonProperty(PropertyName = "name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty(PropertyName = "function_app_id")] | ||
public string FunctionAppId { get; set; } | ||
|
||
[JsonProperty(PropertyName = "script_root_path_href")] | ||
public Uri ScriptRootPathHref { get; set; } | ||
|
||
[JsonProperty(PropertyName = "script_href")] | ||
public Uri ScriptHref { get; set; } | ||
|
||
[JsonProperty(PropertyName = "config_href")] | ||
public Uri ConfigHref { get; set; } | ||
|
||
[JsonProperty(PropertyName = "secrets_file_href")] | ||
public Uri SecretsFileHref { get; set; } | ||
|
||
[JsonProperty(PropertyName = "href")] | ||
public Uri Href { get; set; } | ||
|
||
[JsonProperty(PropertyName = "config")] | ||
public JObject Config { get; set; } | ||
|
||
[JsonProperty(PropertyName = "files")] | ||
public IDictionary<string, string> Files { get; set; } | ||
|
||
[JsonProperty(PropertyName = "test_data")] | ||
public string TestData { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters