# Infrastructure Validation Configuration
# This file defines validation rules, their execution order, and settings

[validation_settings]
# Global validation settings
auto_fix_enabled = true
default_report_format = "md"
default_severity_filter = "warning"
max_concurrent_rules = 4
progress_reporting = true

# Rule execution settings
[execution]
# Rules execution order and grouping
rule_groups = [
  "syntax",         # Critical syntax validation first
  "compilation",    # Compilation checks
  "schema",         # Schema validation
  "security",       # Security checks
  "best_practices", # Best practices
  "compatibility",  # Compatibility checks
]

# Timeout settings (in seconds)
file_timeout = 10
rule_timeout = 30
total_timeout = 300

# Parallel processing
max_file_workers = 8
parallel_files = true

# Core validation rules
[[rules]]
auto_fix = true
category = "syntax"
description = "Validate YAML files have correct syntax and can be parsed"
enabled = true
execution_order = 1
files_pattern = '.*\.ya?ml$'
fix_function = "fix_yaml_syntax"
id = "VAL001"
name = "YAML Syntax Validation"
severity = "critical"
tags = ["syntax", "yaml", "critical"]
validator_function = "validate_yaml_syntax"

[[rules]]
auto_fix = false
category = "compilation"
dependencies = ["kcl"]                                  # Required system dependencies
description = "Validate KCL files compile successfully"
enabled = true
execution_order = 2
files_pattern = '.*\.k$'
id = "VAL002"
name = "KCL Compilation Check"
severity = "critical"
tags = ["kcl", "compilation", "critical"]
validator_function = "validate_kcl_compilation"

[[rules]]
auto_fix = true
category = "syntax"
description = "Check for unquoted variable references in YAML that cause parsing errors"
enabled = true
execution_order = 3
files_pattern = '.*\.ya?ml$'
fix_function = "fix_unquoted_variables"
id = "VAL003"
name = "Unquoted Variable References"
severity = "error"
tags = ["yaml", "variables", "syntax"]
validator_function = "validate_quoted_variables"

[[rules]]
auto_fix = false
category = "schema"
description = "Validate that all required fields are present in configuration files"
enabled = true
execution_order = 10
files_pattern = '.*\.(k|ya?ml)$'
id = "VAL004"
name = "Required Fields Validation"
severity = "error"
tags = ["schema", "required", "fields"]
validator_function = "validate_required_fields"

[[rules]]
auto_fix = true
category = "best_practices"
description = "Validate resource names follow established conventions"
enabled = true
execution_order = 20
files_pattern = '.*\.(k|ya?ml)$'
fix_function = "fix_naming_conventions"
id = "VAL005"
name = "Resource Naming Conventions"
severity = "warning"
tags = ["naming", "conventions", "best_practices"]
validator_function = "validate_naming_conventions"

[[rules]]
auto_fix = false
category = "security"
description = "Validate basic security configurations like SSH keys, exposed ports"
enabled = true
execution_order = 15
files_pattern = '.*\.(k|ya?ml)$'
id = "VAL006"
name = "Basic Security Checks"
severity = "error"
tags = ["security", "ssh", "ports"]
validator_function = "validate_security_basics"

[[rules]]
auto_fix = false
category = "compatibility"
description = "Check for deprecated versions and compatibility issues"
enabled = true
execution_order = 25
files_pattern = '.*\.(k|ya?ml|toml)$'
id = "VAL007"
name = "Version Compatibility Check"
severity = "warning"
tags = ["versions", "compatibility", "deprecation"]
validator_function = "validate_version_compatibility"

[[rules]]
auto_fix = false
category = "networking"
description = "Validate network configurations, CIDR blocks, and IP assignments"
enabled = true
execution_order = 18
files_pattern = '.*\.(k|ya?ml)$'
id = "VAL008"
name = "Network Configuration Validation"
severity = "error"
tags = ["networking", "cidr", "ip"]
validator_function = "validate_network_config"

# Extension points for custom rules
[extensions]
# Paths to search for custom validation rules
rule_paths = [
  "./custom_rules",
  "./providers/*/validation_rules",
  "./taskservs/*/validation_rules",
  "../validation_extensions",
]

# Custom rule file patterns
rule_file_patterns = ["*_validation_rules.toml", "validation_*.toml", "rules.toml"]

# Hook system for extending validation
[hooks]
# Pre-validation hooks
pre_validation = []

# Post-validation hooks
post_validation = []

# Per-rule hooks
post_rule = []
pre_rule = []

# Report generation hooks
post_report = []
pre_report = []

# CI/CD integration settings
[ci_cd]
# Exit code mapping
exit_codes = { passed = 0, critical = 1, error = 2, warning = 3, system_error = 4 }

# CI-specific settings
minimal_output = true
no_colors = true
structured_output = true

# Report formats for CI
ci_report_formats = ["yaml", "json"]

# Performance settings
[performance]
# File size limits (in MB)
max_file_size = 10
max_total_size = 100

# Memory limits
max_memory_usage = "512MB"

# Caching settings
cache_duration = 3600 # seconds
enable_caching = true

# Provider-specific rule configurations
[providers.upcloud]
custom_rules = ["UPCLOUD001", "UPCLOUD002"]
enabled_rules = ["VAL001", "VAL002", "VAL003", "VAL004", "VAL006", "VAL008"]

[providers.aws]
custom_rules = ["AWS001", "AWS002", "AWS003"]
enabled_rules = ["VAL001", "VAL002", "VAL003", "VAL004", "VAL006", "VAL007", "VAL008"]

[providers.local]
custom_rules = []
enabled_rules = ["VAL001", "VAL002", "VAL003", "VAL004", "VAL005"]

# Taskserv-specific configurations
[taskservs.kubernetes]
custom_rules = ["K8S001", "K8S002"]
enabled_rules = ["VAL001", "VAL002", "VAL004", "VAL006", "VAL008"]

[taskservs.containerd]
custom_rules = ["CONTAINERD001"]
enabled_rules = ["VAL001", "VAL004", "VAL006"]
