2025-12-11 22:17:44 +00:00

149 lines
3.4 KiB
Plaintext

"""
GitOps configuration schema.
Manages declarative GitOps rules and event-driven automation.
"""
schema TypesGit:
GitProvider: "github" | "gitlab" | "gitea"
EventType: "push" | "pull-request" | "webhook" | "scheduled" | "health-check" | "manual"
Environment: "dev" | "staging" | "prod"
schema GitOpsRule:
"""GitOps automation rule"""
# Rule name
name: str
# Git provider
provider: TypesGit.GitProvider
# Repository URL
repository: str
# Target branch pattern
branch: str = "main"
# Triggering events
events: [TypesGit.EventType]
# Deployment targets/environments
targets: [TypesGit.Environment]
# Deployment command
command: str
# Pre-deployment hook
pre_deploy_hook?: str
# Post-deployment hook
post_deploy_hook?: str
# Manual approval required
require_approval: bool = False
# Concurrency policy
concurrency_limit: int = 1
check:
len(name) > 0, "name must not be empty"
len(repository) > 0, "repository must not be empty"
len(branch) > 0, "branch must not be empty"
len(events) > 0, "events must not be empty"
len(targets) > 0, "targets must not be empty"
len(command) > 0, "command must not be empty"
concurrency_limit > 0, "concurrency_limit must be positive"
schema WebhookConfig:
"""Webhook configuration for Git providers"""
# Provider
provider: TypesGit.GitProvider
# Listener port
port: int = 8080
# Webhook secret for validation
secret?: str
# Allowed events
allowed_events: [TypesGit.EventType]
check:
port > 1024 and port <= 65535, "port must be 1024-65535"
len(allowed_events) > 0, "allowed_events must not be empty"
schema ScheduledTrigger:
"""Scheduled trigger configuration"""
# Trigger name
name: str
# Cron expression
cron: str
# Associated rule
rule: str
# Target environment
environment: TypesGit.Environment
check:
len(name) > 0, "name must not be empty"
len(cron) > 0, "cron must not be empty"
len(rule) > 0, "rule must not be empty"
schema HealthCheckTrigger:
"""Health check based trigger configuration"""
# Trigger name
name: str
# Health check endpoint
endpoint: str
# Check interval in seconds
interval_secs: int = 60
# Failure threshold
failure_threshold: int = 3
# Action on failure
on_failure_action: str
check:
len(name) > 0, "name must not be empty"
len(endpoint) > 0, "endpoint must not be empty"
interval_secs > 0, "interval_secs must be positive"
failure_threshold > 0, "failure_threshold must be positive"
schema GitOpsConfig:
"""Global GitOps configuration"""
# Automation rules
rules: [GitOpsRule]
# Webhooks
webhooks: [WebhookConfig] = []
# Scheduled triggers
scheduled: [ScheduledTrigger] = []
# Health check triggers
health_checks: [HealthCheckTrigger] = []
# Default deployment strategy
default_strategy: str = "rolling"
# Enable dry-run by default
dry_run_by_default: bool = False
# Audit logging
enable_audit_log: bool = True
check:
len(rules) >= 0, "rules must be a valid list"
# Global GitOps configuration
gitops_config: GitOpsConfig = {
rules = []
webhooks = []
scheduled = []
health_checks = []
default_strategy = "rolling"
dry_run_by_default = False
enable_audit_log = True
}