feat(export): support multiple --path flags to merge secrets from several paths#280
feat(export): support multiple --path flags to merge secrets from several paths#280codewithsupra wants to merge 1 commit into
Conversation
Adds support for specifying `--path` multiple times in `infisical export`,
mirroring the behaviour already present in `infisical run`:
infisical export --path /global --path /app-a --env prod > .env
Secrets from each path are fetched and merged; later paths win on duplicate
keys (same personal/shared override logic used by `run`).
Implementation reuses `fetchSecrets()` defined in run.go (same `cmd`
package) and switches the export flag from `String("/")` to
`StringArray(["/"])`, keeping the single-path default unchanged.
Closes #900 (export command)
|
| Filename | Overview |
|---|---|
| packages/cmd/export.go | Switches --path from String to StringArray and delegates to fetchSecrets() from run.go; works correctly for the single-path case, but multi-path usage can produce duplicate keys in the exported output when two paths share a secret name |
Reviews (1): Last reviewed commit: "feat(export): support multiple --path fl..." | Re-trigger Greptile
| secrets, err := fetchSecrets(multiPathRequest, "", secretOverriding, token) | ||
| if err != nil { | ||
| util.HandleError(err, "Unable to fetch secrets") | ||
| } |
There was a problem hiding this comment.
Duplicate keys in multi-path export output
When two or more paths contain a secret with the same key, fetchSecrets appends all of them into allSecrets and then calls OverrideSecrets, which only resolves personal-vs-shared conflicts — not cross-path conflicts. The result is that the final slice can hold multiple entries for the same key, producing duplicate keys in the exported output (e.g. the same DB_HOST appearing twice in a .env file). In run.go this is silently deduplicated downstream by getSecretsByKeys, which uses a map; the export path has no equivalent step. A consumer that relies on only one value per key (dotenv, yaml) will silently use whichever instance appears last, which may not be the intended one.
Problem
infisical exportonly accepted a single--pathflag, making it impossible to merge secrets from several folder paths in one command.The
infisical runcommand already supported this viaStringArray(issue #900 tracked the gap across the CLI).Solution
Switch
export's--pathflag fromStringtoStringArrayso users can pass it multiple times:What changed (
packages/cmd/export.go)Flags().String("path", "/", …)Flags().StringArray("path", []string{"/"}, …)GetString("path")→ singleSecretsPathGetStringArray("path")→SecretsPaths []stringmodels.GetAllSecretsParameters+ manual overridemodels.GetMultiPathSecretsParameterspassed tofetchSecrets()fetchSecrets()is already defined inrun.go(samecmdpackage) and handles per-path fetching, token injection, dedup, and personal/shared override — this PR reuses it without duplication.Backwards compatibility
--path /foostill works exactly as before.--path /) is unchanged.Testing
Closes #900 (export command)
🤖 Generated with Claude Code