Ayon-Python-Api 0.4.2__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.
Files changed (23) hide show
  1. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/PKG-INFO +1 -1
  2. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/utils.py +37 -12
  3. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/version.py +1 -1
  4. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/PKG-INFO +1 -1
  5. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/pyproject.toml +1 -1
  6. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/LICENSE +0 -0
  7. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/README.md +0 -0
  8. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/__init__.py +0 -0
  9. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/_api.py +0 -0
  10. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/constants.py +0 -0
  11. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/entity_hub.py +0 -0
  12. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/events.py +0 -0
  13. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/exceptions.py +0 -0
  14. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/graphql.py +0 -0
  15. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/graphql_queries.py +0 -0
  16. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/operations.py +0 -0
  17. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_api/server_api.py +0 -0
  18. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/SOURCES.txt +0 -0
  19. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/dependency_links.txt +0 -0
  20. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/requires.txt +0 -0
  21. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/ayon_python_api.egg-info/top_level.txt +0 -0
  22. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/setup.cfg +0 -0
  23. {ayon-python-api-0.4.2 → ayon-python-api-0.4.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: AYON Python API
5
5
  Home-page: https://github.com/ynput/ayon-python-api
6
6
  Author: ynput.io
@@ -263,19 +263,23 @@ def _try_connect_to_server(url, timeout=None):
263
263
  return True
264
264
 
265
265
 
266
- def login_to_server(url, username, password):
266
+ def login_to_server(url, username, password, timeout=None):
267
267
  """Use login to the server to receive token.
268
268
 
269
269
  Args:
270
270
  url (str): Server url.
271
271
  username (str): User's username.
272
272
  password (str): User's password.
273
+ timeout (Optional[float]): Timeout for request. Value from
274
+ 'get_default_timeout' is used if not specified.
273
275
 
274
276
  Returns:
275
277
  Union[str, None]: User's token if login was successfull.
276
278
  Otherwise 'None'.
277
279
  """
278
280
 
281
+ if timeout is None:
282
+ timeout = get_default_timeout()
279
283
  headers = {"Content-Type": "application/json"}
280
284
  response = requests.post(
281
285
  "{}/api/auth/login".format(url),
@@ -283,7 +287,8 @@ def login_to_server(url, username, password):
283
287
  json={
284
288
  "name": username,
285
289
  "password": password
286
- }
290
+ },
291
+ timeout=timeout,
287
292
  )
288
293
  token = None
289
294
  # 200 - success
@@ -294,44 +299,64 @@ def login_to_server(url, username, password):
294
299
  return token
295
300
 
296
301
 
297
- def logout_from_server(url, token):
302
+ def logout_from_server(url, token, timeout=None):
298
303
  """Logout from server and throw token away.
299
304
 
300
305
  Args:
301
306
  url (str): Url from which should be logged out.
302
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.
303
310
  """
304
311
 
312
+ if timeout is None:
313
+ timeout = get_default_timeout()
305
314
  headers = {
306
315
  "Content-Type": "application/json",
307
316
  "Authorization": "Bearer {}".format(token)
308
317
  }
309
318
  requests.post(
310
319
  url + "/api/auth/logout",
311
- headers=headers
320
+ headers=headers,
321
+ timeout=timeout,
312
322
  )
313
323
 
314
324
 
315
- def is_token_valid(url, token):
325
+ def is_token_valid(url, token, timeout=None):
316
326
  """Check if token is valid.
317
327
 
328
+ Token can be a user token or service api key.
329
+
318
330
  Args:
319
331
  url (str): Server url.
320
332
  token (str): User's token.
333
+ timeout (Optional[float]): Timeout for request. Value from
334
+ 'get_default_timeout' is used if not specified.
321
335
 
322
336
  Returns:
323
337
  bool: True if token is valid.
324
338
  """
325
339
 
326
- headers = {
340
+ if timeout is None:
341
+ timeout = get_default_timeout()
342
+
343
+ base_headers = {
327
344
  "Content-Type": "application/json",
328
- "Authorization": "Bearer {}".format(token)
329
345
  }
330
- response = requests.get(
331
- "{}/api/users/me".format(url),
332
- headers=headers
333
- )
334
- return response.status_code == 200
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
335
360
 
336
361
 
337
362
  def validate_url(url, timeout=None):
@@ -1,2 +1,2 @@
1
1
  """Package declaring Python API for Ayon server."""
2
- __version__ = "0.4.2"
2
+ __version__ = "0.4.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayon-python-api
3
- Version: 0.4.2
3
+ Version: 0.4.3
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 = "0.4.2"
3
+ version = "0.4.3"
4
4
  description = "AYON Python API"
5
5
  license = {file = "LICENSE"}
6
6
  readme = {file = "README.md", content-type = "text/markdown"}
File without changes