From 1f136c84f278dd5ecbff1876bc62f45ff70ab30f Mon Sep 17 00:00:00 2001 From: Gheorghita Hurmuz Date: Tue, 4 Feb 2025 16:59:11 +0200 Subject: [PATCH 1/2] refactor: change folder structure --- src/uipath_sdk/__init__.py | 4 +- src/uipath_sdk/_assets_service.py | 61 ------------------- .../{_uipath_client_config.py => _config.py} | 2 +- src/uipath_sdk/_models/__init__.py | 3 + src/uipath_sdk/_models/assets.py | 23 +++++++ src/uipath_sdk/_services/__init__.py | 4 ++ .../{ => _services}/_base_service.py | 0 src/uipath_sdk/_services/assets_service.py | 48 +++++++++++++++ .../processes_service.py} | 9 ++- .../{_uipath_client.py => _uipath_sdk.py} | 9 ++- src/uipath_sdk/_utils/__init__.py | 3 + .../{_utils.py => _utils/singleton.py} | 3 - 12 files changed, 96 insertions(+), 73 deletions(-) delete mode 100644 src/uipath_sdk/_assets_service.py rename src/uipath_sdk/{_uipath_client_config.py => _config.py} (95%) create mode 100644 src/uipath_sdk/_models/__init__.py create mode 100644 src/uipath_sdk/_models/assets.py create mode 100644 src/uipath_sdk/_services/__init__.py rename src/uipath_sdk/{ => _services}/_base_service.py (100%) create mode 100644 src/uipath_sdk/_services/assets_service.py rename src/uipath_sdk/{_processes_service.py => _services/processes_service.py} (61%) rename src/uipath_sdk/{_uipath_client.py => _uipath_sdk.py} (84%) create mode 100644 src/uipath_sdk/_utils/__init__.py rename src/uipath_sdk/{_utils.py => _utils/singleton.py} (92%) diff --git a/src/uipath_sdk/__init__.py b/src/uipath_sdk/__init__.py index fdeaea0a7..9336c153c 100644 --- a/src/uipath_sdk/__init__.py +++ b/src/uipath_sdk/__init__.py @@ -1 +1,3 @@ -from ._uipath_client import UiPathClient as UiPathClient +from ._uipath_sdk import UiPathSDK + +__all__ = ["UiPathSDK"] diff --git a/src/uipath_sdk/_assets_service.py b/src/uipath_sdk/_assets_service.py deleted file mode 100644 index e009b9d86..000000000 --- a/src/uipath_sdk/_assets_service.py +++ /dev/null @@ -1,61 +0,0 @@ -from typing import TypedDict, cast - -from ._base_service import BaseService - - -class CredentialsConnectionData(TypedDict): - url: str - body: str - bearerToken: str - - -class UserAsset(TypedDict): - Name: str - Value: str - ValueType: str - StringValue: str - BoolValue: bool - IntValue: int - CredentialUsername: str - CredentialPassword: str - ExternalName: str - CredentialStoreId: int - KeyValueList: list[dict[str, str]] - ConnectionData: CredentialsConnectionData - Id: int - - -class RobotAssetsService(BaseService): - def retrieve( - self, - assetName: str, - robotKey: str, - ) -> UserAsset: - return cast( - UserAsset, - self.client.post( - "/orchestrator_/odata/Assets/UiPath.Server.Configuration.OData.GetRobotAssetByNameForRobotKey", - content=str( - { - "assetName": assetName, - "robotKey": robotKey, - "supportsCredentialsProxyDisconnected": True, - } - ), - ).json(), - ) - - def update( - self, - robotKey: str, - robotAsset: UserAsset, - ) -> None: - self.client.post( - "/orchestrator_/odata/Assets/UiPath.Server.Configuration.OData.SetRobotAssetByRobotKey", - content=str( - { - "robotKey": robotKey, - "robotAsset": robotAsset, - } - ), - ) diff --git a/src/uipath_sdk/_uipath_client_config.py b/src/uipath_sdk/_config.py similarity index 95% rename from src/uipath_sdk/_uipath_client_config.py rename to src/uipath_sdk/_config.py index a7bdac76d..21e3bf8eb 100644 --- a/src/uipath_sdk/_uipath_client_config.py +++ b/src/uipath_sdk/_config.py @@ -7,7 +7,7 @@ load_dotenv() -class UiPathClientConfig(metaclass=SingletonMeta): +class Config(metaclass=SingletonMeta): def __init__(self) -> None: self._uipath_url = self._get_env_var("UIPATH_URL") self._account_name = self._get_env_var("UIPATH_ACCOUNT_NAME") diff --git a/src/uipath_sdk/_models/__init__.py b/src/uipath_sdk/_models/__init__.py new file mode 100644 index 000000000..1aaee2c78 --- /dev/null +++ b/src/uipath_sdk/_models/__init__.py @@ -0,0 +1,3 @@ +from .assets import UserAsset + +__all__ = ["UserAsset"] diff --git a/src/uipath_sdk/_models/assets.py b/src/uipath_sdk/_models/assets.py new file mode 100644 index 000000000..a88293be5 --- /dev/null +++ b/src/uipath_sdk/_models/assets.py @@ -0,0 +1,23 @@ +from typing import TypedDict + + +class CredentialsConnectionData(TypedDict): + url: str + body: str + bearerToken: str + + +class UserAsset(TypedDict): + Name: str + Value: str + ValueType: str + StringValue: str + BoolValue: bool + IntValue: int + CredentialUsername: str + CredentialPassword: str + ExternalName: str + CredentialStoreId: int + KeyValueList: list[dict[str, str]] + ConnectionData: CredentialsConnectionData + Id: int diff --git a/src/uipath_sdk/_services/__init__.py b/src/uipath_sdk/_services/__init__.py new file mode 100644 index 000000000..b99bf32c1 --- /dev/null +++ b/src/uipath_sdk/_services/__init__.py @@ -0,0 +1,4 @@ +from .assets_service import RobotAssetsService +from .processes_service import ProcessesService + +__all__ = ["RobotAssetsService", "ProcessesService"] diff --git a/src/uipath_sdk/_base_service.py b/src/uipath_sdk/_services/_base_service.py similarity index 100% rename from src/uipath_sdk/_base_service.py rename to src/uipath_sdk/_services/_base_service.py diff --git a/src/uipath_sdk/_services/assets_service.py b/src/uipath_sdk/_services/assets_service.py new file mode 100644 index 000000000..97235bcad --- /dev/null +++ b/src/uipath_sdk/_services/assets_service.py @@ -0,0 +1,48 @@ +from typing import cast + +from httpx import Response + +from .._models import UserAsset +from ._base_service import BaseService + + +class RobotAssetsService(BaseService): + def retrieve( + self, + assetName: str, + robotKey: str, + ) -> UserAsset: + endpoint = "/orchestrator_/odata/Assets/UiPath.Server.Configuration.OData.GetRobotAssetByNameForRobotKey" + content = str( + { + "assetName": assetName, + "robotKey": robotKey, + "supportsCredentialsProxyDisconnected": True, + } + ) + + return cast( + UserAsset, + self.client.post( + endpoint, + content=content, + ).json(), + ) + + def update( + self, + robotKey: str, + robotAsset: UserAsset, + ) -> Response: + endpoint = "/orchestrator_/odata/Assets/UiPath.Server.Configuration.OData.SetRobotAssetByRobotKey" + content = str( + { + "robotKey": robotKey, + "robotAsset": robotAsset, + } + ) + + return self.client.post( + endpoint, + content=content, + ) diff --git a/src/uipath_sdk/_processes_service.py b/src/uipath_sdk/_services/processes_service.py similarity index 61% rename from src/uipath_sdk/_processes_service.py rename to src/uipath_sdk/_services/processes_service.py index 523572898..a757ffccb 100644 --- a/src/uipath_sdk/_processes_service.py +++ b/src/uipath_sdk/_services/processes_service.py @@ -5,7 +5,12 @@ class ProcessesService(BaseService): def invoke_process(self, release_key: str) -> Response: + endpoint = ( + "/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs" + ) + content = str({"startInfo": {"ReleaseKey": release_key}}) + return self.client.post( - "/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs", - content=str({"startInfo": {"ReleaseKey": release_key}}), + endpoint, + content=content, ) diff --git a/src/uipath_sdk/_uipath_client.py b/src/uipath_sdk/_uipath_sdk.py similarity index 84% rename from src/uipath_sdk/_uipath_client.py rename to src/uipath_sdk/_uipath_sdk.py index bae5aeed4..e1fb1a2f4 100644 --- a/src/uipath_sdk/_uipath_client.py +++ b/src/uipath_sdk/_uipath_sdk.py @@ -1,13 +1,12 @@ from httpx import Client, Headers -from ._assets_service import RobotAssetsService -from ._processes_service import ProcessesService -from ._uipath_client_config import UiPathClientConfig +from ._config import Config +from ._services import ProcessesService, RobotAssetsService -class UiPathClient: +class UiPathSDK: def __init__(self, secret: str | None) -> None: - self.config = UiPathClientConfig() + self.config = Config() if secret is not None: self.config.secret = secret diff --git a/src/uipath_sdk/_utils/__init__.py b/src/uipath_sdk/_utils/__init__.py new file mode 100644 index 000000000..38098180c --- /dev/null +++ b/src/uipath_sdk/_utils/__init__.py @@ -0,0 +1,3 @@ +from .singleton import SingletonMeta + +__all__ = ["SingletonMeta"] diff --git a/src/uipath_sdk/_utils.py b/src/uipath_sdk/_utils/singleton.py similarity index 92% rename from src/uipath_sdk/_utils.py rename to src/uipath_sdk/_utils/singleton.py index 6c3965e04..112978518 100644 --- a/src/uipath_sdk/_utils.py +++ b/src/uipath_sdk/_utils/singleton.py @@ -9,6 +9,3 @@ def __call__(cls, *args: tuple[Any, ...], **kwargs: dict[str, Any]) -> type: instance = super().__call__(*args, **kwargs) cls._instances[cls] = instance return cls._instances[cls] - - -# TODO: add utils for retry From 3b3cc4ec63a3d97b85352c8921cbfe9eb29ab2e0 Mon Sep 17 00:00:00 2001 From: Gheorghita Hurmuz Date: Tue, 4 Feb 2025 16:59:38 +0200 Subject: [PATCH 2/2] chore: bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5968c9a71..2ff99aed9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath_sdk" -version = "0.0.2" +version = "0.0.3" description = "UiPath Client for the UiPath API" readme = "README.md" requires-python = ">=3.13"