# Configuration Scripts

This directory contains interactive configuration tools for setting up the Besu network.

## Scripts

### `configure-network.sh`

Basic configuration tool wrapper. Runs `configure-network.py` with proper environment setup.

**Usage**:
```bash
./scripts/configure-network.sh
```

### `configure-network.py`

Basic interactive configuration tool. Configures:
- Genesis block configuration
- Network configuration
- Besu node configuration
- Deployment configuration (AKS/VM)
- Terraform variables
- Helm values

### `configure-network-advanced.sh`

Advanced configuration tool wrapper. Runs `configure-network-advanced.py` with proper environment setup.

**Usage**:
```bash
./scripts/configure-network-advanced.sh
```

### `configure-network-advanced.py`

Advanced interactive configuration tool. Includes all basic features plus:
- Security configuration (Network Policies, RBAC, Pod Security, WAF)
- Key management configuration
- Access control configuration
- Monitoring configuration (Prometheus, Grafana, Loki, Alertmanager)
- Backup configuration
- Oracle publisher configuration

## Features

### Interactive Prompts

- **Input Validation**: All inputs are validated (IPs, CIDR, ports, hex values)
- **Default Values**: Sensible defaults are provided for all fields
- **Required Fields**: Required fields are clearly marked
- **Yes/No Prompts**: Simple yes/no questions for boolean options

### Generated Files

The configuration tools generate:
- `config/genesis.json` - Genesis block configuration
- `config/validators/besu-config.toml` - Validator configuration
- `config/sentries/besu-config.toml` - Sentry configuration
- `config/rpc/besu-config.toml` - RPC configuration
- `config/permissions-nodes.toml` - Node permissions
- `config/permissions-accounts.toml` - Account permissions
- `config/static-nodes.json` - Static nodes
- `terraform/terraform.tfvars` - Terraform variables
- `helm/besu-network/values.yaml` - Helm values
- `CONFIG_SUMMARY.md` - Configuration summary

### Backup and Restore

- **Automatic Backup**: Existing files are automatically backed up to `.config-backup/`
- **Manual Backup**: Use `make config-backup` to manually backup
- **Restore**: Use `make config-restore` to restore from backup

## Usage Examples

### Basic Configuration

```bash
# Run basic configuration
./scripts/configure-network.sh

# Or use Makefile
make config
```

### Advanced Configuration

```bash
# Run advanced configuration
./scripts/configure-network-advanced.sh

# Or use Makefile
make config-advanced
```

### Validate Configuration

```bash
# Validate generated configuration
make config-validate
```

### View Configuration Summary

```bash
# View configuration summary
make config-summary

# Or directly
cat CONFIG_SUMMARY.md
```

## Configuration Flow

1. **Run Configuration Tool**: Execute `configure-network.sh` or `configure-network-advanced.sh`
2. **Answer Prompts**: Provide all necessary configuration values
3. **Review Generated Files**: Check generated configuration files
4. **Generate Validator Keys**: Run `generate-validator-keys.sh`
5. **Generate Proper Genesis**: Run `generate-genesis-proper.sh` to update `extraData`
6. **Deploy Infrastructure**: Deploy using Terraform and Kubernetes

## Troubleshooting

### Python Version

**Issue**: Python version too old

**Solution**: Ensure Python 3.8+ is installed
```bash
python3 --version
```

### Missing Dependencies

**Issue**: Import errors

**Solution**: The scripts use only Python standard library. No additional dependencies required.

### Configuration Validation

**Issue**: Invalid configuration values

**Solution**: 
- Check validation rules in the tool
- Ensure values are in correct format
- Review error messages

### Backup Restoration

**Issue**: Need to restore configuration

**Solution**:
```bash
# Restore from backup
make config-restore

# Or manually
cp -r .config-backup/* .
```

## Best Practices

1. **Backup First**: Always backup before running configuration tool
2. **Review Generated Files**: Review all generated files before deploying
3. **Validate Configuration**: Use validation scripts to verify configuration
4. **Document Changes**: Document any manual changes to configuration files
5. **Version Control**: Commit configuration files to version control

## Related Documentation

- [Configuration Guide](../docs/CONFIGURATION_GUIDE.md) - Detailed configuration guide
- [Deployment Guide](../docs/DEPLOYMENT.md) - Deployment instructions
- [Troubleshooting Guide](../docs/TROUBLESHOOTING.md) - Troubleshooting guide

