Add source code files
This commit is contained in:
38
src/codeguard/core/config.py
Normal file
38
src/codeguard/core/config.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
from dataclasses import field
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class Config(BaseModel):
|
||||||
|
model: str = "codellama"
|
||||||
|
languages: List[str] = field(default_factory=lambda: ["python", "javascript", "go", "rust"])
|
||||||
|
severity_threshold: str = "low"
|
||||||
|
fail_on_critical: bool = False
|
||||||
|
output_format: str = "text"
|
||||||
|
ollama_url: str = "http://localhost:11434"
|
||||||
|
timeout: int = 120
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(config_path: Optional[str] = None) -> Config:
|
||||||
|
if config_path is None:
|
||||||
|
config_path_str = str(Path.cwd() / "codeguard.yaml")
|
||||||
|
else:
|
||||||
|
config_path_str = config_path
|
||||||
|
|
||||||
|
config_file = Path(config_path_str)
|
||||||
|
|
||||||
|
if config_file.exists():
|
||||||
|
with open(config_file) as f:
|
||||||
|
data = yaml.safe_load(f) or {}
|
||||||
|
return Config(**data)
|
||||||
|
|
||||||
|
return Config()
|
||||||
|
|
||||||
|
|
||||||
|
def save_config(config: Config, config_path: str = "codeguard.yaml") -> None:
|
||||||
|
config_file = Path(config_path)
|
||||||
|
with open(config_file, "w") as f:
|
||||||
|
yaml.dump(config.model_dump(), f)
|
||||||
Reference in New Issue
Block a user