Skip to content

Commit b0059c4

Browse files
authored
Add Ability to specify port for Gui command (#693)
1 parent 8f3ee69 commit b0059c4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Cli/AttackSurfaceAnalyzerClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,21 @@ private static ASA_ERROR RunGuiCommand(GuiCommandOptions opts)
469469
}
470470
}
471471
}
472+
var url = $"http://localhost:{opts.Port}";
472473

473474
var host = server.ConfigureWebHostDefaults(webBuilder =>
474475
{
475476
webBuilder.UseWebRoot(webRoot);
476477
webBuilder.UseStartup<Startup>();
478+
webBuilder.UseUrls(url);
477479
})
478480
.Build();
479481

480482
if (!opts.NoLaunch)
481483
{
482484
((Action)(async () =>
483485
{
484-
await Task.Run(() => SleepAndOpenBrowser(1500)).ConfigureAwait(false);
486+
await Task.Run(() => SleepAndOpenBrowser(1500, url)).ConfigureAwait(false);
485487
}))();
486488
}
487489

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

493-
private static void SleepAndOpenBrowser(int sleep)
495+
private static void SleepAndOpenBrowser(int sleep, string url)
494496
{
495497
Thread.Sleep(sleep);
496-
AsaHelpers.OpenBrowser(new System.Uri("http://localhost:5000")); /*DevSkim: ignore DS137138*/
498+
AsaHelpers.OpenBrowser(new System.Uri(url));
497499
}
498500

499-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2241:Provide correct arguments to formatting methods", Justification = "<Pending>")]
500-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "<Pending>")]
501501
private static ASA_ERROR RunConfigCommand(ConfigCommandOptions opts)
502502
{
503503
if (opts.ResetDatabase)

Lib/Objects/CommandOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ public class GuiCommandOptions : CommandOptions
270270
{
271271
[Option(HelpText = "Disable launching a browser after gui starts.")]
272272
public bool NoLaunch { get; set; }
273+
274+
[Option(HelpText = "Port to listen on.", Default = 5000)]
275+
public int Port { get; set; } = 5000;
273276
}
274277

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

0 commit comments

Comments
 (0)