Skip to content

feat(cli): add --credentials-file to load dotenv-style credentials - #671

Open
jennijuju wants to merge 4 commits into
masterfrom
feat/env-file
Open

feat(cli): add --credentials-file to load dotenv-style credentials#671
jennijuju wants to merge 4 commits into
masterfrom
feat/env-file

Conversation

@jennijuju

@jennijuju jennijuju commented Aug 25, 2026

Copy link
Copy Markdown
Member

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-file in 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-file is not a Node flag, and it names what the file holds.

The option is registered on every command tree that takes auth options, including server and session create/authorize/revoke, so Commander accepts it wherever the pre-parse loader reads it.

Parsing uses util.parseEnv from Node.

Part of the login epic, tracked in #697.

@jennijuju
jennijuju requested a review from SgtPooki as a code owner August 25, 2026 16:59
@FilOzzy FilOzzy added team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board. labels Aug 25, 2026
@FilOzzy FilOzzy added this to FOC Aug 25, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Aug 25, 2026
@FilOzzy FilOzzy moved this from 📌 Triage to 🔎 Awaiting review in FOC Aug 25, 2026

@SgtPooki SgtPooki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general lgtm, one main change requested

Comment thread src/utils/env-file.ts Outdated
Comment thread src/test/unit/env-file.test.ts Outdated
@github-project-automation github-project-automation Bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Aug 25, 2026

@SgtPooki SgtPooki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

@SgtPooki SgtPooki changed the title feat(cli): add --env-file to load dotenv-style credentials feat(cli): add --credentials-file to load dotenv-style credentials Sep 2, 2026
@SgtPooki
SgtPooki self-requested a review September 2, 2026 18:00
@SgtPooki

SgtPooki commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Renamed to --credentials-file in 0565a54. Both findings addressed: our error now fires on a bad path, and the option is registered through addSigningAuthOptions (covers server and every addAuthOptions command) and addOwnerAuthOptions (session create/authorize/revoke). A test asserts the flag is present on each of those trees.

@pkg-pr-new

pkg-pr-new Bot commented Sep 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/filecoin-pin@671

commit: 18c3e73

jennijuju and others added 4 commits September 2, 2026 21:11
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants