user-context-remote 0.0.89__tar.gz → 0.0.90__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: user-context-remote
3
- Version: 0.0.89
3
+ Version: 0.0.90
4
4
  Summary: PyPI Package for Circles User Context Local/Remote Python
5
5
  Home-page: https://github.com/circles-zone/user-context-remote-python-package
6
6
  Author: Circles
@@ -5,7 +5,7 @@ package_dir = PACKAGE_NAME.replace("-", "_")
5
5
 
6
6
  setuptools.setup(
7
7
  name=PACKAGE_NAME,
8
- version='0.0.89', # https://pypi.org/project/user-context-remote/
8
+ version='0.0.90', # https://pypi.org/project/user-context-remote/
9
9
  author="Circles",
10
10
  author_email="info@circlez.ai",
11
11
  description="PyPI Package for Circles User Context Local/Remote Python",
@@ -1,18 +1,19 @@
1
1
  import json
2
2
  from http import HTTPStatus
3
+ from functools import lru_cache
3
4
 
4
5
  import requests
5
6
  from language_remote.lang_code import LangCode
6
7
  from python_sdk_remote.mini_logger import MiniLogger as logger
7
- from python_sdk_remote.utilities import our_get_env
8
+ from python_sdk_remote.utilities import get_brand_name, get_environment_name, our_get_env
8
9
  from python_sdk_remote.http_response import create_return_http_headers
9
10
  from url_remote import action_name_enum, component_name_enum, entity_name_enum
10
11
  from url_remote.our_url import OurUrl
11
12
 
12
13
  # TODO Shall we use authentication-remote-python-package and not directly authentication-local-restapi-typescript?
13
14
 
14
- BRAND_NAME = our_get_env("BRAND_NAME")
15
- ENVIORNMENT_NAME = our_get_env("ENVIRONMENT_NAME")
15
+ BRAND_NAME = get_brand_name()
16
+ ENVIORNMENT_NAME = get_environment_name()
16
17
 
17
18
  # TODO How about using AUTHENTICATION_API_VERSION_DICT per environment_name in url-remote-python-package?
18
19
  AUTHENTICATION_API_VERSION = 1
@@ -20,14 +21,11 @@ DEFAULT_LANG_CODE = LangCode.ENGLISH
20
21
 
21
22
  # TODO: use data class instead of getter & setters
22
23
  class UserContext:
23
- # TODO Is it a good idea to user UserContext in UserContext?
24
- _instance = None
25
-
24
+ @lru_cache # instance per unique combination of user_identifier, password, user_jwt
26
25
  def __new__(cls, user_identifier: str = None, password: str = None, user_jwt: str = None):
27
- if cls._instance is None:
28
- cls._instance = super(UserContext, cls).__new__(cls)
29
- cls._instance._initialize(user_identifier=user_identifier, password=password, user_jwt=user_jwt)
30
- return cls._instance
26
+ user = super(UserContext, cls).__new__(cls)
27
+ user._initialize(user_identifier=user_identifier, password=password, user_jwt=user_jwt)
28
+ return user
31
29
 
32
30
  def _initialize(self, user_identifier: str = None, password: str = None, user_jwt: str = None) -> None:
33
31
  # self.user_identifier = user_identifier
@@ -53,34 +51,30 @@ class UserContext:
53
51
  self.__get_user_data_login_response(validate_user_jwt_response=validate_user_jwt_response)
54
52
 
55
53
  @staticmethod
56
- # Does it support no parameters? Yes
54
+ @lru_cache
57
55
  def login_using_user_identification_and_password(user_identifier: str = None, password: str = None):
58
56
  # LOGIN_USING_USER_IDENTIFICATION_AND_PASSWORD_METHOD_NAME = "login_using_user_identification_and_password"
59
57
  # TODO Why commented? Shall we add if (DebugMode)
60
58
  # logger.start(LOGIN_USING_USER_IDENTIFICATION_AND_PASSWORD_METHOD_NAME, object={"user_identifier": user_identifier, "password": password})
61
- if UserContext._instance is None:
62
- if user_identifier is None:
63
- user_identifier = our_get_env("PRODUCT_USER_IDENTIFIER")
64
- if password is None:
65
- password = our_get_env("PRODUCT_PASSWORD")
66
- if not user_identifier or not password:
67
- # To support cases with no PRODUCT_USER_IDENTIFIER and PRODUCT_PASSWORD in the deployment.
68
- logger.warning(
69
- "Warning: missing PRODUCT_USER_IDENTIFIER or PRODUCT_PASSWORD in .env file - WARNING -")
70
- return None
71
- UserContext._instance = UserContext(
72
- user_identifier=user_identifier, password=password)
73
- user = UserContext._instance
59
+ if user_identifier is None:
60
+ user_identifier = our_get_env("PRODUCT_USER_IDENTIFIER")
61
+ if password is None:
62
+ password = our_get_env("PRODUCT_PASSWORD")
63
+ if not user_identifier or not password:
64
+ # To support cases with no PRODUCT_USER_IDENTIFIER and PRODUCT_PASSWORD in the deployment.
65
+ logger.warning(
66
+ "Warning: missing PRODUCT_USER_IDENTIFIER or PRODUCT_PASSWORD in .env file - WARNING -")
67
+ return None
68
+ user = UserContext(user_identifier=user_identifier, password=password)
74
69
  # logger.end(LOGIN_USING_USER_IDENTIFICATION_AND_PASSWORD_METHOD_NAME,object={"user": str(user)})
75
70
  return user
76
71
 
77
72
  @staticmethod
73
+ @lru_cache
78
74
  def login_using_user_jwt(user_jwt: str) -> 'UserContext':
79
75
  # LOGIN_USING_USER_JWT_METHOD_NAME = "login_using_user_jwt"
80
76
  # logger.start(LOGIN_USING_USER_JWT_METHOD_NAME ,object={"user_jwt": user_jwt})
81
- if UserContext._instance is None:
82
- UserContext._instance = UserContext(user_jwt=user_jwt)
83
- user = UserContext._instance
77
+ user = UserContext(user_jwt=user_jwt)
84
78
  # logger.end(LOGIN_USING_USER_JWT_METHOD_NAME,object={"user": str(user)})
85
79
  return user
86
80
 
@@ -271,7 +265,8 @@ class UserContext:
271
265
  object={"validate_user_jwt_response": authentication_login_validate_user_jwt_response})
272
266
  return authentication_login_validate_user_jwt_response
273
267
 
274
- # Used only in one please
268
+ # this private method is being used only in one place
269
+ # TODO validate_user_jwt_response -> authenticate_product_user_response
275
270
  def __get_user_data_login_response(self, validate_user_jwt_response: requests.Response) -> None:
276
271
  _GET_USER_DATA_LOGIN_RESPONSE_METHOD_NAME = "get_user_data_login_response"
277
272
  # validate_user_jwt_response created in Authentication Local REST-API https://github.com/circles-zone/authentication-local-restapi-typescript-serverless-com/edit/dev/auth-restapi-serverless-com/src/services/auth-service/auth-service-impl.ts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: user-context-remote
3
- Version: 0.0.89
3
+ Version: 0.0.90
4
4
  Summary: PyPI Package for Circles User Context Local/Remote Python
5
5
  Home-page: https://github.com/circles-zone/user-context-remote-python-package
6
6
  Author: Circles