-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
56 lines (40 loc) · 1.46 KB
/
config.py
File metadata and controls
56 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Configuration management for FAC CLI."""
import os
import sys
from typing import Dict, Optional
try:
from dotenv import load_dotenv
except ImportError:
load_dotenv = None
def load() -> None:
"""Load environment variables from .env file if available."""
if load_dotenv:
load_dotenv()
def get(key: str, default: Optional[str] = None) -> Optional[str]:
"""Get environment variable value."""
return os.getenv(key, default)
def require(key: str) -> str:
"""Get required environment variable or exit with error."""
value = get(key)
if not value:
error(f"Required environment variable {key} not set")
return value
def validate() -> Dict[str, str]:
"""Validate required configuration and return config dict."""
load()
config = {}
required_vars = ["AIRTABLE_API_KEY", "AIRTABLE_VIEW_URL"]
for var in required_vars:
config[var] = require(var)
# Optional configuration
config["GR_COLUMNS"] = get("GR_COLUMNS", "Name,Email,Status,Date")
config["GR_HEADERS"] = get(
"GR_HEADERS", "Student Name,Email Address,Current Status,Last Updated"
)
config["FAC_CLI_DEBUG"] = get("FAC_CLI_DEBUG", "false").lower() == "true"
return config
def error(message: str, exit_code: int = 1) -> None:
"""Print error message and exit."""
print(f"Error: {message}", file=sys.stderr)
print("Tip: Copy .env.example to .env and add your credentials", file=sys.stderr)
sys.exit(exit_code)