e15aa0e430
The Flow Debugger design doc still described the pre-remediation shape: a
debug-stream subscription for the value-change entry, Deployer everywhere, an
unredacted inline trace copy and "~7 audit rows per call". Reconciled with what
shipped on this branch (Tasks 1-12):
- design D6 / §5.4 / §9 / §10: RequireFlowDebugger page policy with Deployer-only
execution (F3), the PullTraceEvents polling path with AttributeValueUpdate
fields 7/8 recorded as RESERVED and unconsumed (F12), the redacting + byte-
capped shared FlowTraceCollector (F1), route-time site scope (F2), the derived
client waits (F4), the 7-10 row estimate, the doubled central audit write per
routed call, and the inbound-row-after-the-run ordering.
- sitestream.proto: fields 7/8 marked reserved-but-populated, numbers not to be
reused (comment only; no regeneration needed).
- Component-InboundAPI: SkipBodyCapture on the RouteCall row (F11),
SchemaRefResolver's public visibility, WithSiteScope / SITE_SCOPE_DENIED (F2),
Replay's wider role set (F3).
- Component-CentralUI: page policy vs Deployer-only controls (F3), route-time
site scope (F2), client wait derivation (F4).
- "7-10 audit rows per call (3 of them trace-only)" everywhere the estimate is
quoted: the method form, both CLI --trace-all-calls help strings, the CLI
README, the ApiMethod entity doc, the manual migration script and the two
Flow Debugger plans.
- arch-review doc: new §7 Resolution listing F1-F13 with the fixing commit, plus
the tracking-store test race fixed alongside them (86451382).
Claude-Session: https://claude.ai/code/session_01NcMG6xXdsJbmD2wYAgkK29
140 lines
7.3 KiB
C#
140 lines
7.3 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
public static class ApiMethodCommands
|
|
{
|
|
/// <summary>
|
|
/// Builds the <c>api-method</c> CLI command group with subcommands for managing inbound API methods.
|
|
/// </summary>
|
|
/// <param name="urlOption">Global option for the management URL.</param>
|
|
/// <param name="formatOption">Global option for the output format.</param>
|
|
/// <param name="usernameOption">Global option for the authentication username.</param>
|
|
/// <param name="passwordOption">Global option for the authentication password.</param>
|
|
/// <returns>The configured <c>api-method</c> command with all subcommands registered.</returns>
|
|
public static Command Build(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var command = new Command("api-method") { Description = "Manage inbound API methods" };
|
|
|
|
command.Add(BuildList(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildGet(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildCreate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildUpdate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDelete(urlOption, formatOption, usernameOption, passwordOption));
|
|
|
|
return command;
|
|
}
|
|
|
|
private static Command BuildList(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var cmd = new Command("list") { Description = "List all API methods" };
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new ListApiMethodsCommand());
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildGet(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "API method ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get an API method by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new GetApiMethodCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildCreate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var nameOption = new Option<string>("--name") { Description = "Method name", Required = true };
|
|
var scriptOption = new Option<string>("--script") { Description = "Script code", Required = true };
|
|
var timeoutOption = new Option<int>("--timeout") { Description = "Timeout in seconds" };
|
|
timeoutOption.DefaultValueFactory = _ => 30;
|
|
var parametersOption = new Option<string?>("--parameters") { Description = "Parameter definitions JSON" };
|
|
var returnDefOption = new Option<string?>("--return-def") { Description = "Return type definition" };
|
|
var traceAllCallsOption = new Option<bool>("--trace-all-calls")
|
|
{
|
|
Description = "Trace every production call to this method for the Flow Debugger (adds 7-10 audit rows per call; low-volume integration methods only)"
|
|
};
|
|
|
|
var cmd = new Command("create") { Description = "Create an API method" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(scriptOption);
|
|
cmd.Add(timeoutOption);
|
|
cmd.Add(parametersOption);
|
|
cmd.Add(returnDefOption);
|
|
cmd.Add(traceAllCallsOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var script = result.GetValue(scriptOption)!;
|
|
var timeout = result.GetValue(timeoutOption);
|
|
var parameters = result.GetValue(parametersOption);
|
|
var returnDef = result.GetValue(returnDefOption);
|
|
var traceAllCalls = result.GetValue(traceAllCallsOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new CreateApiMethodCommand(name, script, timeout, parameters, returnDef, traceAllCalls));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUpdate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "API method ID", Required = true };
|
|
var scriptOption = new Option<string>("--script") { Description = "Script code", Required = true };
|
|
var timeoutOption = new Option<int>("--timeout") { Description = "Timeout in seconds" };
|
|
timeoutOption.DefaultValueFactory = _ => 30;
|
|
var parametersOption = new Option<string?>("--parameters") { Description = "Parameter definitions JSON" };
|
|
var returnDefOption = new Option<string?>("--return-def") { Description = "Return type definition" };
|
|
// bool? so an update that omits the flag leaves the stored value unchanged.
|
|
var traceAllCallsOption = new Option<bool?>("--trace-all-calls")
|
|
{
|
|
Description = "Trace every production call to this method for the Flow Debugger (true/false; omitted = unchanged; adds 7-10 audit rows per call)"
|
|
};
|
|
|
|
var cmd = new Command("update") { Description = "Update an API method" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(scriptOption);
|
|
cmd.Add(timeoutOption);
|
|
cmd.Add(parametersOption);
|
|
cmd.Add(returnDefOption);
|
|
cmd.Add(traceAllCallsOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var script = result.GetValue(scriptOption)!;
|
|
var timeout = result.GetValue(timeoutOption);
|
|
var parameters = result.GetValue(parametersOption);
|
|
var returnDef = result.GetValue(returnDefOption);
|
|
var traceAllCalls = result.GetValue(traceAllCallsOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new UpdateApiMethodCommand(id, script, timeout, parameters, returnDef, traceAllCalls));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDelete(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "API method ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete an API method" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new DeleteApiMethodCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|