ayon-python-api 1.1.0__tar.gz → 1.1.2__tar.gz

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.
Files changed (24) hide show
  1. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/PKG-INFO +1 -1
  2. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/server_api.py +13 -4
  3. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/utils.py +59 -11
  4. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/version.py +1 -1
  5. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_python_api.egg-info/PKG-INFO +1 -1
  6. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/pyproject.toml +2 -2
  7. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/LICENSE +0 -0
  8. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/README.md +0 -0
  9. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/__init__.py +0 -0
  10. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/_api.py +0 -0
  11. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/constants.py +0 -0
  12. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/entity_hub.py +0 -0
  13. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/events.py +0 -0
  14. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/exceptions.py +0 -0
  15. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/graphql.py +0 -0
  16. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/graphql_queries.py +0 -0
  17. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/operations.py +0 -0
  18. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_api/typing.py +0 -0
  19. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_python_api.egg-info/SOURCES.txt +0 -0
  20. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_python_api.egg-info/dependency_links.txt +0 -0
  21. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_python_api.egg-info/requires.txt +0 -0
  22. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/ayon_python_api.egg-info/top_level.txt +0 -0
  23. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/setup.cfg +0 -0
  24. {ayon-python-api-1.1.0 → ayon-python-api-1.1.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -96,6 +96,7 @@ from .utils import (
96
96
  NOT_SET,
97
97
  get_media_mime_type,
98
98
  SortOrder,
99
+ get_machine_name,
99
100
  )
100
101
 
101
102
  if typing.TYPE_CHECKING:
@@ -1187,8 +1188,13 @@ class ServerAPI(object):
1187
1188
 
1188
1189
  for parsed_data in query.continuous_query(self):
1189
1190
  for user in parsed_data["users"]:
1190
- user["accessGroups"] = json.loads(
1191
- user["accessGroups"])
1191
+ access_groups = user.get("accessGroups")
1192
+ if isinstance(access_groups, str):
1193
+ user["accessGroups"] = json.loads(access_groups)
1194
+ all_attrib = user.get("allAttrib")
1195
+ if isinstance(all_attrib, str):
1196
+ user["allAttrib"] = json.loads(all_attrib)
1197
+ fill_own_attribs(user)
1192
1198
  yield user
1193
1199
 
1194
1200
  def get_user_by_name(
@@ -1245,7 +1251,9 @@ class ServerAPI(object):
1245
1251
 
1246
1252
  response = self.get(f"users/{username}")
1247
1253
  response.raise_for_status()
1248
- return response.data
1254
+ user = response.data
1255
+ fill_own_attribs(user)
1256
+ return user
1249
1257
 
1250
1258
  def get_headers(
1251
1259
  self, content_type: Optional[str] = None
@@ -1256,7 +1264,8 @@ class ServerAPI(object):
1256
1264
  headers = {
1257
1265
  "Content-Type": content_type,
1258
1266
  "x-ayon-platform": platform.system().lower(),
1259
- "x-ayon-hostname": platform.node(),
1267
+ "x-ayon-hostname": get_machine_name(),
1268
+ "referer": self.get_base_url(),
1260
1269
  }
1261
1270
  if self._site_id is not None:
1262
1271
  headers["x-ayon-site-id"] = self._site_id
@@ -4,6 +4,7 @@ import datetime
4
4
  import uuid
5
5
  import string
6
6
  import platform
7
+ import traceback
7
8
  import collections
8
9
  from urllib.parse import urlparse, urlencode
9
10
  import typing
@@ -88,6 +89,17 @@ def get_default_settings_variant() -> str:
88
89
  return os.environ.get(DEFAULT_VARIANT_ENV_KEY) or "production"
89
90
 
90
91
 
92
+ def get_machine_name() -> str:
93
+ """Get machine name.
94
+
95
+ Returns:
96
+ str: Machine name.
97
+
98
+ """
99
+ return platform.node()
100
+ return unidecode.unidecode(platform.node())
101
+
102
+
91
103
  def get_default_site_id() -> Optional[str]:
92
104
  """Site id used for server connection.
93
105
 
@@ -322,18 +334,38 @@ def _try_parse_url(url: str) -> Optional[str]:
322
334
 
323
335
 
324
336
  def _try_connect_to_server(
325
- url: str, timeout: Optional[float] = None
326
- ) -> bool:
337
+ url: str,
338
+ timeout: Optional[float],
339
+ verify: Optional["Union[str, bool]"],
340
+ cert: Optional[str],
341
+ ) -> Optional[str]:
327
342
  if timeout is None:
328
343
  timeout = get_default_timeout()
344
+
345
+ if verify is None:
346
+ verify = os.environ.get("AYON_CA_FILE") or True
347
+
348
+ if cert is None:
349
+ cert = os.environ.get("AYON_CERT_FILE") or None
350
+
329
351
  try:
330
352
  # TODO add validation if the url lead to AYON server
331
353
  # - this won't validate if the url lead to 'google.com'
332
- requests.get(url, timeout=timeout)
354
+ response = requests.get(
355
+ url,
356
+ timeout=timeout,
357
+ verify=verify,
358
+ cert=cert,
359
+ )
360
+ if response.history:
361
+ return response.history[-1].headers["location"].rstrip("/")
362
+ return url
333
363
 
334
- except BaseException:
335
- return False
336
- return True
364
+ except Exception:
365
+ print(f"Failed to connect to '{url}'")
366
+ traceback.print_exc()
367
+
368
+ return None
337
369
 
338
370
 
339
371
  def login_to_server(
@@ -463,7 +495,12 @@ def is_token_valid(
463
495
  return False
464
496
 
465
497
 
466
- def validate_url(url: str, timeout: Optional[int] = None) -> str:
498
+ def validate_url(
499
+ url: str,
500
+ timeout: Optional[int] = None,
501
+ verify: Optional["Union[str, bool]"] = None,
502
+ cert: Optional[str] = None,
503
+ ) -> str:
467
504
  """Validate url if is valid and server is available.
468
505
 
469
506
  Validation checks if can be parsed as url and contains scheme.
@@ -520,12 +557,23 @@ def validate_url(url: str, timeout: Optional[int] = None) -> str:
520
557
  # Try add 'https://' scheme if is missing
521
558
  # - this will trigger UrlError if both will crash
522
559
  if not parsed_url.scheme:
523
- new_url = "https://" + modified_url
524
- if _try_connect_to_server(new_url, timeout=timeout):
560
+ new_url = _try_connect_to_server(
561
+ "http://" + modified_url,
562
+ timeout=timeout,
563
+ verify=verify,
564
+ cert=cert,
565
+ )
566
+ if new_url:
525
567
  return new_url
526
568
 
527
- if _try_connect_to_server(modified_url, timeout=timeout):
528
- return modified_url
569
+ new_url = _try_connect_to_server(
570
+ modified_url,
571
+ timeout=timeout,
572
+ verify=verify,
573
+ cert=cert,
574
+ )
575
+ if new_url:
576
+ return new_url
529
577
 
530
578
  hints = []
531
579
  if "/" in parsed_url.path or not parsed_url.scheme:
@@ -1,2 +1,2 @@
1
1
  """Package declaring Python API for AYON server."""
2
- __version__ = "1.1.0"
2
+ __version__ = "1.1.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ayon-python-api"
3
- version = "1.1.0"
3
+ version = "1.1.2"
4
4
  description = "AYON Python API"
5
5
  license = {file = "LICENSE"}
6
6
  readme = {file = "README.md", content-type = "text/markdown"}
@@ -28,7 +28,7 @@ build-backend = "poetry.core.masonry.api"
28
28
 
29
29
  [tool.poetry]
30
30
  name = "ayon-python-api"
31
- version = "1.1.0"
31
+ version = "1.1.2"
32
32
  description = "AYON Python API"
33
33
  authors = [
34
34
  "ynput.io <info@ynput.io>"
File without changes