konecty_sdk_python 2.1.1__py3-none-any.whl → 2.1.2__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.
- KonectySdkPython/lib/exceptions.py +16 -0
- KonectySdkPython/lib/services/auth.py +34 -5
- {konecty_sdk_python-2.1.1.dist-info → konecty_sdk_python-2.1.2.dist-info}/METADATA +1 -1
- {konecty_sdk_python-2.1.1.dist-info → konecty_sdk_python-2.1.2.dist-info}/RECORD +6 -6
- {konecty_sdk_python-2.1.1.dist-info → konecty_sdk_python-2.1.2.dist-info}/WHEEL +0 -0
- {konecty_sdk_python-2.1.1.dist-info → konecty_sdk_python-2.1.2.dist-info}/entry_points.txt +0 -0
|
@@ -13,6 +13,22 @@ class KonectyAPIError(KonectyError):
|
|
|
13
13
|
pass
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class KonectyGoogleSessionError(KonectyAPIError):
|
|
17
|
+
"""
|
|
18
|
+
Raised by exchange_google_code. Carries the machine-readable ``code`` from
|
|
19
|
+
``errors[0].code`` so callers can branch or translate without parsing the
|
|
20
|
+
message; ``failed`` covers unreadable or unrecognised bodies.
|
|
21
|
+
|
|
22
|
+
Subclasses KonectyAPIError so existing ``except KonectyAPIError`` keeps working.
|
|
23
|
+
|
|
24
|
+
Mirrors KonectyGoogleSessionError in the TypeScript SDK — keep both in sync.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, code: str, message: str) -> None:
|
|
28
|
+
super().__init__(message)
|
|
29
|
+
self.code = code
|
|
30
|
+
|
|
31
|
+
|
|
16
32
|
class KonectyValidationError(KonectyError):
|
|
17
33
|
"""Raised for validation errors."""
|
|
18
34
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from typing import Any, Dict, Optional, Union
|
|
4
4
|
from urllib.parse import quote, urlencode
|
|
5
5
|
|
|
6
|
-
from ..exceptions import KonectyAPIError
|
|
6
|
+
from ..exceptions import KonectyAPIError, KonectyGoogleSessionError
|
|
7
7
|
from .base import BaseService
|
|
8
8
|
|
|
9
9
|
GOOGLE_START_PATH = "/api/auth/google/start"
|
|
@@ -15,6 +15,29 @@ GOOGLE_SESSION_PATH = "/api/auth/google/session"
|
|
|
15
15
|
LOGIN_OPTIONS_PATH = "/api/auth/login-options"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
_GOOGLE_SESSION_ERROR_CODES = (
|
|
19
|
+
"invalid_code",
|
|
20
|
+
"expired_code",
|
|
21
|
+
"user_not_found",
|
|
22
|
+
"user_inactive",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _first_error_code(error: KonectyAPIError) -> str:
|
|
27
|
+
"""
|
|
28
|
+
Extract the first recognised ``errors[].code``; ``failed`` when there is none.
|
|
29
|
+
|
|
30
|
+
Same set and same fallback as the TypeScript SDK, so both raise the same code
|
|
31
|
+
for the same response.
|
|
32
|
+
"""
|
|
33
|
+
errors = error.args[0] if error.args else None
|
|
34
|
+
if isinstance(errors, list):
|
|
35
|
+
for item in errors:
|
|
36
|
+
if isinstance(item, dict) and item.get("code") in _GOOGLE_SESSION_ERROR_CODES:
|
|
37
|
+
return str(item["code"])
|
|
38
|
+
return "failed"
|
|
39
|
+
|
|
40
|
+
|
|
18
41
|
def _first_error_message(error: KonectyAPIError) -> str:
|
|
19
42
|
"""Extract errors[0].message from a KonectyAPIError raised by the HTTP layer."""
|
|
20
43
|
errors = error.args[0] if error.args else None
|
|
@@ -74,8 +97,10 @@ class AuthService(BaseService):
|
|
|
74
97
|
POST /api/auth/google/session. Exchanges the single-use code (TTL 60s) for a session.
|
|
75
98
|
|
|
76
99
|
On success the returned authId is adopted by the client, so following requests
|
|
77
|
-
are authenticated. On error raises
|
|
78
|
-
|
|
100
|
+
are authenticated. On error raises KonectyGoogleSessionError — errors[0].message
|
|
101
|
+
as the message plus the machine-readable ``code`` — and leaves the client
|
|
102
|
+
authentication state untouched. The error subclasses KonectyAPIError, so callers
|
|
103
|
+
catching that keep working.
|
|
79
104
|
"""
|
|
80
105
|
payload: Dict[str, Any] = {"code": code}
|
|
81
106
|
if geolocation is not None:
|
|
@@ -90,11 +115,15 @@ class AuthService(BaseService):
|
|
|
90
115
|
try:
|
|
91
116
|
response = await self._post(GOOGLE_SESSION_PATH, json=payload)
|
|
92
117
|
except KonectyAPIError as error:
|
|
93
|
-
raise
|
|
118
|
+
raise KonectyGoogleSessionError(
|
|
119
|
+
_first_error_code(error), _first_error_message(error)
|
|
120
|
+
) from error
|
|
94
121
|
|
|
95
122
|
auth_id = response.get("authId") if isinstance(response, dict) else None
|
|
96
123
|
if not isinstance(auth_id, str) or not auth_id:
|
|
97
|
-
raise
|
|
124
|
+
raise KonectyGoogleSessionError(
|
|
125
|
+
"failed", "Google session response has no authId"
|
|
126
|
+
)
|
|
98
127
|
|
|
99
128
|
self._client.set_auth_id(auth_id)
|
|
100
129
|
return response
|
|
@@ -5,7 +5,7 @@ KonectySdkPython/cli/backup.py,sha256=rcla3EWfPsy-vWgmDK844EaM5u3h7JF-u7-b2HUBMg
|
|
|
5
5
|
KonectySdkPython/cli/pull.py,sha256=n4gIkKtuEpPKULb3zcYu5tZlBLbt_4oNQDeu2l6tHxU,9529
|
|
6
6
|
KonectySdkPython/lib/__init__.py,sha256=Du8jLNfFG1bQuHX5u7pAhbyV9TjC7Ie9K1Xo1KSUqqc,995
|
|
7
7
|
KonectySdkPython/lib/client.py,sha256=i-7goKqsH-jvwxZfGeipTRFByOBAOhMHkuhjjdEN3kE,34034
|
|
8
|
-
KonectySdkPython/lib/exceptions.py,sha256=
|
|
8
|
+
KonectySdkPython/lib/exceptions.py,sha256=RQ6H_zgbF8yeII1F75wCIEJ1LfO4lWfY5hnK30cwETY,1107
|
|
9
9
|
KonectySdkPython/lib/file_manager.py,sha256=CLpOJWdA1tb2iq0qOIeRyEEIuACRq9tIo7Rls1YT2ig,9986
|
|
10
10
|
KonectySdkPython/lib/filters.py,sha256=PsFaUFCEyKgxgzD566LdTLvuMJevoF_i9U1WnpJZzPQ,4482
|
|
11
11
|
KonectySdkPython/lib/http.py,sha256=atwyuKSFniulvAspi_VhinUhtPJGNyZYkIkaEgqfIqo,3377
|
|
@@ -19,7 +19,7 @@ KonectySdkPython/lib/feature_types/kpi.py,sha256=67RpwwwnzU8piIPRyFb6Kn0hqSRpT9R
|
|
|
19
19
|
KonectySdkPython/lib/feature_types/query_json.py,sha256=yZgMPmkMdiBLm-dIrmU1AeZe5G9zQLwLtKUPMb7IOhU,8139
|
|
20
20
|
KonectySdkPython/lib/services/__init__.py,sha256=fluQuxs6LnIZwcjYTuKNeXCFTKuNF3At3X19fIB68p8,121
|
|
21
21
|
KonectySdkPython/lib/services/aggregation.py,sha256=igK1mleMFU2_rDQCAU1yKyvDoOjhTO1SO0Nn4T_DokA,5610
|
|
22
|
-
KonectySdkPython/lib/services/auth.py,sha256=
|
|
22
|
+
KonectySdkPython/lib/services/auth.py,sha256=seb2QgdeWT_ALcVLR8bDMgO1ycI9dz75OhuIjahzy7o,5173
|
|
23
23
|
KonectySdkPython/lib/services/base.py,sha256=tdVyWb7Y77cBhVc8Mz2BQMN6kAyZIohoxBxdwDnRsYs,1820
|
|
24
24
|
KonectySdkPython/lib/services/change_user.py,sha256=ce6mcDYMP6eWxW0bEtzlVf7wbppGHCkGwdgo2jJFJOQ,2548
|
|
25
25
|
KonectySdkPython/lib/services/comments.py,sha256=RNevCg4de2FWNk7mD60-pk3r8f2sJ1NLoolD2iNMidg,3033
|
|
@@ -29,7 +29,7 @@ KonectySdkPython/lib/services/notifications.py,sha256=7AtCBbBl-YAz_RBIW6bzoKvuws
|
|
|
29
29
|
KonectySdkPython/lib/services/query.py,sha256=vCqbf0QdV8Blh8Hfsvq6Ne1-YFuC5siw1gVa7ZBGs_k,6605
|
|
30
30
|
KonectySdkPython/lib/services/stream.py,sha256=1DMVxcg9Ymk2NgX0Qfvpjrr6vZJo5iFovPFT1NA3_CY,4737
|
|
31
31
|
KonectySdkPython/lib/services/subscriptions.py,sha256=_Jq8jW7YkL_hwLNte1bWgrr4D2EMZUUSOXUgnRoGGK4,1022
|
|
32
|
-
konecty_sdk_python-2.1.
|
|
33
|
-
konecty_sdk_python-2.1.
|
|
34
|
-
konecty_sdk_python-2.1.
|
|
35
|
-
konecty_sdk_python-2.1.
|
|
32
|
+
konecty_sdk_python-2.1.2.dist-info/METADATA,sha256=TfygAtKFhJJZvdH8AgpgtIBQnoFexqBLQk9FaXwDZ8Q,5442
|
|
33
|
+
konecty_sdk_python-2.1.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
34
|
+
konecty_sdk_python-2.1.2.dist-info/entry_points.txt,sha256=awf962DamFgy791G3PsJ354edBMLJg16Dqi-2Y1tb9s,58
|
|
35
|
+
konecty_sdk_python-2.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|