Originally created by: thomijasir
Originally owned by: thomijasir
Feature
Add one CLI command that creates an environment in the source project and copies the source environment's current secrets into it.
CLI
dopbase env clone PROJECT_REF/SOURCE_ENVIRONMENT_NAME NEW_ENVIRONMENT_NAME
Examples:
dopbase env clone payment-service/local production
dopbase env clone storefront/staging preview-42 --yes
The source must use a qualified project and environment reference. The destination is always created in the same project as the source.
Behavior
- Resolve the source and its project.
- Check whether the destination name already exists.
- Read the source secret count and show a confirmation summary without showing secret values.
- Require a recent human authentication session.
- Create the destination before exporting plaintext secrets, so a creation race fails before plaintext is fetched.
- Export the source secrets in memory and import them into the destination.
- Remove the newly created destination if export or import fails. Never remove a destination that existed before the command.
- Fetch the project's environments after a successful clone.
- Print the full environment table in normal output.
- With
--json, print the complete environment array, matching dopbase env list --json.
--yes skips the clone confirmation, but it does not bypass authentication or authorization checks.
If the clone succeeds but the final list request fails, report that the clone completed and suggest running dopbase env list PROJECT_REF.
Security
- Human admin credentials only. Runner and service-account credentials are rejected.
- Plaintext secrets stay in memory and are not written to temporary files.
- Secret values are not printed in summaries or errors.
- In-memory secret values are cleared after import where practical.
Out of scope
- Cross-project cloning
- Cross-server cloning
- Syncing into an existing environment
- Copying tokens, audit history, IDs, timestamps, or editor layout
Acceptance criteria
- [x]
dopbase env clone payment-service/local production creates production in payment-service.
- [x] All current secrets from
local are copied, including an empty secret set.
- [x] Existing destination names fail without modifying them.
- [x] Creation failures happen before plaintext export.
- [x] Export and import failures trigger best-effort cleanup.
- [x] Cleanup failures report both the original failure and the cleanup result.
- [x] A final list failure does not roll back a completed clone.
- [x] Normal success output shows every environment in the project.
- [x] JSON success output is the complete environment array.
- [x] Runner credentials, service-account credentials, stale sessions, and cancelled confirmations stop before creation.
- [x] Tests cover argument parsing, request order, output, rollback boundaries, redaction, and zero-secret cloning.
- [x] CLI documentation, examples, and changelog are updated.
Originally posted by: thomijasir
Implemented the clone flow with the agreed interface:
The destination is created in the source project. Normal success output now shows the full project environment table, while
--jsonreturns the same complete array asdopbase env list --json.The implementation includes confirmation, recent human-authentication checks, in-memory secret transfer, creation-before-export ordering, and best-effort rollback after export or import failures. Runner and service-account credentials are rejected.
Verification completed:
The CLI guides, examples, README, and changelog have also been updated.
Ticket changed by: dopbase