Buckets:

download
raw
3.65 kB
"""Configuration models for Zen-AI GitHub App."""
from enum import Enum
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field, field_validator
class SeverityLevel(str, Enum):
"""Severity levels for scan failures."""
NONE = "none"
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
CRITICAL = "critical"
class ToolType(str, Enum):
"""Available security tools."""
SEMGREP = "semgrep"
TRUFFLEHOG = "trufflehog"
TRIVY = "trivy"
BANDIT = "bandit"
SAFETY = "safety"
NUCLEI = "nuclei"
NMAP = "nmap"
SQLMAP = "sqlmap"
CUSTOM = "custom"
class ScanTypeConfig(BaseModel):
"""Base configuration for scan types."""
enabled: bool = True
tools: List[ToolType] = [ToolType.SEMGREP, ToolType.TRUFFLEHOG]
fail_on: SeverityLevel = SeverityLevel.CRITICAL
timeout: int = Field(default=300, ge=60, le=3600)
ignore_paths: List[str] = Field(
default_factory=lambda: ["vendor/", "node_modules/", ".git/", "__pycache__/", "*.min.js", "*.min.css"]
)
custom_args: Dict[str, Any] = Field(default_factory=dict)
class PRScanConfig(ScanTypeConfig):
"""Pull request scan configuration."""
inline_comments: bool = True
comment_summary: bool = True
block_pr: bool = False
check_run: bool = True
max_comments: int = 50
class PushScanConfig(ScanTypeConfig):
"""Push scan configuration."""
branches: List[str] = Field(default_factory=lambda: ["main", "master", "develop"])
sarif_upload: bool = True
create_issues: bool = False
class ScheduleConfig(BaseModel):
"""Scheduled scan configuration."""
enabled: bool = False
cron: str = "0 0 * * 0" # Weekly on Sunday
scope: str = "full" # full, changed, custom
tools: List[ToolType] = Field(default_factory=list)
class NotificationConfig(BaseModel):
"""Notification configuration."""
pr_comment: bool = True
security_tab: bool = True
check_run: bool = True
email: Optional[str] = None
slack: Optional[str] = None
discord: Optional[str] = None
telegram: Optional[str] = None
class AppConfig(BaseModel):
"""Main GitHub App configuration."""
version: str = "1.0"
scans: Dict[str, Any] = Field(default_factory=dict)
notifications: NotificationConfig = Field(default_factory=NotificationConfig)
@field_validator("scans", mode="before")
@classmethod
def validate_scans(cls, v):
"""Validate and default scan configurations."""
if not isinstance(v, dict):
v = {}
# Default PR scan config
if "pull_request" not in v:
v["pull_request"] = {
"enabled": True,
"tools": ["semgrep", "trufflehog"],
"fail_on": "critical",
"inline_comments": True,
}
# Default push scan config
if "push" not in v:
v["push"] = {"enabled": True, "branches": ["main", "develop"], "tools": ["semgrep", "trufflehog", "trivy"]}
# Default schedule config
if "schedule" not in v:
v["schedule"] = {"enabled": False, "cron": "0 0 * * 0"}
return v
def get_pr_config(self) -> PRScanConfig:
"""Get PR scan configuration."""
return PRScanConfig(**self.scans.get("pull_request", {}))
def get_push_config(self) -> PushScanConfig:
"""Get push scan configuration."""
return PushScanConfig(**self.scans.get("push", {}))
def get_schedule_config(self) -> ScheduleConfig:
"""Get schedule configuration."""
return ScheduleConfig(**self.scans.get("schedule", {}))

Xet Storage Details

Size:
3.65 kB
·
Xet hash:
d3e8bcaf3a080344410fdced0db27aad3d17dd3a1894926cb807b9f5d61c23cd

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.