aspyx-service 0.10.7__py3-none-any.whl → 0.11.0__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.
Potentially problematic release.
This version of aspyx-service might be problematic. Click here for more details.
- aspyx_service/__init__.py +5 -0
- aspyx_service/channels.py +30 -3
- aspyx_service/healthcheck.py +2 -2
- aspyx_service/protobuf.py +1083 -0
- aspyx_service/restchannel.py +23 -3
- aspyx_service/server.py +82 -32
- aspyx_service/service.py +9 -4
- {aspyx_service-0.10.7.dist-info → aspyx_service-0.11.0.dist-info}/METADATA +3 -2
- aspyx_service-0.11.0.dist-info/RECORD +14 -0
- aspyx_service-0.10.7.dist-info/RECORD +0 -13
- {aspyx_service-0.10.7.dist-info → aspyx_service-0.11.0.dist-info}/WHEEL +0 -0
- {aspyx_service-0.10.7.dist-info → aspyx_service-0.11.0.dist-info}/licenses/LICENSE +0 -0
aspyx_service/__init__.py
CHANGED
|
@@ -12,6 +12,7 @@ from .healthcheck import health_checks, health_check, HealthCheckManager, Health
|
|
|
12
12
|
from .restchannel import RestChannel, post, get, put, delete, QueryParam, Body, rest
|
|
13
13
|
from .session import Session, SessionManager, SessionContext
|
|
14
14
|
from .authorization import AuthorizationManager, AbstractAuthorizationFactory
|
|
15
|
+
from .protobuf import ProtobufManager
|
|
15
16
|
|
|
16
17
|
@module()
|
|
17
18
|
class ServiceModule:
|
|
@@ -48,6 +49,10 @@ __all__ = [
|
|
|
48
49
|
"MissingTokenException",
|
|
49
50
|
"AuthorizationException",
|
|
50
51
|
|
|
52
|
+
# protobuf
|
|
53
|
+
|
|
54
|
+
"ProtobufManager",
|
|
55
|
+
|
|
51
56
|
# authorization
|
|
52
57
|
|
|
53
58
|
"AuthorizationManager",
|
aspyx_service/channels.py
CHANGED
|
@@ -196,6 +196,32 @@ class HTTPXChannel(Channel):
|
|
|
196
196
|
|
|
197
197
|
headers["Authorization"] = f"Bearer {token}"
|
|
198
198
|
|
|
199
|
+
### TEST
|
|
200
|
+
|
|
201
|
+
print_size = False
|
|
202
|
+
if print_size:
|
|
203
|
+
request = self.get_client().build_request(http_method, url, params=params, json=json, headers=headers, timeout=timeout, content=content)
|
|
204
|
+
# Measure body
|
|
205
|
+
body_size = len(request.content or b"")
|
|
206
|
+
|
|
207
|
+
# Measure headers (as raw bytes)
|
|
208
|
+
headers_size = sum(
|
|
209
|
+
len(k.encode()) + len(v.encode()) + 4 # ": " + "\r\n"
|
|
210
|
+
for k, v in request.headers.items()
|
|
211
|
+
) + 2 # final \r\n
|
|
212
|
+
|
|
213
|
+
# Optional: estimate request line
|
|
214
|
+
request_line = f"{request.method} {request.url.raw_path.decode()} HTTP/1.1\r\n".encode()
|
|
215
|
+
request_line_size = len(request_line)
|
|
216
|
+
|
|
217
|
+
# Total estimated size
|
|
218
|
+
total_size = request_line_size + headers_size + body_size
|
|
219
|
+
|
|
220
|
+
print(f"Request line: {request_line_size} bytes")
|
|
221
|
+
print(f"Headers: {headers_size} bytes")
|
|
222
|
+
print(f"Body: {body_size} bytes")
|
|
223
|
+
print(f"Total request size: {total_size} bytes")
|
|
224
|
+
|
|
199
225
|
try:
|
|
200
226
|
response = self.get_client().request(http_method, url, params=params, json=json, headers=headers, timeout=timeout, content=content)
|
|
201
227
|
response.raise_for_status()
|
|
@@ -397,10 +423,11 @@ class DispatchMSPackChannel(HTTPXChannel):
|
|
|
397
423
|
if "invalid_token" in www_auth:
|
|
398
424
|
if 'expired' in www_auth:
|
|
399
425
|
raise TokenExpiredException() from e
|
|
400
|
-
|
|
426
|
+
|
|
427
|
+
if 'missing' in www_auth:
|
|
401
428
|
raise MissingTokenException() from e
|
|
402
|
-
|
|
403
|
-
|
|
429
|
+
|
|
430
|
+
raise InvalidTokenException() from e
|
|
404
431
|
|
|
405
432
|
raise RemoteServiceException(str(e)) from e
|
|
406
433
|
except httpx.HTTPError as e:
|
aspyx_service/healthcheck.py
CHANGED
|
@@ -15,7 +15,7 @@ from aspyx.reflection import Decorators, TypeDescriptor
|
|
|
15
15
|
|
|
16
16
|
def health_checks():
|
|
17
17
|
"""
|
|
18
|
-
Instances of classes that are annotated with @
|
|
18
|
+
Instances of classes that are annotated with @health_checks contain healt mehtods.
|
|
19
19
|
"""
|
|
20
20
|
def decorator(cls):
|
|
21
21
|
Decorators.add(cls, health_checks)
|
|
@@ -31,7 +31,7 @@ def health_checks():
|
|
|
31
31
|
|
|
32
32
|
def health_check(name="", cache = 0, fail_if_slower_than = 0):
|
|
33
33
|
"""
|
|
34
|
-
Methods annotated with `@
|
|
34
|
+
Methods annotated with `@health_check` specify health checks that will be executed.
|
|
35
35
|
"""
|
|
36
36
|
def decorator(func):
|
|
37
37
|
Decorators.add(func, health_check, name, cache, fail_if_slower_than)
|