Skip to content

srinivasareddy76/password-updater-suite

Repository files navigation

Password Updater for JSON Configuration Files

This Python script automatically updates database passwords, application passwords, and ISVA passwords across multiple JSON configuration files for different environments.

Features

  • ✅ 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

Files Structure

/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

Usage

Method 1: Using Configuration File (Recommended)

python3 password_updater.py --config config.json

Method 2: Command Line Arguments

python3 password_updater.py \
  --db-pwd "new_database_password" \
  --app-pwd "new_application_password" \
  --isva-pwd "new_isva_password"

Method 3: Custom File List

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.json

Dry Run Mode

Preview changes without modifying files:

python3 password_updater.py --config config.json --dry-run

Configuration File Format

The 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"
  ]
}

JSON File Structure

The script expects JSON files with this structure:

{
  "database": {
    "dbpwd": "current_db_password"
  },
  "application": {
    "applicationPassword": "current_app_password"
  },
  "isva": {
    "IsvaPassword": "current_isva_password"
  }
}

Using the Wrapper Script

1. Make the shell script executable:

chmod +x update_passwords.sh

2. Run the wrapper script:

./update_passwords.sh

3. View execution logs:

tail -f update_execution.log

Base64 Encoding and ZIP Compression

The script now supports converting updated JSON files to base64 encoded text files and compressing them into a ZIP archive.

Basic Usage Examples

Update passwords and create encoded ZIP file:

python3 password_updater.py \
  --db-pwd "new_db_pass" \
  --app-pwd "new_app_pass" \
  --isva-pwd "new_isva_pass" \
  --encode-and-zip

Only encode existing files (no password update):

python3 password_updater.py --encode-only

Specify custom ZIP filename and keep .txt files:

python3 password_updater.py \
  --encode-only \
  --zip-filename "my_configs_backup.zip" \
  --keep-txt

Use configuration file with encoding options:

python3 password_updater.py --config config.json

Encoding Process

  1. Password Update: Updates passwords in JSON files (if specified)
  2. Base64 Encoding: Converts each JSON file to base64 encoded text
  3. File Creation: Saves encoded content as .txt files (t1.json → t1.txt)
  4. ZIP Compression: Creates a ZIP archive containing all .txt files
  5. Cleanup: Optionally removes .txt files after zipping (default behavior)

Output Files

  • 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

Security Features

  • 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

Command Line Options

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

Logging

The script creates detailed logs in:

  • password_update.log - Main application log
  • update_execution.log - Wrapper script execution log

Error Handling

The script handles various error scenarios:

  • Missing files
  • Invalid JSON format
  • Permission issues
  • Backup creation failures
  • Network/disk issues

Examples

Update passwords for specific environments:

python3 password_updater.py \
  --db-pwd "SecureDB2024!" \
  --app-pwd "AppPass2024!" \
  --isva-pwd "IsvaPass2024!" \
  --files t1.json t3.json

Preview changes before applying:

python3 password_updater.py --config config.json --dry-run

Check what files would be updated:

python3 password_updater.py --help

Troubleshooting

  1. Permission Denied: Ensure the script has read/write permissions
  2. File Not Found: Check file paths are correct
  3. Invalid JSON: Validate JSON syntax in configuration files
  4. Backup Issues: Ensure sufficient disk space for backups

Best Practices

  1. Test First: Always use --dry-run before actual updates
  2. Backup Strategy: Keep backups in a separate location
  3. Password Security: Use strong, unique passwords
  4. Regular Updates: Update passwords on a regular basis as needed
  5. Monitor Logs: Check logs regularly for any issues
  6. Version Control: Consider excluding sensitive config files from git

About

Comprehensive password updater for JSON configuration files with base64 encoding and ZIP compression

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published