Skip to content

Commit 049df5e

Browse files
committed
Version 2.0.0
1 parent e90c5b2 commit 049df5e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

ark_sdk_python/models/actions/services/ark_sia_exec_action_consts.py

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
ArkSIASSOGetShortLivedOracleWallet,
5454
ArkSIASSOGetShortLivedPassword,
5555
ArkSIASSOGetShortLivedRDPFile,
56+
ArkSIASSOGetSSHKey,
57+
ArkSIASSOGetTokenInfo,
5658
)
5759
from ark_sdk_python.models.services.sia.workspaces.db import (
5860
ArkSIADBAddDatabase,
@@ -208,6 +210,8 @@
208210
'short-lived-client-certificate': ArkSIASSOGetShortLivedClientCertificate,
209211
'short-lived-oracle-wallet': ArkSIASSOGetShortLivedOracleWallet,
210212
'short-lived-rdp-file': ArkSIASSOGetShortLivedRDPFile,
213+
'short-lived-token-info': ArkSIASSOGetTokenInfo,
214+
'short-lived-ssh-key': ArkSIASSOGetSSHKey,
211215
}
212216
SSO_ACTION: Final[ArkServiceActionDefinition] = ArkServiceActionDefinition(action_name='sso', schemas=SSO_ACTION_TO_SCHEMA_MAP)
213217
DB_ACTION_TO_SCHEMA_MAP: Final[Dict[(str, Optional[Type[ArkModel]])]] = {

ark_sdk_python/services/sia/sso/ark_sia_sso_service.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ACQUIRE_SSO_TOKEN_URL: Final[str] = '/api/adb/sso/acquire'
4242
SSO_TOKEN_INFO_URL: Final[str] = '/api/adb/sso/info'
4343
SSH_SSO_KEY_URL: Final[str] = '/api/ssh/sso/key'
44+
DEFAULT_SSH_FOLDER_PATH: Final[str] = '~/.ssh'
4445

4546

4647
class ArkSIASSOService(ArkService):
@@ -351,7 +352,7 @@ def short_lived_token_info(self, get_token_info: ArkSIASSOGetTokenInfo) -> ArkSI
351352
self._logger.exception(f'Failed to parse get short lived token info response [{str(ex)}] - [{response.text}]')
352353
raise ArkServiceException(f'Failed to parse get short lived token info response [{str(ex)}]') from ex
353354

354-
def short_lived_ssh_key(self, get_ssh_key: ArkSIASSOGetSSHKey) -> None:
355+
def short_lived_ssh_key(self, get_ssh_key: ArkSIASSOGetSSHKey) -> str:
355356
"""
356357
Gets a short lived ssh sso key.
357358
@@ -369,14 +370,18 @@ def short_lived_ssh_key(self, get_ssh_key: ArkSIASSOGetSSHKey) -> None:
369370
if response.status_code != HTTPStatus.OK:
370371
raise ArkServiceException(f'Failed to get short lived ssh sso key - [{response.status_code}] - [{response.text}]')
371372
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)
373375
if not folder_path:
374376
raise ArkServiceException('Folder parameter is required')
375377
if not os.path.exists(folder_path):
376378
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:
379383
file_handle.write(response.text)
384+
return full_path
380385
except (ValidationError, JSONDecodeError, KeyError) as ex:
381386
self._logger.exception(f'Failed to parse get short lived token info response [{str(ex)}] - [{response.text}]')
382387
raise ArkServiceException(f'Failed to parse get short lived token info response [{str(ex)}]') from ex

0 commit comments

Comments
 (0)