Add SiteReplicationActor (runs on every site node) to replicate deployed configs and store-and-forward buffer operations to the standby peer via cluster member discovery and fire-and-forget Tell. Wire ReplicationService handler and pass replication actor to DeploymentManagerActor singleton. Fix 5 pre-existing ConfigurationDatabase test failures: RowVersion NOT NULL on SQLite, stale migration name assertion, and seed data count mismatch.
232 lines
11 KiB
C#
232 lines
11 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ScadaLink.Commons.Messages.Management;
|
|
|
|
namespace ScadaLink.CLI.Commands;
|
|
|
|
public static class ExternalSystemCommands
|
|
{
|
|
public static Command Build(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var command = new Command("external-system") { Description = "Manage external systems" };
|
|
|
|
command.Add(BuildList(contactPointsOption, formatOption));
|
|
command.Add(BuildGet(contactPointsOption, formatOption));
|
|
command.Add(BuildCreate(contactPointsOption, formatOption));
|
|
command.Add(BuildUpdate(contactPointsOption, formatOption));
|
|
command.Add(BuildDelete(contactPointsOption, formatOption));
|
|
command.Add(BuildMethodGroup(contactPointsOption, formatOption));
|
|
|
|
return command;
|
|
}
|
|
|
|
private static Command BuildGet(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "External system ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get an external system by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new GetExternalSystemCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUpdate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "External system ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "System name", Required = true };
|
|
var urlOption = new Option<string>("--endpoint-url") { Description = "Endpoint URL", Required = true };
|
|
var authTypeOption = new Option<string>("--auth-type") { Description = "Auth type", Required = true };
|
|
var authConfigOption = new Option<string?>("--auth-config") { Description = "Auth configuration JSON" };
|
|
|
|
var cmd = new Command("update") { Description = "Update an external system" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(urlOption);
|
|
cmd.Add(authTypeOption);
|
|
cmd.Add(authConfigOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var name = result.GetValue(nameOption)!;
|
|
var url = result.GetValue(urlOption)!;
|
|
var authType = result.GetValue(authTypeOption)!;
|
|
var authConfig = result.GetValue(authConfigOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new UpdateExternalSystemCommand(id, name, url, authType, authConfig));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildList(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var cmd = new Command("list") { Description = "List all external systems" };
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new ListExternalSystemsCommand());
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildCreate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var nameOption = new Option<string>("--name") { Description = "System name", Required = true };
|
|
var urlOption = new Option<string>("--endpoint-url") { Description = "Endpoint URL", Required = true };
|
|
var authTypeOption = new Option<string>("--auth-type") { Description = "Auth type (ApiKey, BasicAuth)", Required = true };
|
|
var authConfigOption = new Option<string?>("--auth-config") { Description = "Auth configuration JSON" };
|
|
|
|
var cmd = new Command("create") { Description = "Create an external system" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(urlOption);
|
|
cmd.Add(authTypeOption);
|
|
cmd.Add(authConfigOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var url = result.GetValue(urlOption)!;
|
|
var authType = result.GetValue(authTypeOption)!;
|
|
var authConfig = result.GetValue(authConfigOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new CreateExternalSystemCommand(name, url, authType, authConfig));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDelete(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "External system ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete an external system" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new DeleteExternalSystemCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
// ── Method subcommands ──
|
|
|
|
private static Command BuildMethodGroup(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var group = new Command("method") { Description = "Manage external system methods" };
|
|
group.Add(BuildMethodList(contactPointsOption, formatOption));
|
|
group.Add(BuildMethodGet(contactPointsOption, formatOption));
|
|
group.Add(BuildMethodCreate(contactPointsOption, formatOption));
|
|
group.Add(BuildMethodUpdate(contactPointsOption, formatOption));
|
|
group.Add(BuildMethodDelete(contactPointsOption, formatOption));
|
|
return group;
|
|
}
|
|
|
|
private static Command BuildMethodList(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var sysIdOption = new Option<int>("--external-system-id") { Description = "External system ID", Required = true };
|
|
var cmd = new Command("list") { Description = "List methods for an external system" };
|
|
cmd.Add(sysIdOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new ListExternalSystemMethodsCommand(result.GetValue(sysIdOption)));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildMethodGet(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Method ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get an external system method by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new GetExternalSystemMethodCommand(result.GetValue(idOption)));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildMethodCreate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var sysIdOption = new Option<int>("--external-system-id") { Description = "External system ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "Method name", Required = true };
|
|
var httpMethodOption = new Option<string>("--http-method") { Description = "HTTP method (GET, POST, PUT, DELETE)", Required = true };
|
|
var pathOption = new Option<string>("--path") { Description = "URL path (e.g. /api/Add)", Required = true };
|
|
var paramsOption = new Option<string?>("--params") { Description = "Parameter definitions JSON" };
|
|
var returnOption = new Option<string?>("--return") { Description = "Return definition JSON" };
|
|
|
|
var cmd = new Command("create") { Description = "Create an external system method" };
|
|
cmd.Add(sysIdOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(httpMethodOption);
|
|
cmd.Add(pathOption);
|
|
cmd.Add(paramsOption);
|
|
cmd.Add(returnOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new CreateExternalSystemMethodCommand(
|
|
result.GetValue(sysIdOption),
|
|
result.GetValue(nameOption)!,
|
|
result.GetValue(httpMethodOption)!,
|
|
result.GetValue(pathOption)!,
|
|
result.GetValue(paramsOption),
|
|
result.GetValue(returnOption)));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildMethodUpdate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Method ID", Required = true };
|
|
var nameOption = new Option<string?>("--name") { Description = "Method name" };
|
|
var httpMethodOption = new Option<string?>("--http-method") { Description = "HTTP method" };
|
|
var pathOption = new Option<string?>("--path") { Description = "URL path" };
|
|
var paramsOption = new Option<string?>("--params") { Description = "Parameter definitions JSON" };
|
|
var returnOption = new Option<string?>("--return") { Description = "Return definition JSON" };
|
|
|
|
var cmd = new Command("update") { Description = "Update an external system method" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(httpMethodOption);
|
|
cmd.Add(pathOption);
|
|
cmd.Add(paramsOption);
|
|
cmd.Add(returnOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new UpdateExternalSystemMethodCommand(
|
|
result.GetValue(idOption),
|
|
result.GetValue(nameOption),
|
|
result.GetValue(httpMethodOption),
|
|
result.GetValue(pathOption),
|
|
result.GetValue(paramsOption),
|
|
result.GetValue(returnOption)));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildMethodDelete(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Method ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete an external system method" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new DeleteExternalSystemMethodCommand(result.GetValue(idOption)));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|