Skip to content

Commit

Permalink
Add Ability to specify port for Gui command (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfs authored May 3, 2023
1 parent 8f3ee69 commit b0059c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Cli/AttackSurfaceAnalyzerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,21 @@ private static ASA_ERROR RunGuiCommand(GuiCommandOptions opts)
}
}
}
var url = $"http://localhost:{opts.Port}";

var host = server.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseWebRoot(webRoot);
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls(url);
})
.Build();

if (!opts.NoLaunch)
{
((Action)(async () =>
{
await Task.Run(() => SleepAndOpenBrowser(1500)).ConfigureAwait(false);
await Task.Run(() => SleepAndOpenBrowser(1500, url)).ConfigureAwait(false);
}))();
}

Expand All @@ -490,14 +492,12 @@ private static ASA_ERROR RunGuiCommand(GuiCommandOptions opts)
return ASA_ERROR.NONE;
}

private static void SleepAndOpenBrowser(int sleep)
private static void SleepAndOpenBrowser(int sleep, string url)
{
Thread.Sleep(sleep);
AsaHelpers.OpenBrowser(new System.Uri("http://localhost:5000")); /*DevSkim: ignore DS137138*/
AsaHelpers.OpenBrowser(new System.Uri(url));
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2241:Provide correct arguments to formatting methods", Justification = "<Pending>")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "<Pending>")]
private static ASA_ERROR RunConfigCommand(ConfigCommandOptions opts)
{
if (opts.ResetDatabase)
Expand Down
3 changes: 3 additions & 0 deletions Lib/Objects/CommandOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ public class GuiCommandOptions : CommandOptions
{
[Option(HelpText = "Disable launching a browser after gui starts.")]
public bool NoLaunch { get; set; }

[Option(HelpText = "Port to listen on.", Default = 5000)]
public int Port { get; set; } = 5000;
}

[Verb("guide", HelpText = "Gather and Analyze metrics using a combination of Collectors and Monitors.")]
Expand Down

0 comments on commit b0059c4

Please sign in to comment.