SGuard.ConfigValidation

A lightweight, production-ready tool to catch critical configuration issues before runtime. Validate your configuration files during application startup or in your CI/CD pipeline.
📚 Documentation
📖 View Full Documentation
Quick links:
✨ Why SGuard.ConfigValidation?
Misconfigured environments, missing connection strings, or wrong URLs can cause major issues after deployment.
SGuard.ConfigValidation helps you detect these problems early, preventing runtime failures and reducing debugging time.
🚀 Key Features
- ✅ Multiple Validators:
required, min_len, max_len, eq, ne, gt, gte, lt, lte, in
- ✅ JSON & YAML Support: Load configuration and app settings from JSON and YAML files
- ✅ JSON Schema Validation: Validate
sguard.json against JSON Schema
- ✅ Custom Validator Plugins: Extend validation capabilities with custom validators
- ✅ CLI Tool: Command-line interface for easy validation
- ✅ Dependency Injection: Full DI support with extension methods
- ✅ Security Features: Built-in DoS protection, path traversal protection, and resource limits
- ✅ Performance Optimized: Caching, streaming, and parallel validation support
- ✅ Multiple Output Formats: Console, JSON, and text file output
- ✅ Comprehensive Testing: High test coverage with xUnit
📦 Projects
This repository contains multiple projects:
🏃 Quick Start
Using the CLI
# Clone the repository
git clone https://github.com/selcukgural/SGuard.ConfigValidation.git
cd SGuard.ConfigValidation
# Run validation
cd SGuard.ConfigValidation.Console
dotnet run -- validate --all
Using as a Library
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SGuard.ConfigValidation.Extensions;
using SGuard.ConfigValidation.Services.Abstract;
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddConsole());
services.AddSGuardConfigValidation();
var serviceProvider = services.BuildServiceProvider();
var ruleEngine = serviceProvider.GetRequiredService<IRuleEngine>();
var result = await ruleEngine.ValidateEnvironmentAsync("sguard.json", "prod");
Example Configuration (sguard.json)
{
"version": "1",
"environments": [
{
"id": "prod",
"name": "Production",
"path": "appsettings.Production.json"
}
],
"rules": [
{
"id": "connection-string-rule",
"environments": ["prod"],
"rule": {
"id": "required-connection-string",
"conditions": [
{
"key": "ConnectionStrings:DefaultConnection",
"condition": [
{
"validator": "required",
"message": "Connection string is required"
},
{
"validator": "min_len",
"value": 10,
"message": "Connection string must be at least 10 characters"
}
]
}
]
}
}
]
}
🔧 Supported Frameworks
- .NET 8.0 (LTS)
- .NET 9.0
- .NET 10.0
📖 Documentation
🧪 Testing
# Run all tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage" --results-directory:"./TestResults"
🔒 Security
SGuard.ConfigValidation includes built-in security features:
- DoS Protection: Resource limits prevent memory exhaustion
- Path Traversal Protection: Prevents access to files outside base directory
- Symlink Attack Protection: Validates symlinks to prevent unauthorized access
- Configurable Limits: Adjustable security limits via configuration
See Security Configuration for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
For questions or contributions, feel free to open an issue or pull request!
评论