This document describes the comprehensive improvements made to user interface, menus, and data persistence throughout the InsightVM-Python tools.
The InsightVM-Python tools have been enhanced with:
- Persistent Configuration System: Saves user preferences and last-used values
- Interactive Menu Framework: Rich UI with colored output and progress indicators
- Enhanced Tool Interfaces: All tools now support both CLI and interactive modes
- Better User Experience: Confirmation prompts, preview modes, and helpful defaults
A comprehensive configuration management system that persists user settings between runs.
Features:
- Stores configuration in
~/.insightvm/config.json - Saves tool-specific defaults (CSV paths, days filters, etc.)
- Manages user preferences (colors, confirmations, progress bars)
- Supports resumable operations with state files
- Dot-notation access (e.g.,
config.get('tools.sonar_queries.default_days'))
Configuration Structure:
{
"version": "2.0.0",
"preferences": {
"confirm_destructive_operations": true,
"colored_output": true,
"show_progress_bars": true,
"verbose": false
},
"tools": {
"sonar_queries": {
"last_csv_path": "/path/to/targets.csv",
"default_days": 30,
"last_output_path": "/path/to/results.csv"
},
"insight_agent": {
"last_installer_path": "",
"last_token": ""
},
"scan_assistant": {
"last_certificate": "",
"package_manager": ""
}
}
}
Usage Example:
from src.rapid7.config import get_config
config = get_config()
# Get a value
days = config.get('tools.sonar_queries.default_days', 30)
# Set a value
config.set('tools.sonar_queries.default_days', 7)
config.save()
# Get tool-specific config
tool_config = config.get_tool_config('sonar_queries')
# Save operation state for resumable operations
config.save_state('my_tool', {'step': 3, 'items': [1, 2, 3]})
# Load state later
state = config.load_state('my_tool')
A rich user interface framework with fallback support for environments without the rich library.
Features:
- Colored Output: Green for success, red for errors, yellow for warnings, blue for info
- Progress Bars: Visual feedback for long-running operations
- Interactive Menus: Numbered selection menus with back navigation
- Confirmation Prompts: Yes/no questions with smart defaults
- Formatted Tables: Pretty-print data in tables
- Headers and Separators: Visual organization
Usage Examples:
from src.rapid7.ui import create_ui
ui = create_ui()
# Print colored messages
ui.print_success("Operation completed successfully!")
ui.print_error("Failed to connect to server")
ui.print_warning("This action cannot be undone")
ui.print_info("Processing 100 items...")
# Headers and sections
ui.print_header("Main Menu")
ui.print_separator()
# Confirmation prompts
if ui.confirm("Proceed with deletion?", default=False):
# Delete items
pass
# User input with defaults
name = ui.prompt("Enter your name", default="John Doe")
csv_path = ui.prompt("Enter CSV file path")
# Selection menus
options = ["Create Query", "List Queries", "Delete Query", "Exit"]
choice = ui.select_menu("Sonar Query Manager", options)
if choice is not None:
print(f"You selected: {options[choice]}")
else:
print("User went back")
# Progress bars
with ui.progress_bar("Processing items", total=100) as progress:
for i in range(100):
# Do work
progress.update(1)
# Tables
ui.print_table(
"Query Results",
headers=["Target", "Status", "Query ID"],
rows=[
["example.com", "success", "12345"],
["test.org", "success", "12346"],
["bad-target", "error", "N/A"]
]
)
The Sonar Query creation tool now supports interactive mode with persistent configuration.
New Features:
Run without arguments to enter interactive mode:
python src/rapid7/tools/create_sonar_queries.py
Interactive Workflow:
- Remembers last-used CSV file path
- Saves default days filter setting
- Suggests output file path
- Shows preview before execution
- Requires confirmation before proceeding
- Displays colored progress and results
- Saves all settings for next run
Traditional command-line mode still works:
# With defaults
python src/rapid7/tools/create_sonar_queries.py targets.csv
# With custom days
python src/rapid7/tools/create_sonar_queries.py targets.csv --days 7
# With custom output
python src/rapid7/tools/create_sonar_queries.py targets.csv --output results.csv
# Force interactive mode
python src/rapid7/tools/create_sonar_queries.py --interactive
Configuration Persistence:
- Last CSV file path is remembered
- Default days setting is saved
- Output path preferences are stored
- Settings persist across runs
UI Enhancements:
- ✓ Green checkmarks for successful operations
- ✗ Red X marks for errors
- ⚠ Yellow warnings for potential issues
- ℹ Blue info messages
- Formatted summary table at completion
Template for future enhancement with:
- Interactive installer selection
- Token management with encrypted storage
- Confirmation before installation
- Post-install verification menu
- Configuration persistence
Template for future enhancement with:
- Main menu (install, verify, configure, uninstall)
- Certificate management
- Progress indicators for downloads
- Configuration preview
- Installation status tracking
- Reduced Repetition: Never re-enter the same CSV path or settings
- Better Defaults: Tools remember your preferences
- Clear Feedback: Colored output makes success/failure obvious
- Safer Operations: Confirmation prompts prevent mistakes
- Progress Visibility: Know what's happening during long operations
- Easier Navigation: Menu systems for complex workflows
- Reusable Components: Config and UI modules work across all tools
- Consistent Patterns: Same UI/UX across different tools
- Easy Testing: Graceful fallback when
richisn't available - Maintainable Code: Centralized configuration management
- Extensible: Easy to add new tools with same patterns
To add UI improvements to an existing tool:
# 1. Import new modules
from src.rapid7.config import get_config
from src.rapid7.ui import create_ui
# 2. Create instances
config = get_config()
ui = create_ui()
# 3. Load tool configuration
tool_config = config.get_tool_config('my_tool')
last_value = tool_config.get('last_setting', 'default')
# 4. Use UI for prompts
value = ui.prompt("Enter value", default=last_value)
# 5. Save configuration
config.set('tools.my_tool.last_setting', value)
config.save()
# 6. Use colored output
ui.print_success("Operation completed!")
def interactive_mode():
"""Run in interactive mode."""
config = get_config()
ui = create_ui()
ui.print_header("My Tool - Interactive Mode")
# Get settings with smart defaults
tool_config = config.get_tool_config('my_tool')
setting = ui.prompt(
"Enter setting",
default=tool_config.get('last_setting', 'default')
)
# Confirm before proceeding
if not ui.confirm("Proceed?", default=True):
ui.print_warning("Operation cancelled")
return 0
# Save settings
config.set('tools.my_tool.last_setting', setting)
config.save()
# Do work with progress
with ui.progress_bar("Processing", total=10) as progress:
for i in range(10):
# Work here
progress.update(1)
ui.print_success("Complete!")
return 0
def main():
# Run interactive if no arguments
if len(sys.argv) == 1:
sys.exit(interactive_mode())
# Otherwise parse CLI arguments
parser = argparse.ArgumentParser(...)
# ...
- Main Config:
~/.insightvm/config.json - State Files:
~/.insightvm/state/<tool_name>_state.json - Automatic Creation: Directories created automatically on first run
requests- HTTP communicationpython-dotenv- Environment variablespandas- Data processing (for CSV tools)
rich- Enhanced UI with colors, tables, progress bars- Graceful Fallback: Tools work without
rich, just less pretty - Install:
pip install rich>=13.0.0
- Graceful Fallback: Tools work without
-
Operation History Database (SQLite)
- Track all operations
- Searchable history
- Repeat previous operations
- Audit trail
-
Unified Tool Launcher
- Main menu for all tools
- Consistent navigation
- Shared configuration
- Help system
-
Dry-Run Mode
- Preview before execution
- Validate inputs
- Estimate time/resources
- Rollback support
-
Enhanced Logging
- Structured logging
- Log levels (DEBUG, INFO, WARN, ERROR)
- Log file rotation
- Remote logging support
-
Multi-Language Support
- Internationalization (i18n)
- Configurable language
- Translated messages
Problem: Config file corrupted or missing
from src.rapid7.config import get_config
config = get_config()
config.reset() # Reset to defaults
config.save()
Problem: Old config format
- Delete
~/.insightvm/config.json - Restart tool to create new config
Problem: Colors not showing
- Check
config.json:"colored_output": true - Or set preference:
config.set_preference('colored_output', True)
Problem: Progress bars not appearing
- Check
config.json:"show_progress_bars": true - Or install rich:
pip install rich
Problem: Tool doesn't remember settings
- Check config file exists:
~/.insightvm/config.json - Check tool name matches in
toolssection - Verify
config.save()is called after setting values
See docs/EXAMPLES.md for complete working examples of:
- Using configuration system
- Building interactive menus
- Creating progress indicators
- Handling user input
- Saving and loading state
When adding new tools or features:
- Use
get_config()for persistent settings - Use
create_ui()for user interaction - Add tool configuration section in default config
- Support both interactive and CLI modes
- Save user preferences after operations
- Use colored output for feedback
- Add confirmation for destructive operations
- Document new features in this file
- ✨ Added persistent configuration system
- ✨ Added UI utilities framework
- ✨ Enhanced create_sonar_queries.py with interactive mode
- ✨ Added colored output and progress bars
- ✨ Added confirmation prompts
- 📝 Updated requirements.txt
- 📝 Created comprehensive documentation
- 🎉 Major architecture refactoring
- ✅ Modern authentication with HTTPBasicAuth
- ✅ Unified client interface
- ✅ Modular API design