Ayon-Python-Api 0.4.1__tar.gz → 0.4.3__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.
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/PKG-INFO +1 -1
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/_api.py +2 -2
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/graphql_queries.py +4 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/server_api.py +36 -22
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/utils.py +65 -18
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/version.py +1 -1
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/PKG-INFO +1 -1
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/pyproject.toml +1 -1
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/LICENSE +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/README.md +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/__init__.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/constants.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/entity_hub.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/events.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/exceptions.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/graphql.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_api/operations.py +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/SOURCES.txt +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/dependency_links.txt +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/requires.txt +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/top_level.txt +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/setup.cfg +0 -0
- {ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/setup.py +0 -0
|
@@ -753,12 +753,12 @@ def get_secrets(*args, **kwargs):
|
|
|
753
753
|
|
|
754
754
|
def get_secret(*args, **kwargs):
|
|
755
755
|
con = get_server_api_connection()
|
|
756
|
-
return con.
|
|
756
|
+
return con.get_secret(*args, **kwargs)
|
|
757
757
|
|
|
758
758
|
|
|
759
759
|
def save_secret(*args, **kwargs):
|
|
760
760
|
con = get_server_api_connection()
|
|
761
|
-
return con.
|
|
761
|
+
return con.save_secret(*args, **kwargs)
|
|
762
762
|
|
|
763
763
|
|
|
764
764
|
def delete_secret(*args, **kwargs):
|
|
@@ -175,6 +175,8 @@ def folders_graphql_query(fields):
|
|
|
175
175
|
parent_folder_ids_var = query.add_variable("parentFolderIds", "[String!]")
|
|
176
176
|
folder_paths_var = query.add_variable("folderPaths", "[String!]")
|
|
177
177
|
folder_names_var = query.add_variable("folderNames", "[String!]")
|
|
178
|
+
folder_types_var = query.add_variable("folderTypes", "[String!]")
|
|
179
|
+
statuses_var = query.add_variable("folderStatuses", "[String!]")
|
|
178
180
|
has_products_var = query.add_variable("folderHasProducts", "Boolean!")
|
|
179
181
|
|
|
180
182
|
project_field = query.add_field("project")
|
|
@@ -185,6 +187,8 @@ def folders_graphql_query(fields):
|
|
|
185
187
|
folders_field.set_filter("parentIds", parent_folder_ids_var)
|
|
186
188
|
folders_field.set_filter("names", folder_names_var)
|
|
187
189
|
folders_field.set_filter("paths", folder_paths_var)
|
|
190
|
+
folders_field.set_filter("folderTypes", folder_types_var)
|
|
191
|
+
folders_field.set_filter("statuses", statuses_var)
|
|
188
192
|
folders_field.set_filter("hasProducts", has_products_var)
|
|
189
193
|
|
|
190
194
|
nested_fields = fields_to_dict(fields)
|
|
@@ -75,6 +75,7 @@ from .utils import (
|
|
|
75
75
|
TransferProgress,
|
|
76
76
|
create_dependency_package_basename,
|
|
77
77
|
ThumbnailContent,
|
|
78
|
+
get_default_timeout,
|
|
78
79
|
)
|
|
79
80
|
|
|
80
81
|
PatternType = type(re.compile(""))
|
|
@@ -351,7 +352,6 @@ class ServerAPI(object):
|
|
|
351
352
|
timeout (Optional[float]): Timeout for requests.
|
|
352
353
|
max_retries (Optional[int]): Number of retries for requests.
|
|
353
354
|
"""
|
|
354
|
-
_default_timeout = 10.0
|
|
355
355
|
_default_max_retries = 3
|
|
356
356
|
|
|
357
357
|
def __init__(
|
|
@@ -500,20 +500,13 @@ class ServerAPI(object):
|
|
|
500
500
|
def get_default_timeout(cls):
|
|
501
501
|
"""Default value for requests timeout.
|
|
502
502
|
|
|
503
|
-
|
|
504
|
-
can affect timeout value. If not available then use class
|
|
505
|
-
attribute '_default_timeout'.
|
|
503
|
+
Utils function 'get_default_timeout' is used by default.
|
|
506
504
|
|
|
507
505
|
Returns:
|
|
508
506
|
float: Timeout value in seconds.
|
|
509
507
|
"""
|
|
510
508
|
|
|
511
|
-
|
|
512
|
-
return float(os.environ.get(SERVER_TIMEOUT_ENV_KEY))
|
|
513
|
-
except (ValueError, TypeError):
|
|
514
|
-
pass
|
|
515
|
-
|
|
516
|
-
return cls._default_timeout
|
|
509
|
+
return get_default_timeout()
|
|
517
510
|
|
|
518
511
|
@classmethod
|
|
519
512
|
def get_default_max_retries(cls):
|
|
@@ -3515,7 +3508,9 @@ class ServerAPI(object):
|
|
|
3515
3508
|
folder_ids=None,
|
|
3516
3509
|
folder_paths=None,
|
|
3517
3510
|
folder_names=None,
|
|
3511
|
+
folder_types=None,
|
|
3518
3512
|
parent_ids=None,
|
|
3513
|
+
statuses=None,
|
|
3519
3514
|
active=True,
|
|
3520
3515
|
fields=None,
|
|
3521
3516
|
own_attributes=False
|
|
@@ -3536,8 +3531,12 @@ class ServerAPI(object):
|
|
|
3536
3531
|
for filtering.
|
|
3537
3532
|
folder_names (Optional[Iterable[str]]): Folder names used
|
|
3538
3533
|
for filtering.
|
|
3534
|
+
folder_types (Optional[Iterable[str]]): Folder types used
|
|
3535
|
+
for filtering.
|
|
3539
3536
|
parent_ids (Optional[Iterable[str]]): Ids of folder parents.
|
|
3540
3537
|
Use 'None' if folder is direct child of project.
|
|
3538
|
+
statuses (Optional[Iterable[str]]): Folder statuses used
|
|
3539
|
+
for filtering.
|
|
3541
3540
|
active (Optional[bool]): Filter active/inactive folders.
|
|
3542
3541
|
Both are returned if is set to None.
|
|
3543
3542
|
fields (Optional[Iterable[str]]): Fields to be queried for
|
|
@@ -3574,6 +3573,18 @@ class ServerAPI(object):
|
|
|
3574
3573
|
return
|
|
3575
3574
|
filters["folderNames"] = list(folder_names)
|
|
3576
3575
|
|
|
3576
|
+
if folder_types is not None:
|
|
3577
|
+
folder_types = set(folder_types)
|
|
3578
|
+
if not folder_types:
|
|
3579
|
+
return
|
|
3580
|
+
filters["folderTypes"] = list(folder_types)
|
|
3581
|
+
|
|
3582
|
+
if statuses is not None:
|
|
3583
|
+
statuses = set(statuses)
|
|
3584
|
+
if not statuses:
|
|
3585
|
+
return
|
|
3586
|
+
filters["folderStatuses"] = list(statuses)
|
|
3587
|
+
|
|
3577
3588
|
if parent_ids is not None:
|
|
3578
3589
|
parent_ids = set(parent_ids)
|
|
3579
3590
|
if not parent_ids:
|
|
@@ -5845,19 +5856,22 @@ class ServerAPI(object):
|
|
|
5845
5856
|
"""Helper method to get links from server for entity types.
|
|
5846
5857
|
|
|
5847
5858
|
Example output:
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
+
{
|
|
5860
|
+
"59a212c0d2e211eda0e20242ac120001": [
|
|
5861
|
+
{
|
|
5862
|
+
"id": "59a212c0d2e211eda0e20242ac120002",
|
|
5863
|
+
"linkType": "reference",
|
|
5864
|
+
"description": "reference link between folders",
|
|
5865
|
+
"projectName": "my_project",
|
|
5866
|
+
"author": "frantadmin",
|
|
5867
|
+
"entityId": "b1df109676db11ed8e8c6c9466b19aa8",
|
|
5868
|
+
"entityType": "folder",
|
|
5869
|
+
"direction": "out"
|
|
5870
|
+
},
|
|
5871
|
+
...
|
|
5872
|
+
],
|
|
5859
5873
|
...
|
|
5860
|
-
|
|
5874
|
+
}
|
|
5861
5875
|
|
|
5862
5876
|
Args:
|
|
5863
5877
|
project_name (str): Project where links are.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os
|
|
1
2
|
import re
|
|
2
3
|
import datetime
|
|
3
4
|
import uuid
|
|
@@ -15,6 +16,7 @@ except ImportError:
|
|
|
15
16
|
import requests
|
|
16
17
|
import unidecode
|
|
17
18
|
|
|
19
|
+
from .constants import SERVER_TIMEOUT_ENV_KEY
|
|
18
20
|
from .exceptions import UrlError
|
|
19
21
|
|
|
20
22
|
REMOVED_VALUE = object()
|
|
@@ -27,6 +29,23 @@ RepresentationParents = collections.namedtuple(
|
|
|
27
29
|
)
|
|
28
30
|
|
|
29
31
|
|
|
32
|
+
def get_default_timeout():
|
|
33
|
+
"""Default value for requests timeout.
|
|
34
|
+
|
|
35
|
+
First looks for environment variable SERVER_TIMEOUT_ENV_KEY which
|
|
36
|
+
can affect timeout value. If not available then use 10.0 s.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
float: Timeout value in seconds.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
return float(os.environ.get(SERVER_TIMEOUT_ENV_KEY))
|
|
44
|
+
except (ValueError, TypeError):
|
|
45
|
+
pass
|
|
46
|
+
return 10.0
|
|
47
|
+
|
|
48
|
+
|
|
30
49
|
class ThumbnailContent:
|
|
31
50
|
"""Wrapper for thumbnail content.
|
|
32
51
|
|
|
@@ -231,30 +250,36 @@ def _try_parse_url(url):
|
|
|
231
250
|
return None
|
|
232
251
|
|
|
233
252
|
|
|
234
|
-
def _try_connect_to_server(url):
|
|
253
|
+
def _try_connect_to_server(url, timeout=None):
|
|
254
|
+
if timeout is None:
|
|
255
|
+
timeout = get_default_timeout()
|
|
235
256
|
try:
|
|
236
257
|
# TODO add validation if the url lead to Ayon server
|
|
237
|
-
# -
|
|
238
|
-
requests.get(url)
|
|
258
|
+
# - this won't validate if the url lead to 'google.com'
|
|
259
|
+
requests.get(url, timeout=timeout)
|
|
239
260
|
|
|
240
261
|
except BaseException:
|
|
241
262
|
return False
|
|
242
263
|
return True
|
|
243
264
|
|
|
244
265
|
|
|
245
|
-
def login_to_server(url, username, password):
|
|
266
|
+
def login_to_server(url, username, password, timeout=None):
|
|
246
267
|
"""Use login to the server to receive token.
|
|
247
268
|
|
|
248
269
|
Args:
|
|
249
270
|
url (str): Server url.
|
|
250
271
|
username (str): User's username.
|
|
251
272
|
password (str): User's password.
|
|
273
|
+
timeout (Optional[float]): Timeout for request. Value from
|
|
274
|
+
'get_default_timeout' is used if not specified.
|
|
252
275
|
|
|
253
276
|
Returns:
|
|
254
277
|
Union[str, None]: User's token if login was successfull.
|
|
255
278
|
Otherwise 'None'.
|
|
256
279
|
"""
|
|
257
280
|
|
|
281
|
+
if timeout is None:
|
|
282
|
+
timeout = get_default_timeout()
|
|
258
283
|
headers = {"Content-Type": "application/json"}
|
|
259
284
|
response = requests.post(
|
|
260
285
|
"{}/api/auth/login".format(url),
|
|
@@ -262,7 +287,8 @@ def login_to_server(url, username, password):
|
|
|
262
287
|
json={
|
|
263
288
|
"name": username,
|
|
264
289
|
"password": password
|
|
265
|
-
}
|
|
290
|
+
},
|
|
291
|
+
timeout=timeout,
|
|
266
292
|
)
|
|
267
293
|
token = None
|
|
268
294
|
# 200 - success
|
|
@@ -273,47 +299,67 @@ def login_to_server(url, username, password):
|
|
|
273
299
|
return token
|
|
274
300
|
|
|
275
301
|
|
|
276
|
-
def logout_from_server(url, token):
|
|
302
|
+
def logout_from_server(url, token, timeout=None):
|
|
277
303
|
"""Logout from server and throw token away.
|
|
278
304
|
|
|
279
305
|
Args:
|
|
280
306
|
url (str): Url from which should be logged out.
|
|
281
307
|
token (str): Token which should be used to log out.
|
|
308
|
+
timeout (Optional[float]): Timeout for request. Value from
|
|
309
|
+
'get_default_timeout' is used if not specified.
|
|
282
310
|
"""
|
|
283
311
|
|
|
312
|
+
if timeout is None:
|
|
313
|
+
timeout = get_default_timeout()
|
|
284
314
|
headers = {
|
|
285
315
|
"Content-Type": "application/json",
|
|
286
316
|
"Authorization": "Bearer {}".format(token)
|
|
287
317
|
}
|
|
288
318
|
requests.post(
|
|
289
319
|
url + "/api/auth/logout",
|
|
290
|
-
headers=headers
|
|
320
|
+
headers=headers,
|
|
321
|
+
timeout=timeout,
|
|
291
322
|
)
|
|
292
323
|
|
|
293
324
|
|
|
294
|
-
def is_token_valid(url, token):
|
|
325
|
+
def is_token_valid(url, token, timeout=None):
|
|
295
326
|
"""Check if token is valid.
|
|
296
327
|
|
|
328
|
+
Token can be a user token or service api key.
|
|
329
|
+
|
|
297
330
|
Args:
|
|
298
331
|
url (str): Server url.
|
|
299
332
|
token (str): User's token.
|
|
333
|
+
timeout (Optional[float]): Timeout for request. Value from
|
|
334
|
+
'get_default_timeout' is used if not specified.
|
|
300
335
|
|
|
301
336
|
Returns:
|
|
302
337
|
bool: True if token is valid.
|
|
303
338
|
"""
|
|
304
339
|
|
|
305
|
-
|
|
340
|
+
if timeout is None:
|
|
341
|
+
timeout = get_default_timeout()
|
|
342
|
+
|
|
343
|
+
base_headers = {
|
|
306
344
|
"Content-Type": "application/json",
|
|
307
|
-
"Authorization": "Bearer {}".format(token)
|
|
308
345
|
}
|
|
309
|
-
|
|
310
|
-
"{}
|
|
311
|
-
|
|
312
|
-
)
|
|
313
|
-
|
|
346
|
+
for header_value in (
|
|
347
|
+
{"Authorization": "Bearer {}".format(token)},
|
|
348
|
+
{"X-Api-Key": token},
|
|
349
|
+
):
|
|
350
|
+
headers = base_headers.copy()
|
|
351
|
+
headers.update(header_value)
|
|
352
|
+
response = requests.get(
|
|
353
|
+
"{}/api/users/me".format(url),
|
|
354
|
+
headers=headers,
|
|
355
|
+
timeout=timeout,
|
|
356
|
+
)
|
|
357
|
+
if response.status_code == 200:
|
|
358
|
+
return True
|
|
359
|
+
return False
|
|
314
360
|
|
|
315
361
|
|
|
316
|
-
def validate_url(url):
|
|
362
|
+
def validate_url(url, timeout=None):
|
|
317
363
|
"""Validate url if is valid and server is available.
|
|
318
364
|
|
|
319
365
|
Validation checks if can be parsed as url and contains scheme.
|
|
@@ -334,6 +380,7 @@ def validate_url(url):
|
|
|
334
380
|
|
|
335
381
|
Args:
|
|
336
382
|
url (str): Server url.
|
|
383
|
+
timeout (Optional[int]): Timeout in seconds for connection to server.
|
|
337
384
|
|
|
338
385
|
Returns:
|
|
339
386
|
Url which was used to connect to server.
|
|
@@ -369,10 +416,10 @@ def validate_url(url):
|
|
|
369
416
|
# - this will trigger UrlError if both will crash
|
|
370
417
|
if not parsed_url.scheme:
|
|
371
418
|
new_url = "https://" + modified_url
|
|
372
|
-
if _try_connect_to_server(new_url):
|
|
419
|
+
if _try_connect_to_server(new_url, timeout=timeout):
|
|
373
420
|
return new_url
|
|
374
421
|
|
|
375
|
-
if _try_connect_to_server(modified_url):
|
|
422
|
+
if _try_connect_to_server(modified_url, timeout=timeout):
|
|
376
423
|
return modified_url
|
|
377
424
|
|
|
378
425
|
hints = []
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""Package declaring Python API for Ayon server."""
|
|
2
|
-
__version__ = "0.4.
|
|
2
|
+
__version__ = "0.4.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ayon-python-api-0.4.1 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|