user-context-remote 0.0.86__tar.gz → 0.0.87__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.86
3
+ Version: 0.0.87
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.86', # https://pypi.org/project/user-context-remote/
8
+ version='0.0.87', # 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",
@@ -213,8 +213,7 @@ class UserContext:
213
213
  logger.info("authentication_login_response_json.json()" + str(authentication_login_response_json))
214
214
  logger.info("authentication_login_response_json.json() with json()" + str(
215
215
  authentication_login_response_json.json()))
216
- # TODO Put this in try/except as there might be no "data" or no "userJwt"
217
- self.user_jwt = authentication_login_response_json.json()["data"]["userJwt"]
216
+ self.__process_response(authentication_login_response_json)
218
217
  logger.end(AUTHENTICATE_BY_USER_IDENTIFICATION_AND_PASSWORD_METHOD_NAME, object={
219
218
  "user_jwt": self.user_jwt})
220
219
  return authentication_login_response_json
@@ -225,6 +224,26 @@ class UserContext:
225
224
  logger.end(AUTHENTICATE_BY_USER_IDENTIFICATION_AND_PASSWORD_METHOD_NAME)
226
225
  raise
227
226
 
227
+ def __process_response(self, authentication_login_response_json):
228
+ try:
229
+ response_json = authentication_login_response_json.json()
230
+ data = response_json.get("data")
231
+ if data is None:
232
+ logger.error("Error: 'data' not found in authentication_login_response_json.json()",
233
+ object={"authentication_login_response_json": authentication_login_response_json.text,
234
+ "response_json": response_json})
235
+ else:
236
+ self.user_jwt = data.get("userJwt")
237
+ if self.user_jwt is None:
238
+ logger.error(
239
+ "Error: 'userJwt' not found in 'data'.",
240
+ object={"data": data,
241
+ "authentication_login_response_json": authentication_login_response_json.text})
242
+ except Exception as exception:
243
+ logger.error(
244
+ "Error(Exception): user-context-remote-python _authenticate() " + str(exception),
245
+ object={"authentication_login_response_json": authentication_login_response_json.text})
246
+
228
247
  def _authenticate_by_user_jwt(self, user_jwt: str) -> requests.Response:
229
248
  AUTHENTICATE_BY_USER_JWT_METHOD_NAME = "_authenticate_by_user_jwt"
230
249
  logger.start(AUTHENTICATE_BY_USER_JWT_METHOD_NAME,
@@ -257,24 +276,25 @@ class UserContext:
257
276
  _GET_USER_DATA_LOGIN_RESPONSE_METHOD_NAME = "get_user_data_login_response"
258
277
  # 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
259
278
  # TODO validate_user_jwt_data_dict
260
- data_dict = validate_user_jwt_response.json()['data']
279
+ response_json = validate_user_jwt_response.json()
280
+ data_dict = response_json.get('data')
261
281
  first_name = last_name = None
262
282
  if "userDetails" in data_dict:
263
283
  # TODO user_details
264
- user_details = data_dict["userDetails"]
284
+ user_details: dict = data_dict.get("userDetails")
265
285
 
266
286
  if "profileId" in user_details:
267
- profile_id = user_details["profileId"]
287
+ profile_id = user_details.get("profileId")
268
288
  self._set_real_profile_id(int(profile_id))
269
289
  self._set_effective_profile_id(int(profile_id))
270
290
 
271
291
  if "userId" in user_details:
272
- user_id = user_details["userId"]
292
+ user_id = user_details.get("userId")
273
293
  self._set_effective_user_id(int(user_id))
274
294
  self._set_real_user_id(int(user_id))
275
295
 
276
296
  if "profilePreferredLangCode" in user_details:
277
- lang_code = user_details["profilePreferredLangCode"]
297
+ lang_code = user_details.get("profilePreferredLangCode")
278
298
  if lang_code is None: # default lang_code is en
279
299
  lang_code = "en"
280
300
  # change to lang_code enum object
@@ -282,15 +302,15 @@ class UserContext:
282
302
  self._set_effective_profile_preferred_lang_code(lang_code)
283
303
 
284
304
  if "firstName" in user_details:
285
- first_name = user_details["firstName"]
305
+ first_name = user_details.get("firstName")
286
306
  self._set_real_first_name(first_name)
287
307
 
288
308
  if "lastName" in user_details:
289
- last_name = user_details["lastName"]
309
+ last_name = user_details.get("lastName")
290
310
  self._set_real_last_name(last_name)
291
311
 
292
312
  if "subscriptionId" in user_details:
293
- subscription_id = user_details["subscriptionId"]
313
+ subscription_id = user_details.get("subscriptionId")
294
314
  logger.end(
295
315
  _GET_USER_DATA_LOGIN_RESPONSE_METHOD_NAME + " Got subscription_id from the cloud. subscription_id=" +
296
316
  str(subscription_id), object={"subscription_id": subscription_id})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: user-context-remote
3
- Version: 0.0.86
3
+ Version: 0.0.87
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