mirror of
https://github.com/sstent/FitTrack_GarminSync.git
synced 2026-01-25 00:21:58 +00:00
- Create full CLI application with authentication, sync triggering, and status checking - Implement MFA support for secure authentication - Add token management with secure local storage - Create API client for backend communication - Implement data models for User Session, Sync Job, and Authentication Token - Add command-line interface with auth and sync commands - Include unit and integration tests - Follow project constitution standards for Python 3.13, type hints, and code quality - Support multiple output formats (table, JSON, CSV)
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
import os
|
|
from pathlib import Path
|
|
from typing import Any, Dict, Optional
|
|
|
|
import yaml
|
|
|
|
|
|
class ConfigManager:
|
|
"""Configuration management utilities for YAML config"""
|
|
|
|
def __init__(self, config_path: Optional[Path] = None):
|
|
if config_path is None:
|
|
# Use default location in user's home directory
|
|
self.config_path = Path.home() / ".garmin-sync" / "config.yaml"
|
|
self.config_path.parent.mkdir(exist_ok=True)
|
|
else:
|
|
self.config_path = config_path
|
|
self.config_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
self.config = self._load_config()
|
|
|
|
def _load_config(self) -> Dict[str, Any]:
|
|
"""Load configuration from YAML file"""
|
|
if self.config_path.exists():
|
|
with open(self.config_path, "r") as f:
|
|
return yaml.safe_load(f) or {}
|
|
else:
|
|
# Return default configuration
|
|
default_config = {
|
|
"api_base_url": "https://api.garmin.com",
|
|
"default_timeout": 30,
|
|
"output_format": "table", # Options: table, json, csv
|
|
"remember_login": True,
|
|
}
|
|
self._save_config(default_config)
|
|
return default_config
|
|
|
|
def _save_config(self, config: Dict[str, Any]) -> None:
|
|
"""Save configuration to YAML file"""
|
|
with open(self.config_path, "w") as f:
|
|
yaml.dump(config, f)
|
|
|
|
def get(self, key: str, default: Any = None) -> Any:
|
|
"""Get a configuration value"""
|
|
return self.config.get(key, default)
|
|
|
|
def set(self, key: str, value: Any) -> None:
|
|
"""Set a configuration value"""
|
|
self.config[key] = value
|
|
self._save_config(self.config)
|
|
|
|
def update(self, updates: Dict[str, Any]) -> None:
|
|
"""Update multiple configuration values"""
|
|
self.config.update(updates)
|
|
self._save_config(self.config)
|