feat(cli): read secret-bearing option values from a file or stdin (#137)

Every CLI option that can carry a secret gets a `--<name>-file <path|->`
sibling ('-' reads stdin), so the value stays out of the process list and
shell history: --password-file (global), --primary-config-file /
--backup-config-file (data-connection create|update), --auth-config-file
(external-system create|update), --connection-string-file (db-connection
create|update), --credentials-file (notification smtp create|update) and
--auth-token-file (notification sms create|update). Follows the existing
--config-file convention; `@path` is avoided because System.CommandLine
expands @-tokens as response files.

The value is read at parse time; a missing/unreadable/empty source, or '-'
on a terminal stdin, is a parse error naming option + path only, never the
content. Inline and file forms are mutually exclusive, at most one option
may read stdin, and one trailing line break is stripped. Inline forms keep
working.

docker/seed-sites.sh and docker-env2/seed-sites.sh now write the MxGateway
config (windev gateway key) to a mode-600 temp file removed by an EXIT trap
and pass --primary-config-file; seed-flow-outbound-demo.sh pipes its rig
connection string via --connection-string-file -. CLI README (new "Secrets
from a file or stdin" section + per-command tables), Component-CLI.md and
both docker READMEs updated.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-13 00:46:17 -05:00
parent 1e98997ce1
commit e2f433e849
19 changed files with 724 additions and 52 deletions
@@ -56,15 +56,17 @@ public static class DbConnectionCommands
private static Command BuildCreate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
{
var nameOption = new Option<string>("--name") { Description = "Connection name", Required = true };
var connStrOption = new Option<string>("--connection-string") { Description = "Connection string", Required = true };
var connStrOption = new Option<string>("--connection-string") { Description = "Connection string (or use --connection-string-file)" };
var connStrFileOption = ValueSourceOptions.CreateFileOption(connStrOption, "the connection string");
var cmd = new Command("create") { Description = "Create a database connection" };
cmd.Add(nameOption);
cmd.Add(connStrOption);
ValueSourceOptions.AddFileOptions(cmd, (connStrOption, connStrFileOption, true));
cmd.SetAction(async (ParseResult result) =>
{
var name = result.GetValue(nameOption)!;
var connStr = result.GetValue(connStrOption)!;
var connStr = ValueSourceOptions.GetValue(result, connStrOption, connStrFileOption)!;
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new CreateDatabaseConnectionDefCommand(name, connStr));
@@ -76,17 +78,19 @@ public static class DbConnectionCommands
{
var idOption = new Option<int>("--id") { Description = "Database connection ID", Required = true };
var nameOption = new Option<string>("--name") { Description = "Connection name", Required = true };
var connStrOption = new Option<string>("--connection-string") { Description = "Connection string", Required = true };
var connStrOption = new Option<string>("--connection-string") { Description = "Connection string (or use --connection-string-file)" };
var connStrFileOption = ValueSourceOptions.CreateFileOption(connStrOption, "the connection string");
var cmd = new Command("update") { Description = "Update a database connection" };
cmd.Add(idOption);
cmd.Add(nameOption);
cmd.Add(connStrOption);
ValueSourceOptions.AddFileOptions(cmd, (connStrOption, connStrFileOption, true));
cmd.SetAction(async (ParseResult result) =>
{
var id = result.GetValue(idOption);
var name = result.GetValue(nameOption)!;
var connStr = result.GetValue(connStrOption)!;
var connStr = ValueSourceOptions.GetValue(result, connStrOption, connStrFileOption)!;
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new UpdateDatabaseConnectionDefCommand(id, name, connStr));