This Python script automatically updates database passwords, application passwords, and ISVA passwords across multiple JSON configuration files for different environments.
- ✅ Updates passwords in multiple JSON files simultaneously
- ✅ Creates automatic backups before making changes
- ✅ Comprehensive logging with timestamps
- ✅ Support for configuration files or command-line arguments
- ✅ Dry-run mode to preview changes
- ✅ Error handling and validation
- ✅ Simple wrapper script for easy execution
- ✅ Base64 encoding and ZIP compression of updated files
/workspace/
├── password_updater.py # Main Python script
├── config.json # Configuration file with new passwords
├── update_passwords.sh # Shell script wrapper for execution
├── t1.json # Environment 1 configuration
├── t3.json # Environment 3 configuration
├── t5.json # Environment 5 configuration
├── backups/ # Automatic backups directory
├── password_update.log # Detailed log file
└── README.md # This file
python3 password_updater.py --config config.jsonpython3 password_updater.py \
--db-pwd "new_database_password" \
--app-pwd "new_application_password" \
--isva-pwd "new_isva_password"python3 password_updater.py \
--db-pwd "new_db_pass" \
--app-pwd "new_app_pass" \
--isva-pwd "new_isva_pass" \
--files t1.json t3.json t5.json custom.jsonPreview changes without modifying files:
python3 password_updater.py --config config.json --dry-runThe config.json file should contain:
{
"database_password": "your_new_db_password",
"application_password": "your_new_app_password",
"isva_password": "your_new_isva_password",
"files": [
"t1.json",
"t3.json",
"t5.json"
]
}The script expects JSON files with this structure:
{
"database": {
"dbpwd": "current_db_password"
},
"application": {
"applicationPassword": "current_app_password"
},
"isva": {
"IsvaPassword": "current_isva_password"
}
}chmod +x update_passwords.sh./update_passwords.shtail -f update_execution.logThe script now supports converting updated JSON files to base64 encoded text files and compressing them into a ZIP archive.
python3 password_updater.py \
--db-pwd "new_db_pass" \
--app-pwd "new_app_pass" \
--isva-pwd "new_isva_pass" \
--encode-and-zippython3 password_updater.py --encode-onlypython3 password_updater.py \
--encode-only \
--zip-filename "my_configs_backup.zip" \
--keep-txtpython3 password_updater.py --config config.json- Password Update: Updates passwords in JSON files (if specified)
- Base64 Encoding: Converts each JSON file to base64 encoded text
- File Creation: Saves encoded content as .txt files (t1.json → t1.txt)
- ZIP Compression: Creates a ZIP archive containing all .txt files
- Cleanup: Optionally removes .txt files after zipping (default behavior)
- JSON files: Original configuration files with updated passwords
- ZIP file: Contains base64 encoded versions of all JSON files
- Backup files: Automatic backups in
backups/directory - Log files: Detailed execution logs
- Automatic Backups: Original files are backed up with timestamps
- Password Masking: Passwords are masked in logs (shows only first 3 characters)
- Error Handling: Comprehensive error handling and logging
- Validation: Checks file existence and JSON validity before processing
usage: password_updater.py [-h] [--config CONFIG] [--db-pwd DB_PWD]
[--app-pwd APP_PWD] [--isva-pwd ISVA_PWD]
[--files FILES [FILES ...]] [--dry-run]
Update passwords in JSON configuration files
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -c CONFIG
Configuration file containing passwords and file list
--db-pwd DB_PWD New database password
--app-pwd APP_PWD New application password
--isva-pwd ISVA_PWD New ISVA password
--files FILES [FILES ...]
List of JSON files to update
--dry-run Show what would be updated without making changes
The script creates detailed logs in:
password_update.log- Main application logupdate_execution.log- Wrapper script execution log
The script handles various error scenarios:
- Missing files
- Invalid JSON format
- Permission issues
- Backup creation failures
- Network/disk issues
python3 password_updater.py \
--db-pwd "SecureDB2024!" \
--app-pwd "AppPass2024!" \
--isva-pwd "IsvaPass2024!" \
--files t1.json t3.jsonpython3 password_updater.py --config config.json --dry-runpython3 password_updater.py --help- Permission Denied: Ensure the script has read/write permissions
- File Not Found: Check file paths are correct
- Invalid JSON: Validate JSON syntax in configuration files
- Backup Issues: Ensure sufficient disk space for backups
- Test First: Always use
--dry-runbefore actual updates - Backup Strategy: Keep backups in a separate location
- Password Security: Use strong, unique passwords
- Regular Updates: Update passwords on a regular basis as needed
- Monitor Logs: Check logs regularly for any issues
- Version Control: Consider excluding sensitive config files from git