41
41
ACQUIRE_SSO_TOKEN_URL : Final [str ] = '/api/adb/sso/acquire'
42
42
SSO_TOKEN_INFO_URL : Final [str ] = '/api/adb/sso/info'
43
43
SSH_SSO_KEY_URL : Final [str ] = '/api/ssh/sso/key'
44
+ DEFAULT_SSH_FOLDER_PATH : Final [str ] = '~/.ssh'
44
45
45
46
46
47
class ArkSIASSOService (ArkService ):
@@ -351,7 +352,7 @@ def short_lived_token_info(self, get_token_info: ArkSIASSOGetTokenInfo) -> ArkSI
351
352
self ._logger .exception (f'Failed to parse get short lived token info response [{ str (ex )} ] - [{ response .text } ]' )
352
353
raise ArkServiceException (f'Failed to parse get short lived token info response [{ str (ex )} ]' ) from ex
353
354
354
- def short_lived_ssh_key (self , get_ssh_key : ArkSIASSOGetSSHKey ) -> None :
355
+ def short_lived_ssh_key (self , get_ssh_key : ArkSIASSOGetSSHKey ) -> str :
355
356
"""
356
357
Gets a short lived ssh sso key.
357
358
@@ -369,14 +370,18 @@ def short_lived_ssh_key(self, get_ssh_key: ArkSIASSOGetSSHKey) -> None:
369
370
if response .status_code != HTTPStatus .OK :
370
371
raise ArkServiceException (f'Failed to get short lived ssh sso key - [{ response .status_code } ] - [{ response .text } ]' )
371
372
try :
372
- folder_path = self .__expand_folder (get_ssh_key .folder )
373
+ folder_path = get_ssh_key .folder or DEFAULT_SSH_FOLDER_PATH
374
+ folder_path = self .__expand_folder (folder_path )
373
375
if not folder_path :
374
376
raise ArkServiceException ('Folder parameter is required' )
375
377
if not os .path .exists (folder_path ):
376
378
os .makedirs (folder_path )
377
- base_name = 'ssh_key'
378
- with open (f'{ folder_path } { os .path .sep } { base_name } ' , 'w' , encoding = 'utf-8' ) as file_handle :
379
+ claims = ArkJWTUtils .get_unverified_claims (self .__client .session_token )
380
+ base_name = f'sia_ssh_key_{ claims ["unique_name" ].split ("@" )[0 ]} .pem'
381
+ full_path = os .path .normpath (f'{ folder_path } { os .path .sep } { base_name } ' )
382
+ with open (full_path , 'w' , encoding = 'utf-8' ) as file_handle :
379
383
file_handle .write (response .text )
384
+ return full_path
380
385
except (ValidationError , JSONDecodeError , KeyError ) as ex :
381
386
self ._logger .exception (f'Failed to parse get short lived token info response [{ str (ex )} ] - [{ response .text } ]' )
382
387
raise ArkServiceException (f'Failed to parse get short lived token info response [{ str (ex )} ]' ) from ex
0 commit comments