Skip to content

Conversation

@frontmesh
Copy link
Owner

This PR implements Option 4 as discussed - storage configuration persistence through multiple methods:

Features

1. Export/Import Commands

  • Export: cfkv storage export --file backup.json - Backup all storages and active storage setting
  • Import: cfkv storage import --file backup.json - Restore storages from backup
  • JSON format for easy version control and transfer between machines

2. Environment Variable Loading

  • Load: cfkv storage load-env - Load storages from environment variables
  • Variables use format: CFKV_STORAGE_<NAME>_<FIELD>
  • Examples: CFKV_STORAGE_PROD_ACCOUNT_ID, CFKV_STORAGE_PROD_NAMESPACE_ID, CFKV_STORAGE_PROD_API_TOKEN
  • Perfect for CI/CD pipelines, Docker containers, and secure credential management

3. Documentation

  • New file: docs/STORAGE_PERSISTENCE.md with:
    • Detailed usage examples for each method
    • Security best practices
    • Use cases (backup/restore, Docker, CI/CD, multiple environments)
    • Troubleshooting guide

Benefits

Backup & Restore - Never lose your configurations after reinstall
Portability - Transfer configs between machines
CI/CD Integration - Use secrets from your CI/CD platform
Containerization - Easy setup in Docker environments
Multiple Environments - Manage dev, staging, prod configs

Tests

  • 4 new unit tests for export/import/env functionality
  • All 21 tests in cfkv crate pass
  • No warnings or errors

Technical Details

  • Added StorageExport struct for export/import format
  • Methods: export_to_json(), import_from_json(), load_from_env(), merge_from_env()
  • Environment variable scanning via CFKV_STORAGE_* pattern matching
  • Automatic merging with existing storages (non-destructive)

- Add export_to_json() method to export storages to JSON format
- Add import_from_json() method to import storages from JSON
- Add load_from_env() to load storages from CFKV_STORAGE_* environment variables
- Add merge_from_env() to merge environment-based storages with existing config
- Add CLI commands: storage export, storage import, storage load-env
- Add comprehensive tests for all new functionality
- Add STORAGE_PERSISTENCE.md documentation with use cases and security guidelines
- Fix unused variable warning in load_from_env
- All tests pass (21 tests in cfkv crate now)
- Add lazy_static mutex to prevent race conditions between tests
- Use unique storage names based on process ID to avoid conflicts
- Move Mutex import to test module only to avoid unused import warning
- All 19 tests in cfkv pass, including parallel execution
@frontmesh frontmesh merged commit 590402a into main Nov 27, 2025
17 checks passed
@frontmesh frontmesh deleted the feature/storage-export-import-env branch November 27, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants