refactor: simplify configuration to use only environment variables

- Remove credentials.py import, use pydantic-settings .env support
- Remove unused search API keys (Brave, Google)
- Update default search provider to SearXNG
- Add extra="ignore" to allow flexible env var usage
- Update .env.example with organized sections

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-31 11:13:26 +01:00
co-authored by Claude Opus 4.5
parent 167a3a43a8
commit 3ecfb91cc2
3 changed files with 62 additions and 66 deletions
+47 -5
View File
@@ -1,15 +1,57 @@
# Core Code API Configuration # Core Code API Configuration
# Copy to .env and fill in real values
# Application settings # =============================================================================
# Application
# =============================================================================
APP_NAME="Core Code API" APP_NAME="Core Code API"
DEBUG=false DEBUG=false
LOG_LEVEL=INFO
# Server settings # =============================================================================
# Server
# =============================================================================
HOST=0.0.0.0 HOST=0.0.0.0
PORT=8083 PORT=8083
# CORS settings (default allows all origins for internal use) # CORS (default allows all origins for internal use)
# CORS_ORIGINS=["http://192.168.86.149:82"] # CORS_ORIGINS=["http://192.168.86.149:82"]
# Logging # =============================================================================
LOG_LEVEL=INFO # Infrastructure Services
# =============================================================================
# Portainer API (required for container/stack management)
PORTAINER_URL=http://portainer:9000
PORTAINER_API_KEY=ptr_your-api-key-here
# Nginx Proxy Manager API
NPM_URL=http://npm:81
NPM_EMAIL=admin@example.com
NPM_PASSWORD=your-npm-password
# =============================================================================
# Home Automation
# =============================================================================
# Home Assistant API
HOMEASSISTANT_URL=http://homeassistant:8123
HOMEASSISTANT_TOKEN=your-long-lived-access-token
# =============================================================================
# AI Services
# =============================================================================
# Ollama API
OLLAMA_BASE_URL=http://ollama:11434
# SearXNG (self-hosted search)
SEARXNG_URL=http://searxng:8080
# =============================================================================
# Vector Database
# =============================================================================
# Qdrant
QDRANT_HOST=qdrant
QDRANT_PORT=6333
+15 -38
View File
@@ -1,5 +1,8 @@
""" """
Global configuration for Core Code API Global configuration for Core Code API
All configuration is loaded from environment variables or .env file.
See .env.example for available settings.
""" """
import tomllib import tomllib
from pathlib import Path from pathlib import Path
@@ -20,29 +23,6 @@ def _get_version_from_pyproject() -> str:
__version__ = _get_version_from_pyproject() __version__ = _get_version_from_pyproject()
# Import infrastructure credentials from gitignored module
try:
from src.credentials import (
PORTAINER_URL, PORTAINER_API_KEY,
NPM_URL, NPM_EMAIL, NPM_PASSWORD,
BRAVE_SEARCH_API_KEY,
GOOGLE_SEARCH_API_KEY, GOOGLE_SEARCH_ENGINE_ID,
HOMEASSISTANT_URL, HOMEASSISTANT_TOKEN
)
except ImportError:
# Fallback to empty strings if credentials.py doesn't exist
# (e.g., fresh clone before credentials setup)
PORTAINER_URL = "http://localhost:8001"
PORTAINER_API_KEY = ""
NPM_URL = "http://localhost:81"
NPM_EMAIL = ""
NPM_PASSWORD = ""
BRAVE_SEARCH_API_KEY = ""
GOOGLE_SEARCH_API_KEY = ""
GOOGLE_SEARCH_ENGINE_ID = ""
HOMEASSISTANT_URL = "http://localhost:8123"
HOMEASSISTANT_TOKEN = ""
class Settings(BaseSettings): class Settings(BaseSettings):
"""Global application settings""" """Global application settings"""
@@ -109,25 +89,21 @@ class Settings(BaseSettings):
embedding_batch_size: int = 32 embedding_batch_size: int = 32
# Search Configuration # Search Configuration
search_provider: str = "google" # Options: google, brave, searxng, duckduckgo search_provider: str = "searxng"
searxng_url: str = "http://searxng:8080" # For future self-hosted SearxNG searxng_url: str = "http://searxng:8080"
# Search API Keys (from credentials.py) # Infrastructure Management (Portainer)
brave_search_api_key: str = BRAVE_SEARCH_API_KEY # https://brave.com/search/api/ portainer_url: str = "http://portainer:9000"
google_search_api_key: str = GOOGLE_SEARCH_API_KEY # https://console.cloud.google.com/ portainer_api_key: str = ""
google_search_engine_id: str = GOOGLE_SEARCH_ENGINE_ID # Custom Search Engine ID
# Infrastructure Management (from credentials.py) # Infrastructure Management (Nginx Proxy Manager)
portainer_url: str = PORTAINER_URL npm_url: str = "http://npm:81"
portainer_api_key: str = PORTAINER_API_KEY npm_email: str = ""
npm_password: str = ""
npm_url: str = NPM_URL
npm_email: str = NPM_EMAIL
npm_password: str = NPM_PASSWORD
# Home Assistant Configuration # Home Assistant Configuration
homeassistant_url: str = HOMEASSISTANT_URL homeassistant_url: str = "http://homeassistant:8123"
homeassistant_token: str = HOMEASSISTANT_TOKEN homeassistant_token: str = ""
homeassistant_timeout: int = 30 homeassistant_timeout: int = 30
# Core-AI Service (AI performance metrics) # Core-AI Service (AI performance metrics)
@@ -163,6 +139,7 @@ class Settings(BaseSettings):
class Config: class Config:
env_file = ".env" env_file = ".env"
case_sensitive = False case_sensitive = False
extra = "ignore" # Ignore extra env vars not defined in Settings
@lru_cache() @lru_cache()
-23
View File
@@ -1,23 +0,0 @@
"""
Infrastructure Credentials Template
INSTRUCTIONS:
1. Copy this file to credentials.py
2. Fill in your actual credentials
3. DO NOT commit credentials.py to version control (it's in .gitignore)
This file should be committed to the repository as a template.
"""
# Portainer Configuration
PORTAINER_URL = "http://localhost:8001"
PORTAINER_API_KEY = "ptr_your_api_token_here" # Create in Portainer UI: User menu → My account → Access tokens
# Nginx Proxy Manager Configuration
NPM_URL = "http://localhost:81"
NPM_EMAIL = "admin@example.com"
NPM_PASSWORD = "your_password_here"
# Home Assistant Configuration
HOMEASSISTANT_URL = "http://192.168.86.149:8123" # Or http://home-assistant:8123 in Docker
HOMEASSISTANT_TOKEN = "your_long_lived_access_token_here" # Create in HA: Profile → Long-Lived Access Tokens