@@ -283,6 +283,14 @@ async def retrieve_async(
283283 else :
284284 return Asset .model_validate (response .json ()["value" ][0 ])
285285
286+ def _ensure_robot_context (self ) -> None :
287+ try :
288+ is_user = self ._execution_context .robot_key is not None
289+ except ValueError :
290+ is_user = False
291+ if not is_user :
292+ raise ValueError ("This method can only be used for robot assets." )
293+
286294 @resource_override (resource_type = "asset" )
287295 @traced (
288296 name = "assets_credential" , run_type = "uipath" , hide_input = True , hide_output = True
@@ -294,11 +302,9 @@ def retrieve_credential(
294302 folder_key : Optional [str ] = None ,
295303 folder_path : Optional [str ] = None ,
296304 ) -> Optional [str ]:
297- """Gets a specified Orchestrator credential.
298-
299- The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable)
305+ """Get the decrypted password of a Credential asset.
300306
301- Related Activity: [Get Credential](https://docs.uipath.com/activities/other/latest/workflow/get-robot-credential)
307+ The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable).
302308
303309 Args:
304310 name (str): The name of the credential asset.
@@ -309,22 +315,10 @@ def retrieve_credential(
309315 Optional[str]: The decrypted credential password.
310316
311317 Raises:
312- ValueError: If the method is called for a user asset .
318+ ValueError: If called outside a robot context (no `UIPATH_ROBOT_KEY`) .
313319 """
314- try :
315- is_user = self ._execution_context .robot_key is not None
316- except ValueError :
317- is_user = False
318-
319- if not is_user :
320- raise ValueError ("This method can only be used for robot assets." )
321-
322- spec = self ._retrieve_spec (
323- name ,
324- folder_key = folder_key ,
325- folder_path = folder_path ,
326- )
327-
320+ self ._ensure_robot_context ()
321+ spec = self ._retrieve_spec (name , folder_key = folder_key , folder_path = folder_path )
328322 response = self .request (
329323 spec .method ,
330324 url = spec .endpoint ,
@@ -333,10 +327,7 @@ def retrieve_credential(
333327 content = spec .content ,
334328 headers = spec .headers ,
335329 )
336-
337- user_asset = UserAsset .model_validate (response .json ())
338-
339- return user_asset .credential_password
330+ return UserAsset .model_validate (response .json ()).credential_password
340331
341332 @resource_override (resource_type = "asset" )
342333 @traced (
@@ -349,11 +340,9 @@ async def retrieve_credential_async(
349340 folder_key : Optional [str ] = None ,
350341 folder_path : Optional [str ] = None ,
351342 ) -> Optional [str ]:
352- """Asynchronously gets a specified Orchestrator credential .
343+ """Asynchronously get the decrypted password of a Credential asset .
353344
354- The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable)
355-
356- Related Activity: [Get Credential](https://docs.uipath.com/activities/other/latest/workflow/get-robot-credential)
345+ The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable).
357346
358347 Args:
359348 name (str): The name of the credential asset.
@@ -364,34 +353,91 @@ async def retrieve_credential_async(
364353 Optional[str]: The decrypted credential password.
365354
366355 Raises:
367- ValueError: If the method is called for a user asset .
356+ ValueError: If called outside a robot context (no `UIPATH_ROBOT_KEY`) .
368357 """
369- try :
370- is_user = self ._execution_context .robot_key is not None
371- except ValueError :
372- is_user = False
358+ self ._ensure_robot_context ()
359+ spec = self ._retrieve_spec (name , folder_key = folder_key , folder_path = folder_path )
360+ response = await self .request_async (
361+ spec .method ,
362+ url = spec .endpoint ,
363+ params = spec .params ,
364+ json = spec .json ,
365+ content = spec .content ,
366+ headers = spec .headers ,
367+ )
368+ return UserAsset .model_validate (response .json ()).credential_password
373369
374- if not is_user :
375- raise ValueError ("This method can only be used for robot assets." )
370+ @resource_override (resource_type = "asset" )
371+ @traced (name = "assets_secret" , run_type = "uipath" , hide_input = True , hide_output = True )
372+ def retrieve_secret (
373+ self ,
374+ name : str ,
375+ * ,
376+ folder_key : Optional [str ] = None ,
377+ folder_path : Optional [str ] = None ,
378+ ) -> Optional [str ]:
379+ """Get the decrypted value of a Secret asset.
376380
377- spec = self ._retrieve_spec (
378- name ,
379- folder_key = folder_key ,
380- folder_path = folder_path ,
381- )
381+ The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable).
382382
383- response = await self .request_async (
383+ Args:
384+ name (str): The name of the secret asset.
385+ folder_key (Optional[str]): The key of the folder to execute the process in. Override the default one set in the SDK config.
386+ folder_path (Optional[str]): The path of the folder to execute the process in. Override the default one set in the SDK config.
387+
388+ Returns:
389+ Optional[str]: The decrypted secret value.
390+
391+ Raises:
392+ ValueError: If called outside a robot context (no `UIPATH_ROBOT_KEY`).
393+ """
394+ self ._ensure_robot_context ()
395+ spec = self ._retrieve_spec (name , folder_key = folder_key , folder_path = folder_path )
396+ response = self .request (
384397 spec .method ,
385398 url = spec .endpoint ,
386399 params = spec .params ,
387400 json = spec .json ,
388401 content = spec .content ,
389402 headers = spec .headers ,
390403 )
404+ return UserAsset .model_validate (response .json ()).secret_value
391405
392- user_asset = UserAsset .model_validate (response .json ())
406+ @resource_override (resource_type = "asset" )
407+ @traced (name = "assets_secret" , run_type = "uipath" , hide_input = True , hide_output = True )
408+ async def retrieve_secret_async (
409+ self ,
410+ name : str ,
411+ * ,
412+ folder_key : Optional [str ] = None ,
413+ folder_path : Optional [str ] = None ,
414+ ) -> Optional [str ]:
415+ """Asynchronously get the decrypted value of a Secret asset.
416+
417+ The robot id is retrieved from the execution context (`UIPATH_ROBOT_KEY` environment variable).
418+
419+ Args:
420+ name (str): The name of the secret asset.
421+ folder_key (Optional[str]): The key of the folder to execute the process in. Override the default one set in the SDK config.
422+ folder_path (Optional[str]): The path of the folder to execute the process in. Override the default one set in the SDK config.
423+
424+ Returns:
425+ Optional[str]: The decrypted secret value.
393426
394- return user_asset .credential_password
427+ Raises:
428+ ValueError: If called outside a robot context (no `UIPATH_ROBOT_KEY`).
429+ """
430+ self ._ensure_robot_context ()
431+ spec = self ._retrieve_spec (name , folder_key = folder_key , folder_path = folder_path )
432+ response = await self .request_async (
433+ spec .method ,
434+ url = spec .endpoint ,
435+ params = spec .params ,
436+ json = spec .json ,
437+ content = spec .content ,
438+ headers = spec .headers ,
439+ )
440+ return UserAsset .model_validate (response .json ()).secret_value
395441
396442 @traced (name = "assets_update" , run_type = "uipath" , hide_input = True , hide_output = True )
397443 def update (
0 commit comments