#18 [Feature]: Support dotenv, JSON, and YAML secret import and export
Originally created by: thomijasir
Originally owned by: thomijasir
Feature description
Let users move secret sets through dotenv, JSON, or YAML files and standard input. Apply the same input support when initializing a project.
Current behavior
Import and init read dotenv files. Export writes dotenv to a file or stdout.
Why we need this
Deployment tools and existing applications commonly exchange flat configuration as JSON or YAML. Manual conversion adds scripts that can mishandle quoting or expose values.
CLI interface
dopbase init storefront development --from .envdopbase init storefront development --from secrets.jsondopbase init storefront development --from - --format yamldopbase import ENVIRONMENT secrets.json --format jsondopbase import ENVIRONMENT - --format yamldopbase export ENVIRONMENT --output secrets.yaml --format yamldopbase export ENVIRONMENT --stdout --format json
--format <dotenv|json|yaml> is optional for files and overrides filename inference. It is required when init or import reads - from stdin.
Expected behavior
- Infer JSON from
.jsonand YAML from.yamlor.yml, case-insensitively. - Treat every other filename as dotenv. This preserves
.env,.env.production, and extensionless dotenv files. - Keep dotenv as the default stdout export format.
- Accept only one flat mapping of string keys to string values for JSON and YAML.
- Reject nested objects, arrays, numbers, booleans, null values, duplicate keys, empty keys, multiple YAML documents, and inputs with no secret entries.
- Continue accepting empty string values such as
KEY=or{"KEY":""}. - Sort keys for deterministic dotenv, JSON, and YAML output.
- Preserve import dry runs, replacement previews, confirmations, and expected-revision checks.
- Preserve password confirmation for plaintext export and private file permissions.
Security and compatibility
- Never include secret values in validation errors, progress messages, or logs. An error may identify the affected key and value type.
- Keep global
--jsonseparate from secret serialization. Continue rejecting global--jsonwith plaintext--stdout. - Do not overwrite an output file without
--force. - Stdin import and init require an existing valid login or
DOPBASE_TOKENbecause stdin is carrying secret data and cannot also serve an interactive login prompt. - Keep server request and response schemas unchanged. Format parsing and rendering belong to the CLI.
Out of scope
- Adding JSON or YAML import and export to the Admin UI.
- Framework-specific formats.
- Template rendering.
- Changing server request or response schemas.
Acceptance criteria
- [ ] Init, import, and export support dotenv, JSON, and YAML files.
- [ ] Init and import accept stdin only with an explicit format.
- [ ] Explicit formats override filename inference.
- [ ]
.env.productionand unknown extensions remain compatible as dotenv. - [ ] All three formats export deterministic content.
- [ ] Invalid value types identify the affected key without printing its value.
- [ ] Inputs with no entries are rejected, while empty string values remain valid.
- [ ] Existing dotenv commands remain compatible.
- [ ] Dry-run and replacement safety work for every input format.
- [ ] File exports retain overwrite protection and private permissions.
Test scenarios
Add format and round-trip tests under app/tests/cli/. Cover init and import arguments, stdin requirements, malformed documents, duplicate and empty keys, unsupported types, zero-entry input, extension inference, format overrides, output ordering, overwrite protection, and errors that do not expose secret values.
Documentation
Document supported shapes, init and import stdin usage, format inference, .env.production compatibility, plaintext handling, deterministic output, and pipeline examples. Make it clear that the Admin UI remains dotenv-only.
Dependencies
Use serde-saphyr with strict duplicate-key, merge-key, type, and parser-budget settings for YAML.
Originally posted by: thomijasir
Implemented in [#42].
The pull request adds the shared CLI format layer, wires it into init, import, and export, and includes parser, argument, and end-to-end command tests. The server request and response schemas are unchanged.
Verification passed:
Related
Tickets:
#42Ticket changed by: dopbase