Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /cli /src /kimi_pentest /config.py
| """Configuration management for Kimi Pentest CLI.""" | |
| from pathlib import Path | |
| from typing import Optional | |
| from platformdirs import user_cache_dir, user_config_dir, user_data_dir | |
| from pydantic import Field | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| class Config(BaseSettings): | |
| """Configuration for Kimi Pentest CLI.""" | |
| model_config = SettingsConfigDict( | |
| env_prefix="KIMI_PENTEST_", | |
| env_file=".env", | |
| env_file_encoding="utf-8", | |
| ) | |
| # API Configuration | |
| api_url: str = Field( | |
| default="http://localhost:8000/api/v1", | |
| description="Base URL for the API", | |
| ) | |
| ws_url: str = Field( | |
| default="ws://localhost:8000/ws", | |
| description="WebSocket URL for real-time updates", | |
| ) | |
| # Authentication | |
| api_key: Optional[str] = Field(default=None, description="API key for authentication") | |
| access_token: Optional[str] = Field(default=None, description="OAuth access token") | |
| refresh_token: Optional[str] = Field(default=None, description="OAuth refresh token") | |
| token_expires_at: Optional[int] = Field(default=None, description="Token expiration timestamp") | |
| # Feature Flags | |
| enable_mcp: bool = Field(default=True, description="Enable Model Context Protocol") | |
| enable_plugins: bool = Field(default=True, description="Enable plugin system") | |
| enable_ai: bool = Field(default=True, description="Enable AI features") | |
| # TUI Settings | |
| theme: str = Field(default="dark", description="UI theme (dark, light, system)") | |
| language: str = Field(default="en", description="Interface language") | |
| compact_mode: bool = Field(default=False, description="Enable compact UI mode") | |
| # Scan Settings | |
| default_threads: int = Field(default=10, description="Default number of scan threads") | |
| default_timeout: int = Field(default=30, description="Default scan timeout in seconds") | |
| auto_save: bool = Field(default=True, description="Auto-save scan results") | |
| # AI Settings | |
| ai_model: str = Field(default="gpt-4", description="AI model to use") | |
| ai_api_key: Optional[str] = Field(default=None, description="API key for AI service") | |
| auto_remediate: bool = Field(default=True, description="Auto-suggest remediations") | |
| # Logging | |
| log_level: str = Field(default="info", description="Logging level") | |
| enable_logging: bool = Field(default=True, description="Enable logging") | |
| # Security | |
| secure_storage: bool = Field(default=True, description="Use secure credential storage") | |
| auto_lock: bool = Field(default=False, description="Auto-lock after inactivity") | |
| lock_timeout: int = Field(default=30, description="Auto-lock timeout in minutes") | |
| def config_dir(self) -> Path: | |
| """Get configuration directory.""" | |
| path = Path(user_config_dir("kimi-pentest", "MoonshotAI")) | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def data_dir(self) -> Path: | |
| """Get data directory.""" | |
| path = Path(user_data_dir("kimi-pentest", "MoonshotAI")) | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def cache_dir(self) -> Path: | |
| """Get cache directory.""" | |
| path = Path(user_cache_dir("kimi-pentest", "MoonshotAI")) | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def log_dir(self) -> Path: | |
| """Get log directory.""" | |
| path = self.data_dir / "logs" | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def plugin_dir(self) -> Path: | |
| """Get plugin directory.""" | |
| path = self.data_dir / "plugins" | |
| path.mkdir(parents=True, exist_ok=True) | |
| return path | |
| def version(self) -> str: | |
| """Get CLI version.""" | |
| from importlib.metadata import version as get_version | |
| try: | |
| return get_version("kimi-pentest") | |
| except Exception: | |
| return "dev" | |
| def save(self): | |
| """Save configuration to file.""" | |
| config_file = self.config_dir / "config.json" | |
| import json | |
| with open(config_file, "w") as f: | |
| # Only save non-sensitive settings | |
| data = self.model_dump( | |
| exclude={ | |
| "api_key", | |
| "access_token", | |
| "refresh_token", | |
| "ai_api_key", | |
| } | |
| ) | |
| json.dump(data, f, indent=2) | |
| def load(cls) -> "Config": | |
| """Load configuration from file.""" | |
| config_dir = Path(user_config_dir("kimi-pentest", "MoonshotAI")) | |
| config_file = config_dir / "config.json" | |
| if config_file.exists(): | |
| import json | |
| with open(config_file) as f: | |
| data = json.load(f) | |
| return cls(**data) | |
| return cls() | |
Xet Storage Details
- Size:
- 4.89 kB
- Xet hash:
- e5de72581bd5eacb0bf7f1aaf73c74d7e867848b621cd964a85c8e2cf64a3a23
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.