python-sdk-local 0.0.126__tar.gz → 0.0.128__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 (20) hide show
  1. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/PKG-INFO +1 -1
  2. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_local.egg-info/PKG-INFO +1 -1
  3. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/constants.py +0 -9
  4. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/http_response.py +26 -15
  5. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/utilities.py +1 -1
  6. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/setup.py +1 -1
  7. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/README.md +0 -0
  8. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/pyproject.toml +0 -0
  9. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_local.egg-info/SOURCES.txt +0 -0
  10. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_local.egg-info/dependency_links.txt +0 -0
  11. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_local.egg-info/requires.txt +0 -0
  12. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_local.egg-info/top_level.txt +0 -0
  13. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/__init__.py +0 -0
  14. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/item.py +0 -0
  15. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/mini_logger.py +0 -0
  16. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/our_object.py +0 -0
  17. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/unified_json.py +0 -0
  18. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/valid_json_versions.py +0 -0
  19. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/python_sdk_remote/src/validate_environment.py +0 -0
  20. {python_sdk_local-0.0.126 → python_sdk_local-0.0.128}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-sdk-local
3
- Version: 0.0.126
3
+ Version: 0.0.128
4
4
  Summary: PyPI Package for Circles Python SDK Local Python
5
5
  Home-page: https://github.com/circles-zone/python-sdk-remote-python-package
6
6
  Author: Circles
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-sdk-local
3
- Version: 0.0.126
3
+ Version: 0.0.128
4
4
  Summary: PyPI Package for Circles Python SDK Local Python
5
5
  Home-page: https://github.com/circles-zone/python-sdk-remote-python-package
6
6
  Author: Circles
@@ -1,17 +1,8 @@
1
- import os
2
-
3
1
  from logger_local.LoggerComponentEnum import LoggerComponentEnum
4
2
 
5
3
  PYTHON_SDK_REMOTE_COMPONENT_ID = 184
6
4
  PYTHON_SDK_REMOTE_COMPONENT_NAME = 'python_sdk_remote'
7
5
 
