huace-aigc-auth-client 1.1.20__py3-none-any.whl → 1.1.22__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.
- huace_aigc_auth_client/__init__.py +1 -1
- huace_aigc_auth_client/api_stats_collector.py +17 -2
- huace_aigc_auth_client/sdk.py +1 -0
- {huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/METADATA +1 -1
- huace_aigc_auth_client-1.1.22.dist-info/RECORD +12 -0
- huace_aigc_auth_client-1.1.20.dist-info/RECORD +0 -12
- {huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/WHEEL +0 -0
- {huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/licenses/LICENSE +0 -0
- {huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/top_level.txt +0 -0
|
@@ -16,6 +16,7 @@ class ApiStatsCollector:
|
|
|
16
16
|
def __init__(
|
|
17
17
|
self,
|
|
18
18
|
api_url: str,
|
|
19
|
+
app_id: str,
|
|
19
20
|
app_secret: str,
|
|
20
21
|
token: str,
|
|
21
22
|
batch_size: int = 10,
|
|
@@ -27,6 +28,7 @@ class ApiStatsCollector:
|
|
|
27
28
|
|
|
28
29
|
Args:
|
|
29
30
|
api_url: 统计接口 URL(如:http://auth.example.com/api/sdk/stats/report/batch)
|
|
31
|
+
app_id: 应用 ID
|
|
30
32
|
app_secret: 应用密钥
|
|
31
33
|
token: 用户访问令牌
|
|
32
34
|
batch_size: 批量提交大小
|
|
@@ -34,6 +36,7 @@ class ApiStatsCollector:
|
|
|
34
36
|
enabled: 是否启用
|
|
35
37
|
"""
|
|
36
38
|
self.api_url = api_url.rstrip('/')
|
|
39
|
+
self.app_id = app_id
|
|
37
40
|
self.app_secret = app_secret
|
|
38
41
|
self.token = token
|
|
39
42
|
self.batch_size = batch_size
|
|
@@ -83,6 +86,10 @@ class ApiStatsCollector:
|
|
|
83
86
|
if not self.enabled:
|
|
84
87
|
return
|
|
85
88
|
|
|
89
|
+
# 过滤重定向请求(3xx 状态码),这些通常是框架自动处理的,不应统计
|
|
90
|
+
if 300 <= status_code < 400:
|
|
91
|
+
return
|
|
92
|
+
|
|
86
93
|
try:
|
|
87
94
|
stat_data = {
|
|
88
95
|
'api_path': api_path,
|
|
@@ -90,8 +97,7 @@ class ApiStatsCollector:
|
|
|
90
97
|
'status_code': status_code,
|
|
91
98
|
'response_time': response_time,
|
|
92
99
|
'error_message': error_message,
|
|
93
|
-
'request_params': request_params
|
|
94
|
-
'timestamp': datetime.utcnow().isoformat()
|
|
100
|
+
'request_params': request_params
|
|
95
101
|
}
|
|
96
102
|
self.queue.put_nowait(stat_data)
|
|
97
103
|
except queue.Full:
|
|
@@ -138,6 +144,7 @@ class ApiStatsCollector:
|
|
|
138
144
|
|
|
139
145
|
try:
|
|
140
146
|
headers = {
|
|
147
|
+
'X-App-Id': self.app_id,
|
|
141
148
|
'X-App-Secret': self.app_secret,
|
|
142
149
|
'Authorization': f'Bearer {self.token}',
|
|
143
150
|
'Content-Type': 'application/json'
|
|
@@ -167,6 +174,7 @@ _global_collector: Optional[ApiStatsCollector] = None
|
|
|
167
174
|
|
|
168
175
|
def init_api_stats_collector(
|
|
169
176
|
api_url: str,
|
|
177
|
+
app_id: str,
|
|
170
178
|
app_secret: str,
|
|
171
179
|
token: str,
|
|
172
180
|
batch_size: int = 10,
|
|
@@ -178,6 +186,7 @@ def init_api_stats_collector(
|
|
|
178
186
|
|
|
179
187
|
Args:
|
|
180
188
|
api_url: 统计接口 URL
|
|
189
|
+
app_id: 应用 ID
|
|
181
190
|
app_secret: 应用密钥
|
|
182
191
|
token: 用户访问令牌
|
|
183
192
|
batch_size: 批量提交大小
|
|
@@ -190,6 +199,7 @@ def init_api_stats_collector(
|
|
|
190
199
|
global _global_collector
|
|
191
200
|
_global_collector = ApiStatsCollector(
|
|
192
201
|
api_url=api_url,
|
|
202
|
+
app_id=app_id,
|
|
193
203
|
app_secret=app_secret,
|
|
194
204
|
token=token,
|
|
195
205
|
batch_size=batch_size,
|
|
@@ -224,7 +234,12 @@ def collect_api_stat(
|
|
|
224
234
|
快捷方法:收集接口统计数据
|
|
225
235
|
|
|
226
236
|
使用全局收集器实例
|
|
237
|
+
注意:会自动过滤 3xx 重定向状态码的请求
|
|
227
238
|
"""
|
|
239
|
+
# 过滤重定向请求(3xx 状态码),这些通常是框架自动处理的,不应统计
|
|
240
|
+
if 300 <= status_code < 400:
|
|
241
|
+
return
|
|
242
|
+
|
|
228
243
|
collector = get_api_stats_collector()
|
|
229
244
|
if collector:
|
|
230
245
|
collector.collect(
|
huace_aigc_auth_client/sdk.py
CHANGED
|
@@ -585,6 +585,7 @@ class AuthMiddleware:
|
|
|
585
585
|
from .api_stats_collector import init_api_stats_collector
|
|
586
586
|
self.stats_collector = init_api_stats_collector(
|
|
587
587
|
api_url=self.stats_api_url,
|
|
588
|
+
app_id=self.client.app_id,
|
|
588
589
|
app_secret=self.client.app_secret,
|
|
589
590
|
token=token,
|
|
590
591
|
batch_size=10,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
huace_aigc_auth_client/__init__.py,sha256=ci3wft3OSN-HynwYWyHtgyECiMx9c7TGtkzmALxf6jQ,4630
|
|
2
|
+
huace_aigc_auth_client/api_stats_collector.py,sha256=gVtbcmLv83KdE4jwXTqPaeuKZMz8ET7QdlbSqdQ_KNY,9023
|
|
3
|
+
huace_aigc_auth_client/legacy_adapter.py,sha256=TVCBAKejE2z2HQFsEwDW8LMiaIkXNfz3Mxv6_E-UJFY,24102
|
|
4
|
+
huace_aigc_auth_client/sdk.py,sha256=03OzVIhawoBXWNfq8AUfdUEPLlQMrBhfsNSYANOrnwg,31346
|
|
5
|
+
huace_aigc_auth_client/user_context.py,sha256=KzevYLsLv1hv8rlvRw83FT-HugeoBJSJ1Pi56iLWyTE,5592
|
|
6
|
+
huace_aigc_auth_client/webhook.py,sha256=XQZYEbMoqIdqZWCGSTcedeDKJpDbUVSq5g08g-6Qucg,4124
|
|
7
|
+
huace_aigc_auth_client/webhook_flask.py,sha256=Iosu4dBtRhQZM_ytn-bn82MpVsyOiV28FBnt7Tfh31U,7225
|
|
8
|
+
huace_aigc_auth_client-1.1.22.dist-info/licenses/LICENSE,sha256=z7dgC7KljhBLNvKjN15391nMj3aLt0gbud8-Yf1F8EQ,1063
|
|
9
|
+
huace_aigc_auth_client-1.1.22.dist-info/METADATA,sha256=o2KeTOZF1PSqR4_SgX_iD_wD3dR2DLJARnwl0Vqk5j8,23629
|
|
10
|
+
huace_aigc_auth_client-1.1.22.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
11
|
+
huace_aigc_auth_client-1.1.22.dist-info/top_level.txt,sha256=kbv0nQ6PQ0JVneWPH7O2AbtlJnP7AjvFJ6JjM6ZEBxo,23
|
|
12
|
+
huace_aigc_auth_client-1.1.22.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
huace_aigc_auth_client/__init__.py,sha256=e-Y0M75DKW4t-hhipxgH_UDhoVSdH1uKFmJKyacyRJo,4630
|
|
2
|
-
huace_aigc_auth_client/api_stats_collector.py,sha256=VL_z-3WUWhEkAKDhGnKX0H-nNUn3x2IO_1FASsFA-Ss,8511
|
|
3
|
-
huace_aigc_auth_client/legacy_adapter.py,sha256=TVCBAKejE2z2HQFsEwDW8LMiaIkXNfz3Mxv6_E-UJFY,24102
|
|
4
|
-
huace_aigc_auth_client/sdk.py,sha256=0E0EmfLVxpOI5rOiVdAGcFzajdNZnDgjwrmOX7aYzGc,31303
|
|
5
|
-
huace_aigc_auth_client/user_context.py,sha256=KzevYLsLv1hv8rlvRw83FT-HugeoBJSJ1Pi56iLWyTE,5592
|
|
6
|
-
huace_aigc_auth_client/webhook.py,sha256=XQZYEbMoqIdqZWCGSTcedeDKJpDbUVSq5g08g-6Qucg,4124
|
|
7
|
-
huace_aigc_auth_client/webhook_flask.py,sha256=Iosu4dBtRhQZM_ytn-bn82MpVsyOiV28FBnt7Tfh31U,7225
|
|
8
|
-
huace_aigc_auth_client-1.1.20.dist-info/licenses/LICENSE,sha256=z7dgC7KljhBLNvKjN15391nMj3aLt0gbud8-Yf1F8EQ,1063
|
|
9
|
-
huace_aigc_auth_client-1.1.20.dist-info/METADATA,sha256=NkVUBXJLpANzcTh_VpBm2Lm1UquzxgjCK_2l-Xj6Kfo,23629
|
|
10
|
-
huace_aigc_auth_client-1.1.20.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
11
|
-
huace_aigc_auth_client-1.1.20.dist-info/top_level.txt,sha256=kbv0nQ6PQ0JVneWPH7O2AbtlJnP7AjvFJ6JjM6ZEBxo,23
|
|
12
|
-
huace_aigc_auth_client-1.1.20.dist-info/RECORD,,
|
|
File without changes
|
{huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{huace_aigc_auth_client-1.1.20.dist-info → huace_aigc_auth_client-1.1.22.dist-info}/top_level.txt
RENAMED
|
File without changes
|