| Crates.io | guardy |
| lib.rs | guardy |
| version | 0.2.4 |
| created_at | 2025-08-22 12:14:21.39663+00 |
| updated_at | 2025-11-16 21:09:49.346851+00 |
| description | Fast, secure git hooks in Rust with secret scanning and protected file synchronization |
| homepage | https://guardy.dev |
| repository | https://gitlab.com/deepbrain.space/guardy |
| max_upload_size | |
| id | 1806250 |
| size | 756,272 |
Fast, secure git hooks in Rust with secret scanning and protected file synchronization.
cargo install guardy
git clone https://gitlab.com/deepbrain.space/guardy
cd guardy
cargo build --release
cd your-repo/
guardy hooks install
This installs git hooks and creates a default configuration.
Guardy supports both custom commands and built-in actions in hooks:
# guardy.yaml
hooks:
pre-commit:
enabled: true
parallel: false # Run commands in parallel (default: false)
# Built-in actions
builtin: ["scan_secrets"]
# Custom commands
custom:
- command: "cargo fmt --check"
description: "Check formatting"
fail_on_error: true
glob: ["*.rs"] # Only run on Rust files (optional)
- command: "eslint {files} --fix"
description: "Fix ESLint issues"
all_files: true # Run on all files matching glob, not just staged
glob: ["*.js", "*.jsx", "*.ts", "*.tsx"]
stage_fixed: true # Auto-stage fixed files
commit-msg:
enabled: true
builtin: ["conventional_commits"] # Validates conventional commits format
pre-push:
enabled: true
builtin: ["ensure_clean"] # Ensure no uncommitted changes before push
parallel: true # Run all commands in parallel for speed
custom:
- command: "cargo check"
description: "Run type check"
fail_on_error: true
- command: "guardy sync update --force --config ./guardy.yaml"
description: "Sync protected files before push"
fail_on_error: true
Keep files synchronized from upstream repositories:
# guardy.yaml
sync:
repos:
- name: "shared-configs"
repo: "https://gitlab.com/your-org/shared-configs"
version: "v1.0.0" # Can be tag, branch, or commit
source_path: ".gitlab"
dest_path: "./.gitlab"
include: ["**/*"]
exclude: ["*.md"]
# guardy.yaml
scanner:
file_extensions:
- "*.rs"
- "*.js"
- "*.py"
ignore_patterns:
- "target/"
- "node_modules/"
entropy_threshold: 3.0
hooks:
pre_commit:
enabled: true
commands:
- scan
# Scan files for secrets
guardy scan src/
# Check installation status
guardy status
# Sync configuration files
guardy sync
guardy hooks install - Install git hooks in the current repositoryguardy scan <PATH> - Scan files/directories for secrets and sensitive dataguardy status - Show installation and configuration statusguardy config - Manage configuration settingsguardy hooks uninstall - Remove all installed git hooksguardy sync - Interactively update files from remote repositoriesguardy sync diff - Show differences without making changesguardy sync --force - Update all changes without promptingguardy sync status - Show sync configuration and statusguardy hooks run <HOOK> - Manually run a specific git hook for testingGuardy supports multiple configuration formats (YAML, TOML, JSON) with automatic discovery and merging.
Guardy automatically searches for configuration files in the following locations (highest to lowest priority):
./.guardy.{json,yaml,yml,toml} or ./guardy.{json,yaml,yml,toml}~/.config/.guardy.{json,yaml,yml,toml} or
~/.config/guardy.{json,yaml,yml,toml}/etc/.guardy.{json,yaml,yml,toml} or /etc/guardy.{json,yaml,yml,toml}Priority Rules:
.guardy.*) take priority over non-prefixed files (guardy.*)Automatic Merging: Guardy automatically merges all discovered config files with higher priority configs overriding lower priority ones. This allows you to:
/etc/.guardy.yaml~/.config/.guardy.yaml./.guardy.yamlExample Merge Behavior:
If you have:
# /etc/guardy.yaml (lowest priority)
hooks:
pre-commit:
parallel: false
commands:
format-rust:
run: cargo fmt
# ~/.config/.guardy.yaml (medium priority)
hooks:
pre-commit:
parallel: true # Overrides system config
# ./.guardy.yaml (highest priority)
hooks:
pre-commit:
commands:
format-rust:
run: mise exec -- moon run :format # Overrides system config
clippy-check: # Adds new command
run: cargo clippy
The final merged configuration will be:
hooks:
pre-commit:
parallel: true # From user config
commands:
format-rust:
run: mise exec -- moon run :format # From project config
clippy-check: # From project config
run: cargo clippy
# Scanner settings
scanner:
file_extensions:
- "*.rs"
- "*.js"
- "*.py"
- "*.go"
ignore_patterns:
- "target/"
- "node_modules/"
- "*.log"
max_file_size: 1048576 # 1MB
entropy_threshold: 3.5
# Git hooks configuration
hooks:
pre-commit:
enabled: true
builtin: ["scan_secrets"] # Built-in secret scanning
custom: [] # Add custom commands here
pre-push:
enabled: true
custom:
- command: "guardy sync update --force --config ./guardy.yaml"
description: "Sync protected files"
fail_on_error: true
# File synchronization
sync:
repos:
- name: "shared-configs"
repo: "https://gitlab.com/yourorg/shared-configs"
version: "main"
source_path: "."
dest_path: "."
include: ["*.yml", "*.json", ".gitignore"]
exclude: [".git", "target/"]
Guardy can be used as a library for building custom security tools:
use guardy::scanner::ScannerConfig;
use guardy::config::GuardyConfig;
// Load configuration
let config = GuardyConfig::load("guardy.yaml", None, 0)?;
let scanner_config = ScannerConfig::from_config(&config)?;
// Scan for secrets
let results = scanner_config.scan_path("src/")?;
// Process findings
for finding in results.findings {
println!(
"Secret found in {}: {} (confidence: {:.2})",
finding.file_path,
finding.secret_type,
finding.confidence
);
}
Guardy provides flexible git hook management with both built-in actions and custom commands:
scan_secrets - Scan staged files for secrets and credentials (pre-commit hook)conventional_commits - Validate commit messages using conventional commits format (commit-msg
hook)ensure_clean - Ensure repository has no uncommitted changes before push (pre-push hook)Run commands in parallel for faster execution (enabled by default):
hooks:
pre-push:
parallel: true # Default: true - commands run simultaneously with optimal concurrency
custom:
- command: "cargo check"
- command: "cargo clippy"
- command: "cargo fmt --check"
Guardy automatically profiles your system and workload to determine optimal parallelism:
Guardy supports template variables in commands and environment variables, fully compatible with Lefthook syntax:
{staged_files} - Staged files filtered by glob patterns (lefthook-compatible!)
commands:
lint:
run: eslint {staged_files}
glob: "*.js" # Only staged .js files
{files} - Custom files from files: command, filtered by glob patterns
commands:
lint:
run: eslint {files}
files: "git diff --name-only main...HEAD" # Files changed since main
glob: "*.js" # Only .js files from the diff
Note: {files} requires a files: command. Without it, the command is skipped.
{all_files} - All tracked files in the repository (no filtering)
commands:
check-all:
run: prettier --check {all_files}
{push_files} - Files being pushed (pre-push hook only)
pre-push:
commands:
test-changed:
run: npm test {push_files}
{cmd} - The command itself (useful in env vars){guardy_job_name} - Current command/job name{0} - All hook arguments as a single space-joined string{1}, {2}, {3} - Individual hook arguments (1-indexed)commit-msg:
commands:
validate:
run: ./scripts/validate-msg.sh {1} # First argument is commit message file
Target specific file types with glob patterns:
custom:
- command: "prettier --write {staged_files}"
glob: ["*.js", "*.css", "*.html"]
- command: "black {staged_files}"
glob: ["*.py"]
Process all matching files, not just staged ones:
custom:
- command: "eslint {files} --fix"
all_files: true # Process all JS files in repo
glob: ["**/*.js"]
stage_fixed: true # Auto-stage corrected files
Ensures commit messages follow the conventional commits format using the git-conventional library:
hooks:
commit-msg:
enabled: true
builtin: ["conventional_commits"]
Supported formats:
feat(scope): add new featurefix: resolve bug in authenticationdocs: update READMEchore(deps): update dependenciesFeatures:
Ensures the repository has no uncommitted changes before pushing, preventing accidental pushes of work-in-progress:
hooks:
pre-push:
enabled: true
builtin: ["ensure_clean"]
What it checks:
Features:
gix library for maximum performanceNote: This builtin is designed specifically for the pre-push hook. If you need to allow
uncommitted changes in certain workflows, simply remove it from your configuration or use
git push --no-verify to skip hooks.
# Install all hooks
guardy install
# Install specific hooks
guardy install --hooks pre-commit,pre-push
# Force overwrite existing hooks
guardy install --force
Keep configuration files synchronized across multiple repositories:
# Configure sync in guardy.yaml
guardy sync status # Show sync configuration
guardy sync diff # Preview changes without applying
guardy sync # Interactive update with diffs
guardy sync --force # Apply all changes automatically
# Bootstrap from a repository
guardy sync --repo=https://gitlab.com/org/configs --version=main
Integrate sync into your git workflow to ensure files stay synchronized:
# guardy.yaml
sync:
repos:
- name: "shared-configs"
repo: "https://gitlab.com/org/shared-configs"
version: "v1.0.0"
source_path: ".gitlab"
dest_path: "./.gitlab"
include: ["**/*"]
hooks:
pre-push:
enabled: true
custom:
- command: "guardy sync update --force --config ./guardy.yaml"
description: "Ensure configs are synchronized before push"
fail_on_error: true
This ensures synced files are always synchronized before pushing changes.
Features:
# Scan only Rust files
guardy scan --include="*.rs" src/
# Scan excluding test files
guardy scan --exclude="*test*" .
# Output as JSON
guardy scan --format=json src/ > scan-results.json
# guardy.yaml
hooks:
pre-commit:
enabled: true
builtin: ["scan_secrets"]
custom:
- command: "cargo fmt -- --check"
description: "Check formatting"
fail_on_error: true
- command: "cargo clippy -- -D warnings"
description: "Run clippy"
fail_on_error: true
sync:
repos:
- name: "eslint-config"
repo: "https://gitlab.com/company/eslint-configs"
version: "v2.1.0"
source_path: "configs"
dest_path: "."
include: [".eslintrc*", "prettier.config.js"]
exclude: ["*.local.*"]
Guardy efficiently utilizes OS-level filesystem caching for exceptional performance:
First Scan (Cold Cache):
Subsequent Scans (Warm Cache):
Real-World Example:
# First run (cold cache)
$ guardy scan ~/code/large-project --stats
⚡ Scan completed in 91.19s (172,832 files scanned)
# Second run (warm cache)
$ guardy scan ~/code/large-project --stats
⚡ Scan completed in 33.37s (172,832 files scanned)
# 🚀 63% faster!
Typical performance on a modern machine:
MIT License - see LICENSE for details.
Contributions welcome! Please see CONTRIBUTING.md for guidelines.