huace-aigc-auth-client 1.1.9__py3-none-any.whl → 1.1.11__py3-none-any.whl

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.
@@ -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.9"
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
- auth_data = self.transform_legacy_to_auth(user)
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
- legacy_data["password"] = password
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}")
@@ -19,6 +19,9 @@ from typing import Optional, List, Dict, Any, Callable, Tuple
19
19
  from dataclasses import dataclass
20
20
 
21
21
  logger = logging.getLogger(__name__)
22
+ def setLogger(log):
23
+ global logger
24
+ logger = log
22
25
 
23
26
  # 尝试加载 .env 文件
24
27
  try:
@@ -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
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: huace-aigc-auth-client
3
- Version: 1.1.9
3
+ Version: 1.1.11
4
4
  Summary: 华策AIGC Auth Client - 提供 Token 验证、用户信息获取、权限检查、旧系统接入等功能
5
5
  Author-email: Huace <support@huace.com>
6
6
  License: MIT
@@ -0,0 +1,10 @@
1
+ huace_aigc_auth_client/__init__.py,sha256=Cuc0QAkMWyGhBlu80XWDZMaoVjrXkrwv_YA7kuMz2C4,3789
2
+ huace_aigc_auth_client/legacy_adapter.py,sha256=1YRfa71IP-LkUxMoFB5uFhloikXIl3ZE01fQ_CXppBs,23455
3
+ huace_aigc_auth_client/sdk.py,sha256=ypClZfQm4Ux4db8XDP51I5Cuk1Uc9F2VPgECpXXphkQ,23272
4
+ huace_aigc_auth_client/webhook.py,sha256=XQZYEbMoqIdqZWCGSTcedeDKJpDbUVSq5g08g-6Qucg,4124
5
+ huace_aigc_auth_client/webhook_flask.py,sha256=Iosu4dBtRhQZM_ytn-bn82MpVsyOiV28FBnt7Tfh31U,7225
6
+ huace_aigc_auth_client-1.1.11.dist-info/licenses/LICENSE,sha256=z7dgC7KljhBLNvKjN15391nMj3aLt0gbud8-Yf1F8EQ,1063
7
+ huace_aigc_auth_client-1.1.11.dist-info/METADATA,sha256=FucMmOMOGE2HPPXfS13TwdwXBNJw8dEDgHB3V3P0d0o,22971
8
+ huace_aigc_auth_client-1.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ huace_aigc_auth_client-1.1.11.dist-info/top_level.txt,sha256=kbv0nQ6PQ0JVneWPH7O2AbtlJnP7AjvFJ6JjM6ZEBxo,23
10
+ huace_aigc_auth_client-1.1.11.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- huace_aigc_auth_client/__init__.py,sha256=U48dzde3qmEDmuwqCiOGpKrEFSJbt_vC-Fjt1PLNEeQ,2549
2
- huace_aigc_auth_client/legacy_adapter.py,sha256=YV7sOFhCr4SDfDUHrJMEy4JBjUgapDfzyvZK82elhQk,22538
3
- huace_aigc_auth_client/sdk.py,sha256=ha1e_MSzLCsIMrdgcKSh-V5hTVR1rqqrIMWcDmtVMKs,23217
4
- huace_aigc_auth_client/webhook.py,sha256=m-mjXNNqrUClrNpOHRBzty0XKFDBuZp4e_PgLd2t0aA,4070
5
- huace_aigc_auth_client/webhook_flask.py,sha256=JiIsAr6INjGNKVzamyHDWVl7tzdCPOR1WguMLAmt6iI,7171
6
- huace_aigc_auth_client-1.1.9.dist-info/licenses/LICENSE,sha256=z7dgC7KljhBLNvKjN15391nMj3aLt0gbud8-Yf1F8EQ,1063
7
- huace_aigc_auth_client-1.1.9.dist-info/METADATA,sha256=ARbnsmp4fQKwSTFDXKA8qgEKxXX10L4yEBGokiFR8aU,22970
8
- huace_aigc_auth_client-1.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- huace_aigc_auth_client-1.1.9.dist-info/top_level.txt,sha256=kbv0nQ6PQ0JVneWPH7O2AbtlJnP7AjvFJ6JjM6ZEBxo,23
10
- huace_aigc_auth_client-1.1.9.dist-info/RECORD,,