Skip to main content

Module script_generator

Module script_generator 

Source
Expand description

Safe script generation for package manager operations.

This module provides the core script generation functionality that makes Santa secure by default. Instead of directly executing potentially dangerous commands, Santa generates platform-specific scripts that can be reviewed before execution.

§Architecture

  • ScriptGenerator: MiniJinja-based template engine for script generation
  • ExecutionMode: Safe (script generation) vs Execute (direct execution)
  • ScriptFormat: Platform-specific script formats (Shell, PowerShell, Batch)

§Security

All user inputs are sanitized using:

  • Shell escaping via shell-escape crate
  • PowerShell escaping with custom filters
  • Package name validation
  • Template-based command construction

§Examples

use santa::script_generator::{ScriptGenerator, ScriptFormat};

let generator = ScriptGenerator::new()?;
let packages = vec!["git".to_string(), "rust".to_string()];

// Generate a safe shell script
let script = generator.generate_install_script(
    &packages,
    "brew",
    ScriptFormat::Shell,
    "homebrew"
)?;

// Script can now be reviewed and executed manually
println!("{}", script);

Structs§

ScriptGenerator
Script generator using MiniJinja templates for safe script generation.

Enums§

ExecutionMode
Execution modes for Santa - determines whether to execute directly or generate scripts.
ScriptFormat
Script formats for different platforms and shells.