@@ -282,11 +282,11 @@ def authenticate(
282
282
)
283
283
284
284
# waiting for MFA authentication
285
- if ret ["data" ].get ("nextAction" ) in (
285
+ if ret ["data" ] and ret [ "data" ] .get ("nextAction" ) in (
286
286
"EXT_AUTHN_DUO_ALL" ,
287
287
"EXT_AUTHN_DUO_PUSH_N_PASSCODE" ,
288
288
):
289
- body ["inFlightCtx" ] = ret ["data" ][ "inFlightCtx" ]
289
+ body ["inFlightCtx" ] = ret ["data" ]. get ( "inFlightCtx" )
290
290
body ["data" ]["EXT_AUTHN_DUO_METHOD" ] = "push"
291
291
self .ret = {"message" : "Timeout" , "data" : {}}
292
292
@@ -310,9 +310,13 @@ def post_request_wrapper(self, url, headers, body) -> None:
310
310
t .join (timeout = timeout )
311
311
312
312
ret = self .ret
313
- if ret and ret ["data" ].get ("nextAction" ) == "EXT_AUTHN_SUCCESS" :
313
+ if (
314
+ ret
315
+ and ret ["data" ]
316
+ and ret ["data" ].get ("nextAction" ) == "EXT_AUTHN_SUCCESS"
317
+ ):
314
318
body = copy .deepcopy (body_template )
315
- body ["inFlightCtx" ] = ret ["data" ][ "inFlightCtx" ]
319
+ body ["inFlightCtx" ] = ret ["data" ]. get ( "inFlightCtx" )
316
320
# final request to get tokens
317
321
ret = self ._rest ._post_request (
318
322
url ,
@@ -321,7 +325,7 @@ def post_request_wrapper(self, url, headers, body) -> None:
321
325
timeout = self ._rest ._connection .login_timeout ,
322
326
socket_timeout = self ._rest ._connection .login_timeout ,
323
327
)
324
- elif not ret or not ret ["data" ].get ("token" ):
328
+ elif not ret or not ret ["data" ] or not ret [ "data" ] .get ("token" ):
325
329
# not token is returned.
326
330
Error .errorhandler_wrapper (
327
331
self ._rest ._connection ,
@@ -343,10 +347,10 @@ def post_request_wrapper(self, url, headers, body) -> None:
343
347
)
344
348
return session_parameters # required for unit test
345
349
346
- elif ret ["data" ].get ("nextAction" ) == "PWD_CHANGE" :
350
+ elif ret ["data" ] and ret [ "data" ] .get ("nextAction" ) == "PWD_CHANGE" :
347
351
if callable (password_callback ):
348
352
body = copy .deepcopy (body_template )
349
- body ["inFlightCtx" ] = ret ["data" ][ "inFlightCtx" ]
353
+ body ["inFlightCtx" ] = ret ["data" ]. get ( "inFlightCtx" )
350
354
body ["data" ]["LOGIN_NAME" ] = user
351
355
body ["data" ]["PASSWORD" ] = (
352
356
auth_instance .password
@@ -411,41 +415,59 @@ def post_request_wrapper(self, url, headers, body) -> None:
411
415
)
412
416
else :
413
417
logger .debug (
414
- "token = %s" , "******" if ret ["data" ]["token" ] is not None else "NULL"
418
+ "token = %s" ,
419
+ "******"
420
+ if ret ["data" ] and ret ["data" ].get ("token" ) is not None
421
+ else "NULL" ,
415
422
)
416
423
logger .debug (
417
424
"master_token = %s" ,
418
- "******" if ret ["data" ]["masterToken" ] is not None else "NULL" ,
425
+ "******"
426
+ if ret ["data" ] and ret ["data" ].get ("masterToken" ) is not None
427
+ else "NULL" ,
419
428
)
420
429
logger .debug (
421
430
"id_token = %s" ,
422
- "******" if ret ["data" ].get ("idToken" ) is not None else "NULL" ,
431
+ "******"
432
+ if ret ["data" ] and ret ["data" ].get ("idToken" ) is not None
433
+ else "NULL" ,
423
434
)
424
435
logger .debug (
425
436
"mfa_token = %s" ,
426
- "******" if ret ["data" ].get ("mfaToken" ) is not None else "NULL" ,
437
+ "******"
438
+ if ret ["data" ] and ret ["data" ].get ("mfaToken" ) is not None
439
+ else "NULL" ,
427
440
)
441
+ if not ret ["data" ]:
442
+ Error .errorhandler_wrapper (
443
+ None ,
444
+ None ,
445
+ Error ,
446
+ {
447
+ "msg" : "There is no data in the returning response, please retry the operation."
448
+ },
449
+ )
428
450
self ._rest .update_tokens (
429
- ret ["data" ][ "token" ] ,
430
- ret ["data" ][ "masterToken" ] ,
451
+ ret ["data" ]. get ( "token" ) ,
452
+ ret ["data" ]. get ( "masterToken" ) ,
431
453
master_validity_in_seconds = ret ["data" ].get ("masterValidityInSeconds" ),
432
454
id_token = ret ["data" ].get ("idToken" ),
433
455
mfa_token = ret ["data" ].get ("mfaToken" ),
434
456
)
435
457
self .write_temporary_credentials (
436
458
self ._rest ._host , user , session_parameters , ret
437
459
)
438
- if "sessionId" in ret ["data" ]:
439
- self ._rest ._connection ._session_id = ret ["data" ][ "sessionId" ]
440
- if "sessionInfo" in ret ["data" ]:
441
- session_info = ret ["data" ][ "sessionInfo" ]
460
+ if ret [ "data" ] and "sessionId" in ret ["data" ]:
461
+ self ._rest ._connection ._session_id = ret ["data" ]. get ( "sessionId" )
462
+ if ret [ "data" ] and "sessionInfo" in ret ["data" ]:
463
+ session_info = ret ["data" ]. get ( "sessionInfo" )
442
464
self ._rest ._connection ._database = session_info .get ("databaseName" )
443
465
self ._rest ._connection ._schema = session_info .get ("schemaName" )
444
466
self ._rest ._connection ._warehouse = session_info .get ("warehouseName" )
445
467
self ._rest ._connection ._role = session_info .get ("roleName" )
446
- if "parameters" in ret ["data" ]:
468
+ if ret [ "data" ] and "parameters" in ret ["data" ]:
447
469
session_parameters .update (
448
- {p ["name" ]: p ["value" ] for p in ret ["data" ][ "parameters" ] }
470
+ {p ["name" ]: p ["value" ] for p in ret ["data" ]. get ( "parameters" ) }
449
471
)
450
472
self ._rest ._connection ._update_parameters (session_parameters )
451
473
return session_parameters
0 commit comments