Skip to content

πŸ›‘οΈ A powerful yet lightweight tool to catch critical configuration issues before runtime, ensuring your .NET applications run reliably across all environments.

License

Notifications You must be signed in to change notification settings

selcukgural/SGuard.ConfigValidation

Repository files navigation

SGuard.ConfigValidation

NuGet Version NuGet Downloads .NET License Documentation

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!

About

πŸ›‘οΈ A powerful yet lightweight tool to catch critical configuration issues before runtime, ensuring your .NET applications run reliably across all environments.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages