huace-aigc-auth-client 1.1.9__tar.gz → 1.1.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {huace_aigc_auth_client-1.1.9/huace_aigc_auth_client.egg-info → huace_aigc_auth_client-1.1.11}/PKG-INFO +1 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/__init__.py +45 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/legacy_adapter.py +44 -19
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/sdk.py +3 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/webhook.py +3 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/webhook_flask.py +3 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11/huace_aigc_auth_client.egg-info}/PKG-INFO +1 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/pyproject.toml +1 -1
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/LICENSE +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/MANIFEST.in +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/QUICK_START.txt +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/README.md +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client.egg-info/SOURCES.txt +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client.egg-info/dependency_links.txt +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client.egg-info/requires.txt +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client.egg-info/top_level.txt +0 -0
- {huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/setup.cfg +0 -0
{huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/__init__.py
RENAMED
|
@@ -78,6 +78,48 @@ from .webhook_flask import (
|
|
|
78
78
|
register_flask_webhook_routes,
|
|
79
79
|
)
|
|
80
80
|
|
|
81
|
+
def setLogger(log):
|
|
82
|
+
"""
|
|
83
|
+
统一设置所有模块的 logger
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
log: logging.Logger 实例
|
|
87
|
+
|
|
88
|
+
使用示例:
|
|
89
|
+
import logging
|
|
90
|
+
from huace_aigc_auth_client import setLogger
|
|
91
|
+
|
|
92
|
+
logger = logging.getLogger("my_app")
|
|
93
|
+
logger.setLevel(logging.INFO)
|
|
94
|
+
|
|
95
|
+
# 设置 SDK 所有模块使用该 logger
|
|
96
|
+
setLogger(logger)
|
|
97
|
+
"""
|
|
98
|
+
try:
|
|
99
|
+
from .sdk import setLogger as sdk_setLogger
|
|
100
|
+
sdk_setLogger(log)
|
|
101
|
+
except Exception as e:
|
|
102
|
+
print(f"Failed to set logger for sdk module: {e}")
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
from .legacy_adapter import setLogger as legacy_setLogger
|
|
106
|
+
legacy_setLogger(log)
|
|
107
|
+
except Exception as e:
|
|
108
|
+
print(f"Failed to set logger for legacy_adapter module: {e}")
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
from .webhook import setLogger as webhook_setLogger
|
|
112
|
+
webhook_setLogger(log)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
print(f"Failed to set logger for webhook module: {e}")
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
from .webhook_flask import setLogger as webhook_flask_setLogger
|
|
118
|
+
webhook_flask_setLogger(log)
|
|
119
|
+
except Exception as e:
|
|
120
|
+
print(f"Failed to set logger for webhook_flask module: {e}")
|
|
121
|
+
|
|
122
|
+
|
|
81
123
|
__all__ = [
|
|
82
124
|
# 核心类
|
|
83
125
|
"AigcAuthClient",
|
|
@@ -105,5 +147,7 @@ __all__ = [
|
|
|
105
147
|
# Webhook 接收 (Flask)
|
|
106
148
|
"create_flask_webhook_blueprint",
|
|
107
149
|
"register_flask_webhook_routes",
|
|
150
|
+
# Logger 设置
|
|
151
|
+
"setLogger",
|
|
108
152
|
]
|
|
109
|
-
__version__ = "1.1.
|
|
153
|
+
__version__ = "1.1.11"
|
|
@@ -20,7 +20,9 @@ from enum import Enum
|
|
|
20
20
|
from abc import ABC, abstractmethod
|
|
21
21
|
|
|
22
22
|
logger = logging.getLogger(__name__)
|
|
23
|
-
|
|
23
|
+
def setLogger(log):
|
|
24
|
+
global logger
|
|
25
|
+
logger = log
|
|
24
26
|
|
|
25
27
|
class PasswordMode(Enum):
|
|
26
28
|
"""密码处理模式"""
|
|
@@ -214,6 +216,41 @@ class LegacySystemAdapter(ABC):
|
|
|
214
216
|
user_id = await self._create_user_async(user_data)
|
|
215
217
|
return {"created": True, "user_id": user_id}
|
|
216
218
|
|
|
219
|
+
async def sync_user_to_auth(self, legacy_user: LegacyUserData) -> Dict[str, Any]:
|
|
220
|
+
"""同步单个旧系统用户到 aigc-auth(默认实现)
|
|
221
|
+
|
|
222
|
+
子类可以选择性覆盖此方法以自定义同步逻辑。
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
legacy_user: 旧系统用户数据
|
|
226
|
+
Returns:
|
|
227
|
+
Dict: 同步结果
|
|
228
|
+
"""
|
|
229
|
+
if not self.auth_client:
|
|
230
|
+
logger.error("auth_client is required for sync_user_to_auth")
|
|
231
|
+
raise ValueError("auth_client is required for sync_user_to_auth. Please provide it in constructor.")
|
|
232
|
+
|
|
233
|
+
logger.info(f"Syncing legacy user to auth: {legacy_user.to_dict()}")
|
|
234
|
+
auth_data = self.transform_legacy_to_auth(legacy_user)
|
|
235
|
+
|
|
236
|
+
# 获取密码(支持新的元组返回格式)
|
|
237
|
+
password_result = self.get_password_for_sync(legacy_user)
|
|
238
|
+
if isinstance(password_result, tuple):
|
|
239
|
+
password, is_hashed = password_result
|
|
240
|
+
else:
|
|
241
|
+
password, is_hashed = password_result, False
|
|
242
|
+
|
|
243
|
+
# 根据是否已加密选择不同的字段
|
|
244
|
+
if is_hashed:
|
|
245
|
+
auth_data["password_hashed"] = password
|
|
246
|
+
else:
|
|
247
|
+
auth_data["password"] = password
|
|
248
|
+
|
|
249
|
+
result = await self.auth_client.sync_user_to_auth(auth_data)
|
|
250
|
+
logger.info(f"Sync result for user {legacy_user.get('username')}: {result}")
|
|
251
|
+
|
|
252
|
+
return result
|
|
253
|
+
|
|
217
254
|
async def batch_sync_to_auth(self) -> Dict[str, Any]:
|
|
218
255
|
"""批量同步旧系统用户到 aigc-auth(默认实现)
|
|
219
256
|
|
|
@@ -239,22 +276,7 @@ class LegacySystemAdapter(ABC):
|
|
|
239
276
|
|
|
240
277
|
for user in users:
|
|
241
278
|
try:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
# 获取密码(支持新的元组返回格式)
|
|
245
|
-
password_result = self.get_password_for_sync(user)
|
|
246
|
-
if isinstance(password_result, tuple):
|
|
247
|
-
password, is_hashed = password_result
|
|
248
|
-
else:
|
|
249
|
-
password, is_hashed = password_result, False
|
|
250
|
-
|
|
251
|
-
# 根据是否已加密选择不同的字段
|
|
252
|
-
if is_hashed:
|
|
253
|
-
auth_data["password_hashed"] = password
|
|
254
|
-
else:
|
|
255
|
-
auth_data["password"] = password
|
|
256
|
-
|
|
257
|
-
result = self.auth_client.sync_user_to_auth(auth_data)
|
|
279
|
+
result = await self.sync_user_to_auth(user)
|
|
258
280
|
logger.info(f"Sync result for user {user.get('username')}: {result}")
|
|
259
281
|
|
|
260
282
|
if result.get("success"):
|
|
@@ -297,12 +319,15 @@ class LegacySystemAdapter(ABC):
|
|
|
297
319
|
legacy_data = self.transform_auth_to_legacy(data)
|
|
298
320
|
|
|
299
321
|
# 获取密码
|
|
300
|
-
password_result = self.get_password_for_sync()
|
|
322
|
+
password_result = self.get_password_for_sync(legacy_data)
|
|
301
323
|
if isinstance(password_result, tuple):
|
|
302
324
|
password, is_hashed = password_result
|
|
303
325
|
else:
|
|
304
326
|
password, is_hashed = password_result, False
|
|
305
|
-
|
|
327
|
+
if is_hashed:
|
|
328
|
+
legacy_data["password_hashed"] = password
|
|
329
|
+
else:
|
|
330
|
+
legacy_data["password"] = password
|
|
306
331
|
|
|
307
332
|
# 创建或更新用户
|
|
308
333
|
logger.info(f"Handling {event} event for user: {legacy_data}")
|
{huace_aigc_auth_client-1.1.9 → huace_aigc_auth_client-1.1.11}/huace_aigc_auth_client/webhook.py
RENAMED
|
@@ -13,7 +13,9 @@ from typing import Callable, Awaitable, Dict, Any, Optional
|
|
|
13
13
|
from fastapi import APIRouter, Request, HTTPException
|
|
14
14
|
|
|
15
15
|
logger = logging.getLogger(__name__)
|
|
16
|
-
|
|
16
|
+
def setLogger(log):
|
|
17
|
+
global logger
|
|
18
|
+
logger = log
|
|
17
19
|
|
|
18
20
|
def verify_webhook_signature(payload: bytes, signature: str, secret: str) -> bool:
|
|
19
21
|
"""
|
|
@@ -14,7 +14,9 @@ from typing import Callable, Dict, Any, Optional
|
|
|
14
14
|
from flask import Blueprint, request, jsonify
|
|
15
15
|
|
|
16
16
|
logger = logging.getLogger(__name__)
|
|
17
|
-
|
|
17
|
+
def setLogger(log):
|
|
18
|
+
global logger
|
|
19
|
+
logger = log
|
|
18
20
|
|
|
19
21
|
def verify_webhook_signature(payload: bytes, signature: str, secret: str) -> bool:
|
|
20
22
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|