Admin
commited on
Commit
·
dbcf976
1
Parent(s):
3eddf6f
api key 环境变量
Browse files- src/core/config.py +6 -2
- verify_api_key.py +23 -0
src/core/config.py
CHANGED
|
@@ -115,11 +115,15 @@ class Config:
|
|
| 115 |
# Mutable properties for runtime updates
|
| 116 |
@property
|
| 117 |
def api_key(self) -> str:
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
@api_key.setter
|
| 121 |
def api_key(self, value: str):
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
@property
|
| 125 |
def admin_password(self) -> str:
|
|
|
|
| 115 |
# Mutable properties for runtime updates
|
| 116 |
@property
|
| 117 |
def api_key(self) -> str:
|
| 118 |
+
import os
|
| 119 |
+
return os.getenv("API_KEY", "")
|
| 120 |
|
| 121 |
@api_key.setter
|
| 122 |
def api_key(self, value: str):
|
| 123 |
+
import os
|
| 124 |
+
os.environ["API_KEY"] = value
|
| 125 |
+
if "global" in self._config:
|
| 126 |
+
self._config["global"]["api_key"] = value
|
| 127 |
|
| 128 |
@property
|
| 129 |
def admin_password(self) -> str:
|
verify_api_key.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# Add src to path
|
| 7 |
+
sys.path.append(str(Path("e:/study/googleapi/1/google/src")))
|
| 8 |
+
|
| 9 |
+
# Mock environment variable
|
| 10 |
+
os.environ["API_KEY"] = "test_env_key_12345"
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from core.config import config
|
| 14 |
+
|
| 15 |
+
print(f"Current API Key: {config.api_key}")
|
| 16 |
+
|
| 17 |
+
if config.api_key == "test_env_key_12345":
|
| 18 |
+
print("SUCCESS: API Key read from environment variable.")
|
| 19 |
+
else:
|
| 20 |
+
print(f"FAILURE: Expected 'test_env_key_12345', got '{config.api_key}'")
|
| 21 |
+
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"ERROR: {e}")
|