8
- ENVIRONMENT_NAME = os.getenv("ENVIRONMENT_NAME")
9
- BRAND_NAME = os.getenv("BRAND_NAME")
10
- LOGZIO_TOKEN = os.getenv("LOGZIO_TOKEN")
11
- # TODO Shall Can we use python-sdk function to get the value from Environment?
12
- # TODO Shall we get the value from environment here of send the value to the function as @akiva-skolnik did?
13
- GOOGLE_PORT_FOR_AUTHENTICATION = os.getenv("PORT_FOR_AUTHENTICATION")
14
-
15
6
  OBJECT_TO_INSERT_CODE = {
16
7
  'component_id': PYTHON_SDK_REMOTE_COMPONENT_ID,
17
8
  'component_name': PYTHON_SDK_REMOTE_COMPONENT_NAME,
@@ -7,7 +7,7 @@ from .mini_logger import MiniLogger as logger
7
7
  from .utilities import camel_to_snake, snake_to_camel, to_dict, to_json
8
8
 
9
9
  HEADERS_KEY = 'headers'
10
- AUTHORIZATION_KEY = 'authorization'
10
+ AUTHORIZATION_KEY = 'Authorization'
11
11
  AUTHORIZATION_PREFIX = 'Bearer '
12
12
 
13
13
 
@@ -36,16 +36,17 @@ def get_request_parameters_from_event(event: dict) -> dict:
36
36
  """Extracts all params from the event object.
37
37
  The order of precedence is: payload > path > query string
38
38
  returns a dictionary with all the parameters, with both camelCase and snake_case keys."""
39
- all_params = get_payload_dict_from_event(event)
40
- all_params.update(get_path_parameters_dict_from_event(event))
41
- all_params.update(get_query_string_parameters_from_event(event))
42
- all_params = {camel_to_snake(key): value for key, value in all_params.items()}
43
- all_params.update({snake_to_camel(key): value for key, value in all_params.items()})
44
- return all_params
45
-
46
-
39
+ all_parameters_dict = get_payload_dict_from_event(event)
40
+ all_parameters_dict.update(get_path_parameters_dict_from_event(event))
41
+ all_parameters_dict.update(get_query_string_parameters_from_event(event))
42
+ all_parameters_dict = {camel_to_snake(key): value for key, value in all_parameters_dict.items()}
43
+ all_parameters_dict.update({snake_to_camel(key): value for key, value in all_parameters_dict.items()})
44
+ return all_parameters_dict
45
+
46
+ # TODO: move everything related to serverless to another file
47
47
  # TODO: test
48
- def handler_decorator(logger):
48
+ # TODO: remove this user_context once we can import it
49
+ def handler_decorator(logger, user_context = None):
49
50
  """Decorator for AWS Lambda handler functions. It wraps the handler function with logging and error handling.
50
51
  Usage:
51
52
  from python_sdk_remote.http_response import handler_decorator
@@ -60,8 +61,11 @@ def handler_decorator(logger):
60
61
  handler_response = None
61
62
  try:
62
63
  logger.start(object={"event": event, "context": context})
64
+ if user_context:
65
+ user_jwt = get_user_jwt_from_event(event)
66
+ user_context.login_using_user_jwt(user_jwt)
63
67
  request_parameters = get_request_parameters_from_event(event)
64
- body_result: dict = handler(request_parameters)
68
+ body_result = handler(request_parameters)
65
69
  handler_response = create_ok_http_response(body_result)
66
70
  except Exception as e:
67
71
  handler_response = create_error_http_response(e)
@@ -89,7 +93,7 @@ def get_user_jwt_from_event(event: dict) -> str:
89
93
  logger.start(object={"event": event})
90
94
  auth_header = event.get(HEADERS_KEY, {}).get(AUTHORIZATION_KEY)
91
95
  if auth_header is None:
92
- auth_header = event.get(HEADERS_KEY, {}).get(AUTHORIZATION_KEY.capitalize())
96
+ auth_header = event.get(HEADERS_KEY, {}).get(AUTHORIZATION_KEY.lower())
93
97
  user_jwt = auth_header.split(AUTHORIZATION_PREFIX)[1]
94
98
  logger.end(object={"user_jwt": user_jwt})
95
99
  return user_jwt
@@ -120,10 +124,17 @@ def create_error_http_response(exception: Exception, status_code: HTTPStatus = H
120
124
  def create_ok_http_response(body: Any) -> dict:
121
125
  logger.start(object={"body": body})
122
126
  # TODO: test sending statusCode/headers/body inside the body
127
+
128
+ if isinstance(body, dict):
129
+ status_code = body.get("statusCode")
130
+ headers = body.get("headers")
131
+ body_result = body.get("body")
132
+ else:
133
+ status_code = headers = body_result = None
123
134
  ok_http_response = {
124
- "statusCode": body.get("statusCode") or HTTPStatus.OK.value,
125
- "headers": body.get("headers") or create_return_http_headers(),
126
- "body": create_http_body(body.get("body") or body)
135
+ "statusCode": status_code or HTTPStatus.OK.value,
136
+ "headers": headers or create_return_http_headers(),
137
+ "body": create_http_body(body_result or body)
127
138
  }
128
139
  logger.end(object={"ok_http_response": ok_http_response})
129
140
  return ok_http_response
@@ -435,7 +435,7 @@ def deprecation_warning(old_name: str, new_name: str, start_date: date = None) -
435
435
  return
436
436
  warnings_message = f"Please use {old_name} instead of {new_name}."
437
437
  try:
438
- warnings_message += " Called from: " + inspect.stack()[1].filename
438
+ warnings_message += " Called from: " + inspect.stack()[2].filename
439
439
  except Exception:
440
440
  pass
441
441
  logger.warning(warnings_message)
@@ -7,7 +7,7 @@ package_dir = PACKAGE_NAME.replace("-", "_")
7
7
  # python -m build needs pyproject.toml or setup.py
8
8
  setuptools.setup(
9
9
  name="python-sdk-local", # TODO PACKAGE_NAME
10
- version='0.0.126', # https://pypi.org/project/python-sdk-remote/
10
+ version='0.0.128', # https://pypi.org/project/python-sdk-local/
11
11
  author="Circles",
12
12
  author_email="info@circlez.ai",
13
13
  description="PyPI Package for Circles Python SDK Local Python",