refactor: allow simulator to connect to api through auth

This commit is contained in:
voltsrage
2026-06-22 20:43:21 +08:00
parent 7170b6efad
commit 518cc5b99a
5 changed files with 1228 additions and 6 deletions
@@ -7,13 +7,16 @@ public static class ReplayAllCommand
var dirArg = new Argument<DirectoryInfo>("directory", "Directory containing scenario JSON files");
var speedOpt = new Option<double>("--speed", () => 60);
var baseUrlOpt = new Option<string>("--base-url", () => "http://localhost:5270");
var usernameOpt = new Option<string>("--username", () => "physician.demo", "API login username");
var passwordOpt = new Option<string>("--password", () => "DemoPhysician1!", "API login password");
var command = new Command("replay-all", "Replay all scenarios in a directory")
{
dirArg, speedOpt, baseUrlOpt
dirArg, speedOpt, baseUrlOpt, usernameOpt, passwordOpt
};
command.SetHandler(async (DirectoryInfo dir, double speed, string baseUrl) =>
command.SetHandler(async (DirectoryInfo dir, double speed, string baseUrl,
string username, string password) =>
{
var files = dir.GetFiles("*.json")
.Where(f => f.Name != "schema.json")
@@ -30,6 +33,11 @@ public static class ReplayAllCommand
using var http = new HttpClient { BaseAddress = new Uri(baseUrl) };
var client = new VigilCareApiClient(http);
SimulatorConsole.Info($"Authenticating as {username}...");
await client.LoginAsync(username, password);
SimulatorConsole.Info("Authenticated.");
var engine = new ReplayEngine(client, poller: null);
var results = new List<ReplayResult>();
@@ -49,7 +57,7 @@ public static class ReplayAllCommand
}
SimulatorConsole.BatchSummary(results);
}, dirArg, speedOpt, baseUrlOpt);
}, dirArg, speedOpt, baseUrlOpt, usernameOpt, passwordOpt);
return command;
}