refactor(audit): consolidate query-param parsers; widen CLI export to multi-value
This commit is contained in:
@@ -6,6 +6,10 @@ namespace ScadaLink.CLI.Commands;
|
||||
/// <summary>
|
||||
/// Filter + destination arguments for an <c>audit export</c> invocation. Mirrors the
|
||||
/// Bundle B <c>GET /api/audit/export</c> parameters.
|
||||
/// <see cref="Channel"/>/<see cref="Kind"/>/<see cref="Status"/>/<see cref="Site"/>
|
||||
/// are multi-valued — each supplied value becomes a repeated query-string param so
|
||||
/// the server's multi-value <c>IN (…)</c> filter sees the full set, exactly like
|
||||
/// the <c>audit query</c> subcommand.
|
||||
/// </summary>
|
||||
public sealed class AuditExportArgs
|
||||
{
|
||||
@@ -13,10 +17,10 @@ public sealed class AuditExportArgs
|
||||
public string Until { get; set; } = string.Empty;
|
||||
public string Format { get; set; } = string.Empty;
|
||||
public string Output { get; set; } = string.Empty;
|
||||
public string? Channel { get; set; }
|
||||
public string? Kind { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? Site { get; set; }
|
||||
public string[] Channel { get; set; } = Array.Empty<string>();
|
||||
public string[] Kind { get; set; } = Array.Empty<string>();
|
||||
public string[] Status { get; set; } = Array.Empty<string>();
|
||||
public string[] Site { get; set; } = Array.Empty<string>();
|
||||
public string? Target { get; set; }
|
||||
public string? Actor { get; set; }
|
||||
}
|
||||
@@ -31,7 +35,11 @@ public static class AuditExportHelpers
|
||||
/// <summary>
|
||||
/// Builds the <c>?...</c> query string for <c>GET /api/audit/export</c>: the required
|
||||
/// time window + format, plus optional filters. Time-specs are resolved via
|
||||
/// <see cref="AuditQueryHelpers.ResolveTimeSpec"/>.
|
||||
/// <see cref="AuditQueryHelpers.ResolveTimeSpec"/>. The multi-valued
|
||||
/// <c>--channel</c>/<c>--kind</c>/<c>--status</c>/<c>--site</c> filters each emit ONE
|
||||
/// repeated query-string key per value (e.g. <c>channel=A&channel=B</c>) so the
|
||||
/// server's multi-value <c>IN (…)</c> filter receives the full set — mirroring
|
||||
/// <see cref="AuditQueryHelpers.BuildQueryString"/>.
|
||||
/// </summary>
|
||||
public static string BuildQueryString(AuditExportArgs args, DateTimeOffset now)
|
||||
{
|
||||
@@ -43,13 +51,21 @@ public static class AuditExportHelpers
|
||||
parts.Add($"{key}={Uri.EscapeDataString(value)}");
|
||||
}
|
||||
|
||||
void AddEach(string key, IReadOnlyList<string> values)
|
||||
{
|
||||
foreach (var value in values)
|
||||
{
|
||||
Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Add("fromUtc", AuditQueryHelpers.ResolveTimeSpec(args.Since, now).ToString("o", CultureInfo.InvariantCulture));
|
||||
Add("toUtc", AuditQueryHelpers.ResolveTimeSpec(args.Until, now).ToString("o", CultureInfo.InvariantCulture));
|
||||
Add("format", args.Format);
|
||||
Add("channel", args.Channel);
|
||||
Add("kind", args.Kind);
|
||||
Add("status", args.Status);
|
||||
Add("sourceSiteId", args.Site);
|
||||
AddEach("channel", args.Channel);
|
||||
AddEach("kind", args.Kind);
|
||||
AddEach("status", args.Status);
|
||||
AddEach("sourceSiteId", args.Site);
|
||||
Add("target", args.Target);
|
||||
Add("actor", args.Actor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user