Refactor code structure for improved readability and maintainability; optimize performance in key functions.
This commit is contained in:
271
src/Cli/StellaOps.Cli/Commands/Binary/BinaryCommandGroup.cs
Normal file
271
src/Cli/StellaOps.Cli/Commands/Binary/BinaryCommandGroup.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// BinaryCommandGroup.cs
|
||||
// Sprint: SPRINT_3850_0001_0001_oci_storage_cli
|
||||
// Tasks: T3, T4, T5, T6
|
||||
// Description: CLI command group for binary reachability operations.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using System.CommandLine;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Cli.Extensions;
|
||||
|
||||
namespace StellaOps.Cli.Commands.Binary;
|
||||
|
||||
/// <summary>
|
||||
/// CLI command group for binary reachability operations.
|
||||
/// </summary>
|
||||
internal static class BinaryCommandGroup
|
||||
{
|
||||
internal static Command BuildBinaryCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var binary = new Command("binary", "Binary reachability analysis operations.");
|
||||
|
||||
binary.Add(BuildSubmitCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildInfoCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildSymbolsCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildVerifyCommand(services, verboseOption, cancellationToken));
|
||||
|
||||
return binary;
|
||||
}
|
||||
|
||||
private static Command BuildSubmitCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var graphOption = new Option<string?>("--graph", new[] { "-g" })
|
||||
{
|
||||
Description = "Path to pre-generated rich graph JSON."
|
||||
};
|
||||
|
||||
var binaryOption = new Option<string?>("--binary", new[] { "-b" })
|
||||
{
|
||||
Description = "Path to binary for analysis."
|
||||
};
|
||||
|
||||
var analyzeOption = new Option<bool>("--analyze")
|
||||
{
|
||||
Description = "Generate graph from binary (requires --binary)."
|
||||
};
|
||||
|
||||
var signOption = new Option<bool>("--sign")
|
||||
{
|
||||
Description = "Sign the graph with DSSE attestation."
|
||||
};
|
||||
|
||||
var registryOption = new Option<string?>("--registry", new[] { "-r" })
|
||||
{
|
||||
Description = "OCI registry to push graph (e.g., ghcr.io/myorg/graphs)."
|
||||
};
|
||||
|
||||
var command = new Command("submit", "Submit binary graph for reachability analysis.")
|
||||
{
|
||||
graphOption,
|
||||
binaryOption,
|
||||
analyzeOption,
|
||||
signOption,
|
||||
registryOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var graphPath = parseResult.GetValue(graphOption);
|
||||
var binaryPath = parseResult.GetValue(binaryOption);
|
||||
var analyze = parseResult.GetValue(analyzeOption);
|
||||
var sign = parseResult.GetValue(signOption);
|
||||
var registry = parseResult.GetValue(registryOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleSubmitAsync(
|
||||
services,
|
||||
graphPath,
|
||||
binaryPath,
|
||||
analyze,
|
||||
sign,
|
||||
registry,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
private static Command BuildInfoCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var hashArg = new Argument<string>("hash")
|
||||
{
|
||||
Description = "Graph digest (e.g., blake3:abc123...)."
|
||||
};
|
||||
|
||||
var formatOption = new Option<string>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: text (default), json."
|
||||
}.SetDefaultValue("text").FromAmong("text", "json");
|
||||
|
||||
var command = new Command("info", "Display binary graph information.")
|
||||
{
|
||||
hashArg,
|
||||
formatOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var hash = parseResult.GetValue(hashArg)!;
|
||||
var format = parseResult.GetValue(formatOption)!;
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleInfoAsync(
|
||||
services,
|
||||
hash,
|
||||
format,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
private static Command BuildSymbolsCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var hashArg = new Argument<string>("hash")
|
||||
{
|
||||
Description = "Graph digest (e.g., blake3:abc123...)."
|
||||
};
|
||||
|
||||
var strippedOnlyOption = new Option<bool>("--stripped-only")
|
||||
{
|
||||
Description = "Show only stripped (heuristic) symbols."
|
||||
};
|
||||
|
||||
var exportedOnlyOption = new Option<bool>("--exported-only")
|
||||
{
|
||||
Description = "Show only exported symbols."
|
||||
};
|
||||
|
||||
var entrypointsOnlyOption = new Option<bool>("--entrypoints-only")
|
||||
{
|
||||
Description = "Show only entrypoint symbols."
|
||||
};
|
||||
|
||||
var searchOption = new Option<string?>("--search", new[] { "-s" })
|
||||
{
|
||||
Description = "Search pattern (supports wildcards, e.g., ssl_*)."
|
||||
};
|
||||
|
||||
var formatOption = new Option<string>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: text (default), json."
|
||||
}.SetDefaultValue("text").FromAmong("text", "json");
|
||||
|
||||
var limitOption = new Option<int>("--limit", new[] { "-n" })
|
||||
{
|
||||
Description = "Limit number of results."
|
||||
}.SetDefaultValue(100);
|
||||
|
||||
var command = new Command("symbols", "List symbols from binary graph.")
|
||||
{
|
||||
hashArg,
|
||||
strippedOnlyOption,
|
||||
exportedOnlyOption,
|
||||
entrypointsOnlyOption,
|
||||
searchOption,
|
||||
formatOption,
|
||||
limitOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var hash = parseResult.GetValue(hashArg)!;
|
||||
var strippedOnly = parseResult.GetValue(strippedOnlyOption);
|
||||
var exportedOnly = parseResult.GetValue(exportedOnlyOption);
|
||||
var entrypointsOnly = parseResult.GetValue(entrypointsOnlyOption);
|
||||
var search = parseResult.GetValue(searchOption);
|
||||
var format = parseResult.GetValue(formatOption)!;
|
||||
var limit = parseResult.GetValue(limitOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleSymbolsAsync(
|
||||
services,
|
||||
hash,
|
||||
strippedOnly,
|
||||
exportedOnly,
|
||||
entrypointsOnly,
|
||||
search,
|
||||
format,
|
||||
limit,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
private static Command BuildVerifyCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var graphOption = new Option<string>("--graph", new[] { "-g" })
|
||||
{
|
||||
Description = "Path to graph file.",
|
||||
IsRequired = true
|
||||
};
|
||||
|
||||
var dsseOption = new Option<string>("--dsse", new[] { "-d" })
|
||||
{
|
||||
Description = "Path to DSSE envelope.",
|
||||
IsRequired = true
|
||||
};
|
||||
|
||||
var publicKeyOption = new Option<string?>("--public-key", new[] { "-k" })
|
||||
{
|
||||
Description = "Path to public key for signature verification."
|
||||
};
|
||||
|
||||
var rekorUrlOption = new Option<string?>("--rekor-url")
|
||||
{
|
||||
Description = "Rekor transparency log URL."
|
||||
};
|
||||
|
||||
var command = new Command("verify", "Verify binary graph attestation.")
|
||||
{
|
||||
graphOption,
|
||||
dsseOption,
|
||||
publicKeyOption,
|
||||
rekorUrlOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var graphPath = parseResult.GetValue(graphOption)!;
|
||||
var dssePath = parseResult.GetValue(dsseOption)!;
|
||||
var publicKey = parseResult.GetValue(publicKeyOption);
|
||||
var rekorUrl = parseResult.GetValue(rekorUrlOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleVerifyAsync(
|
||||
services,
|
||||
graphPath,
|
||||
dssePath,
|
||||
publicKey,
|
||||
rekorUrl,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user