feat(cli): add --credentials-file to load dotenv-style credentials - #671
feat(cli): add --credentials-file to load dotenv-style credentials#671jennijuju wants to merge 4 commits into
Conversation
SgtPooki
left a comment
There was a problem hiding this comment.
ok some findings when testing this out:
Big issue in non-happy path: since --env-file is also used by nodejs, it triggers nodejs validation (but not application) prior to hitting our code, which ends up returning a nodejs error that isn't super informative. We should rename the option so it doesn't conflict
Smaller issue we should handle for completeness: server and session sub-commands do read and process the --env-file if passed, but then emit a "error: unknown option '--env-file'" error. we likely need to add envFileOption into addSigningAuthOptions(server) and addOwnerAuthOptions(session). A later PR should probably normalize these better..
fdabdf5 to
e105cfc
Compare
e105cfc to
0565a54
Compare
|
Renamed to |
commit: |
Lets users point the CLI at a downloaded credentials file (e.g. the Filecoin Pay console's session-key .env) without source-ing it. - src/utils/env-file.ts: parse/load dotenv-style KEY=VALUE files into process.env, skipping blanks/comments and stripping matched quotes. Never overrides a variable already present in the environment. - src/cli.ts: pre-parse argv for --env-file before Commander/telemetry resolve any env vars, so precedence is CLI flag > real env > file. - src/utils/cli-options.ts: declare --env-file on addAuthOptions (help + so Commander doesn't reject the flag); mention it in the --session-key description. - README: note --env-file under session-key setup and in the CLI argument reference.
Node reserves --env-file and validates it before our code runs, so a bad path produced a Node error rather than ours. The renamed flag is registered on every auth-taking command tree (add, import, payments, data-set, rm, provider, server, session create/authorize/revoke), so the pre-parse loader and Commander agree on the option.
…errors Adds the missing precedence case: a value loaded from the credentials file into the environment loses to the flag through Commander's env binding. Read failures name the reason (file not found, permission denied) instead of repeating the path, and the empty-file case joins the loadCredentialsFile block.
e3fcfda to
18c3e73
Compare
Adds
--credentials-file <path>so a downloaded credentials file (for example the Filecoin Pay console's session-key.env) can be loaded without sourcing it into the shell. Values from the file never override variables already set in the environment, and flags still win over both.The flag was
--env-filein the first revision. Node reserves that name and validates it before our code runs, so a bad path produced a Node error instead of ours.--credentials-fileis not a Node flag, and it names what the file holds.The option is registered on every command tree that takes auth options, including
serverandsession create/authorize/revoke, so Commander accepts it wherever the pre-parse loader reads it.Parsing uses
util.parseEnvfrom Node.Part of the login epic, tracked in #697.