c63fb1c4a6
Add 33 new management message records, ManagementActor handlers, and CLI commands to close all functionality gaps between the Central UI and the Management CLI. New capabilities include: - Template member CRUD (attributes, alarms, scripts, compositions) - Shared script CRUD - Database connection definition CRUD - Inbound API method CRUD - LDAP scope rule management - API key enable/disable - Area update - Remote event log and parked message queries - Missing get/update commands for templates, sites, instances, data connections, external systems, notifications, and SMTP config Includes 12 new ManagementActor unit tests covering authorization, happy-path queries, and error handling. Updates CLI README and component design documents (Component-CLI.md, Component-ManagementService.md).
143 lines
6.4 KiB
C#
143 lines
6.4 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ScadaLink.Commons.Messages.Management;
|
|
|
|
namespace ScadaLink.CLI.Commands;
|
|
|
|
public static class DataConnectionCommands
|
|
{
|
|
public static Command Build(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var command = new Command("data-connection") { Description = "Manage data connections" };
|
|
|
|
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(BuildAssign(contactPointsOption, formatOption));
|
|
command.Add(BuildUnassign(contactPointsOption, formatOption));
|
|
|
|
return command;
|
|
}
|
|
|
|
private static Command BuildGet(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Data connection ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get a data connection by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new GetDataConnectionCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUpdate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Data connection ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "Connection name", Required = true };
|
|
var protocolOption = new Option<string>("--protocol") { Description = "Protocol", Required = true };
|
|
var configOption = new Option<string?>("--configuration") { Description = "Configuration JSON" };
|
|
|
|
var cmd = new Command("update") { Description = "Update a data connection" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(protocolOption);
|
|
cmd.Add(configOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var name = result.GetValue(nameOption)!;
|
|
var protocol = result.GetValue(protocolOption)!;
|
|
var config = result.GetValue(configOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new UpdateDataConnectionCommand(id, name, protocol, config));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUnassign(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--assignment-id") { Description = "Assignment ID", Required = true };
|
|
var cmd = new Command("unassign") { Description = "Unassign a data connection from a site" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new UnassignDataConnectionFromSiteCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildList(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var cmd = new Command("list") { Description = "List all data connections" };
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new ListDataConnectionsCommand());
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildCreate(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var nameOption = new Option<string>("--name") { Description = "Connection name", Required = true };
|
|
var protocolOption = new Option<string>("--protocol") { Description = "Protocol (e.g. OpcUa)", Required = true };
|
|
var configOption = new Option<string?>("--configuration") { Description = "Connection configuration JSON" };
|
|
|
|
var cmd = new Command("create") { Description = "Create a new data connection" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(protocolOption);
|
|
cmd.Add(configOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var protocol = result.GetValue(protocolOption)!;
|
|
var config = result.GetValue(configOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new CreateDataConnectionCommand(name, protocol, config));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDelete(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Data connection ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete a data connection" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption, new DeleteDataConnectionCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildAssign(Option<string> contactPointsOption, Option<string> formatOption)
|
|
{
|
|
var connectionIdOption = new Option<int>("--connection-id") { Description = "Data connection ID", Required = true };
|
|
var siteIdOption = new Option<int>("--site-id") { Description = "Site ID", Required = true };
|
|
|
|
var cmd = new Command("assign") { Description = "Assign a data connection to a site" };
|
|
cmd.Add(connectionIdOption);
|
|
cmd.Add(siteIdOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var connectionId = result.GetValue(connectionIdOption);
|
|
var siteId = result.GetValue(siteIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, contactPointsOption, formatOption,
|
|
new AssignDataConnectionToSiteCommand(connectionId, siteId));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|