|
7 | 7 | from .._config import Config |
8 | 8 | from .._execution_context import ExecutionContext |
9 | 9 | from .._utils import Endpoint, RequestSpec, header_folder, infer_bindings |
10 | | -from ..models import Connection, ConnectionToken, EventArguments |
| 10 | +from ..models import Connection, ConnectionMetadata, ConnectionToken, EventArguments |
11 | 11 | from ..models.connections import ConnectionTokenType |
12 | 12 | from ..tracing._traced import traced |
13 | 13 | from ._base_service import BaseService |
@@ -54,6 +54,31 @@ def retrieve(self, key: str) -> Connection: |
54 | 54 | response = self.request(spec.method, url=spec.endpoint) |
55 | 55 | return Connection.model_validate(response.json()) |
56 | 56 |
|
| 57 | + @traced( |
| 58 | + name="connections_metadata", |
| 59 | + run_type="uipath", |
| 60 | + hide_output=True, |
| 61 | + ) |
| 62 | + def metadata( |
| 63 | + self, element_instance_id: int, tool_path: str, schema_mode: bool = True |
| 64 | + ) -> ConnectionMetadata: |
| 65 | + """Synchronously retrieve connection API metadata. |
| 66 | +
|
| 67 | + This method fetches the metadata for a connection, |
| 68 | + which can be used to establish communication with an external service. |
| 69 | +
|
| 70 | + Args: |
| 71 | + element_instance_id (int): The element instance ID of the connection. |
| 72 | + tool_path (str): The tool path to retrieve metadata for. |
| 73 | + schema_mode (bool): Whether or not to represent the output schema in the response fields. |
| 74 | +
|
| 75 | + Returns: |
| 76 | + ConnectionMetadata: The connection metadata. |
| 77 | + """ |
| 78 | + spec = self._metadata_spec(element_instance_id, tool_path, schema_mode) |
| 79 | + response = self.request(spec.method, url=spec.endpoint, headers=spec.headers) |
| 80 | + return ConnectionMetadata.model_validate(response.json()) |
| 81 | + |
57 | 82 | @traced(name="connections_list", run_type="uipath") |
58 | 83 | def list( |
59 | 84 | self, |
@@ -186,6 +211,33 @@ async def retrieve_async(self, key: str) -> Connection: |
186 | 211 | response = await self.request_async(spec.method, url=spec.endpoint) |
187 | 212 | return Connection.model_validate(response.json()) |
188 | 213 |
|
| 214 | + @traced( |
| 215 | + name="connections_metadata", |
| 216 | + run_type="uipath", |
| 217 | + hide_output=True, |
| 218 | + ) |
| 219 | + async def metadata_async( |
| 220 | + self, element_instance_id: int, tool_path: str, schema_mode: bool = True |
| 221 | + ) -> ConnectionMetadata: |
| 222 | + """Asynchronously retrieve connection API metadata. |
| 223 | +
|
| 224 | + This method fetches the metadata for a connection, |
| 225 | + which can be used to establish communication with an external service. |
| 226 | +
|
| 227 | + Args: |
| 228 | + element_instance_id (int): The element instance ID of the connection. |
| 229 | + tool_path (str): The tool path to retrieve metadata for. |
| 230 | + schema_mode (bool): Whether or not to represent the output schema in the response fields. |
| 231 | +
|
| 232 | + Returns: |
| 233 | + ConnectionMetadata: The connection metadata. |
| 234 | + """ |
| 235 | + spec = self._metadata_spec(element_instance_id, tool_path, schema_mode) |
| 236 | + response = await self.request_async( |
| 237 | + spec.method, url=spec.endpoint, headers=spec.headers |
| 238 | + ) |
| 239 | + return ConnectionMetadata.model_validate(response.json()) |
| 240 | + |
189 | 241 | @traced( |
190 | 242 | name="connections_retrieve_token", |
191 | 243 | run_type="uipath", |
@@ -324,6 +376,20 @@ def _retrieve_spec(self, key: str) -> RequestSpec: |
324 | 376 | endpoint=Endpoint(f"/connections_/api/v1/Connections/{key}"), |
325 | 377 | ) |
326 | 378 |
|
| 379 | + def _metadata_spec( |
| 380 | + self, element_instance_id: int, tool_path: str, schema_mode: bool |
| 381 | + ) -> RequestSpec: |
| 382 | + metadata_endpoint_url = f"/elements_/v3/element/instances/{element_instance_id}/elements/{tool_path}/metadata" |
| 383 | + return RequestSpec( |
| 384 | + method="GET", |
| 385 | + endpoint=Endpoint(metadata_endpoint_url), |
| 386 | + headers={ |
| 387 | + "accept": "application/schema+json" |
| 388 | + if schema_mode |
| 389 | + else "application/json" |
| 390 | + }, |
| 391 | + ) |
| 392 | + |
327 | 393 | def _retrieve_token_spec( |
328 | 394 | self, key: str, token_type: ConnectionTokenType = ConnectionTokenType.DIRECT |
329 | 395 | ) -> RequestSpec: |
|
0 commit comments