uiprotect 0.4.0__py3-none-any.whl → 0.5.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 uiprotect might be problematic. Click here for more details.
- uiprotect/api.py +15 -6
- uiprotect/utils.py +8 -2
- {uiprotect-0.4.0.dist-info → uiprotect-0.5.0.dist-info}/METADATA +1 -1
- {uiprotect-0.4.0.dist-info → uiprotect-0.5.0.dist-info}/RECORD +7 -7
- {uiprotect-0.4.0.dist-info → uiprotect-0.5.0.dist-info}/LICENSE +0 -0
- {uiprotect-0.4.0.dist-info → uiprotect-0.5.0.dist-info}/WHEEL +0 -0
- {uiprotect-0.4.0.dist-info → uiprotect-0.5.0.dist-info}/entry_points.txt +0 -0
uiprotect/api.py
CHANGED
|
@@ -161,6 +161,7 @@ class BaseApiClient:
|
|
|
161
161
|
_last_token_cookie_decode: dict[str, Any] | None = None
|
|
162
162
|
_session: aiohttp.ClientSession | None = None
|
|
163
163
|
_loaded_session: bool = False
|
|
164
|
+
_cookiename = "TOKEN"
|
|
164
165
|
|
|
165
166
|
headers: dict[str, str] | None = None
|
|
166
167
|
_websocket: Websocket | None = None
|
|
@@ -204,6 +205,10 @@ class BaseApiClient:
|
|
|
204
205
|
|
|
205
206
|
self._update_url()
|
|
206
207
|
|
|
208
|
+
def _update_cookiename(self, cookie: SimpleCookie) -> None:
|
|
209
|
+
if "UOS_TOKEN" in cookie:
|
|
210
|
+
self._cookiename = "UOS_TOKEN"
|
|
211
|
+
|
|
207
212
|
def _update_url(self) -> None:
|
|
208
213
|
"""Updates the url after changing _host or _port."""
|
|
209
214
|
if self._port != 443:
|
|
@@ -475,7 +480,6 @@ class BaseApiClient:
|
|
|
475
480
|
response = await self.request("post", url=url, json=auth)
|
|
476
481
|
self.set_header("cookie", response.headers.get("set-cookie", ""))
|
|
477
482
|
self._is_authenticated = True
|
|
478
|
-
await self._update_last_token_cookie(response)
|
|
479
483
|
_LOGGER.debug("Authenticated successfully!")
|
|
480
484
|
|
|
481
485
|
async def _update_last_token_cookie(self, response: aiohttp.ClientResponse) -> None:
|
|
@@ -488,9 +492,10 @@ class BaseApiClient:
|
|
|
488
492
|
):
|
|
489
493
|
self.set_header("x-csrf-token", csrf_token)
|
|
490
494
|
await self._update_last_token_cookie(response)
|
|
495
|
+
self._update_cookiename(response.cookies)
|
|
491
496
|
|
|
492
497
|
if (
|
|
493
|
-
token_cookie := response.cookies.get(
|
|
498
|
+
token_cookie := response.cookies.get(self._cookiename)
|
|
494
499
|
) and token_cookie != self._last_token_cookie:
|
|
495
500
|
self._last_token_cookie = token_cookie
|
|
496
501
|
if self.store_sessions:
|
|
@@ -520,6 +525,7 @@ class BaseApiClient:
|
|
|
520
525
|
config["sessions"] = config.get("sessions", {})
|
|
521
526
|
config["sessions"][session_hash] = {
|
|
522
527
|
"metadata": dict(cookie),
|
|
528
|
+
"cookiename": self._cookiename,
|
|
523
529
|
"value": cookie.value,
|
|
524
530
|
"csrf": self.headers.get("x-csrf-token") if self.headers else None,
|
|
525
531
|
}
|
|
@@ -561,12 +567,15 @@ class BaseApiClient:
|
|
|
561
567
|
return None
|
|
562
568
|
|
|
563
569
|
cookie = SimpleCookie()
|
|
564
|
-
|
|
570
|
+
cookie_name = session.get("cookiename")
|
|
571
|
+
if cookie_name is None:
|
|
572
|
+
return None
|
|
573
|
+
cookie[cookie_name] = session.get("value")
|
|
565
574
|
for key, value in session.get("metadata", {}).items():
|
|
566
|
-
cookie[
|
|
575
|
+
cookie[cookie_name][key] = value
|
|
567
576
|
|
|
568
|
-
cookie_value = _COOKIE_RE.sub("", str(cookie[
|
|
569
|
-
self._last_token_cookie = cookie[
|
|
577
|
+
cookie_value = _COOKIE_RE.sub("", str(cookie[cookie_name]))
|
|
578
|
+
self._last_token_cookie = cookie[cookie_name]
|
|
570
579
|
self._last_token_cookie_decode = None
|
|
571
580
|
self._is_authenticated = True
|
|
572
581
|
self.set_header("cookie", cookie_value)
|
uiprotect/utils.py
CHANGED
|
@@ -234,11 +234,11 @@ def convert_unifi_data(value: Any, field: ModelField) -> Any:
|
|
|
234
234
|
return value
|
|
235
235
|
if type_ == datetime:
|
|
236
236
|
return from_js_time(value)
|
|
237
|
-
if type_ in _CREATE_TYPES or (
|
|
237
|
+
if type_ in _CREATE_TYPES or _is_enum_type(type_):
|
|
238
238
|
# cannot do this check too soon because some types cannot be used in isinstance
|
|
239
239
|
if isinstance(value, type_):
|
|
240
240
|
return value
|
|
241
|
-
# handle edge case for improperly
|
|
241
|
+
# handle edge case for improperly formatted UUIDs
|
|
242
242
|
# 00000000-0000-00 0- 000-000000000000
|
|
243
243
|
if type_ == UUID and value == _BAD_UUID:
|
|
244
244
|
value = "0" * 32
|
|
@@ -247,6 +247,12 @@ def convert_unifi_data(value: Any, field: ModelField) -> Any:
|
|
|
247
247
|
return value
|
|
248
248
|
|
|
249
249
|
|
|
250
|
+
@lru_cache
|
|
251
|
+
def _is_enum_type(type_: Any) -> bool:
|
|
252
|
+
"""Checks if type is an Enum."""
|
|
253
|
+
return isclass(type_) and issubclass(type_, Enum)
|
|
254
|
+
|
|
255
|
+
|
|
250
256
|
def serialize_unifi_obj(value: Any, levels: int = -1) -> Any:
|
|
251
257
|
"""Serializes UFP data"""
|
|
252
258
|
if unifi_dict := getattr(value, "unifi_dict", None):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
uiprotect/__init__.py,sha256=tzcxK6cOIIkFEtST4Zjq3bafYTFWtwnaL92DgypjFi8,307
|
|
2
2
|
uiprotect/__main__.py,sha256=T69KE5W4zek6qeNEL8_Fq2DEfBc04SqSuIOJpiW4ydE,471
|
|
3
|
-
uiprotect/api.py,sha256=
|
|
3
|
+
uiprotect/api.py,sha256=G2cvwLuanzvZ7dGfJOlAMvbKSBIsb7t3uOPB-KyT8gk,66006
|
|
4
4
|
uiprotect/cli/__init__.py,sha256=tmwtYrhM8rjOw8noKD6NALl_2Nu3xIycDuQyEKD5oMk,8832
|
|
5
5
|
uiprotect/cli/backup.py,sha256=Mtjd2f0w7zjIeLkJILKxiBnZJYXypzC9gpyAmBZ8sq0,36746
|
|
6
6
|
uiprotect/cli/base.py,sha256=dE6vYb4nLAYbUdHwcKkN7I3iXqTjz84jfHGnsLmk_Ds,7762
|
|
@@ -28,10 +28,10 @@ uiprotect/release_cache.json,sha256=NamnSFy78hOWY0DPO87J9ELFCAN6NnVquv8gQO75ZG4,
|
|
|
28
28
|
uiprotect/stream.py,sha256=V4aJfVWpSUsWE1PQrXH8F7obQQi1ukPAZ7PzwABjt0I,4942
|
|
29
29
|
uiprotect/test_util/__init__.py,sha256=sSEXu6_pwdYNQSCYtftpX1Dy1S8XYOvhrpECYRxeKJE,18596
|
|
30
30
|
uiprotect/test_util/anonymize.py,sha256=AGYELhDC4BrdK0deI6zh5jFp3SuM_HvAWLeoxFHSiwg,8486
|
|
31
|
-
uiprotect/utils.py,sha256=
|
|
31
|
+
uiprotect/utils.py,sha256=1HB-rtzdTxsRzEY_vnzdJZOzyruci7lOkQDfr8D1L_8,18244
|
|
32
32
|
uiprotect/websocket.py,sha256=iMTdchymaCgVHsmY1bRbxkcymqt6WQircIHYNxCu178,7289
|
|
33
|
-
uiprotect-0.
|
|
34
|
-
uiprotect-0.
|
|
35
|
-
uiprotect-0.
|
|
36
|
-
uiprotect-0.
|
|
37
|
-
uiprotect-0.
|
|
33
|
+
uiprotect-0.5.0.dist-info/LICENSE,sha256=INx18jhdbVXMEiiBANeKEbrbz57ckgzxk5uutmmcxGk,1111
|
|
34
|
+
uiprotect-0.5.0.dist-info/METADATA,sha256=lofryisrm6u9ASPQ0r77MqHKRqWNUE1XkAzuUrlBBYI,10984
|
|
35
|
+
uiprotect-0.5.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
36
|
+
uiprotect-0.5.0.dist-info/entry_points.txt,sha256=J78AUTPrTTxgI3s7SVgrmGqDP7piX2wuuEORzhDdVRA,47
|
|
37
|
+
uiprotect-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|