Skip to content

Commit 9405619

Browse files
authored
Merge pull request #613 from UiPath/akshaya/bearer_tokens
feat(BearerTokens) support fetching of bearer tokens
2 parents b6362d5 + c1b76da commit 9405619

5 files changed

Lines changed: 936 additions & 896 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.64"
3+
version = "2.1.65"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/_services/connections_service.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .._execution_context import ExecutionContext
77
from .._utils import Endpoint, RequestSpec, infer_bindings
88
from ..models import Connection, ConnectionToken, EventArguments
9+
from ..models.connections import ConnectionTokenType
910
from ..tracing._traced import traced
1011
from ._base_service import BaseService
1112

@@ -71,7 +72,9 @@ async def retrieve_async(self, key: str) -> Connection:
7172
run_type="uipath",
7273
hide_output=True,
7374
)
74-
def retrieve_token(self, key: str) -> ConnectionToken:
75+
def retrieve_token(
76+
self, key: str, token_type: ConnectionTokenType = ConnectionTokenType.DIRECT
77+
) -> ConnectionToken:
7578
"""Retrieve an authentication token for a connection.
7679
7780
This method obtains a fresh authentication token that can be used to
@@ -80,12 +83,13 @@ def retrieve_token(self, key: str) -> ConnectionToken:
8083
8184
Args:
8285
key (str): The unique identifier of the connection.
86+
token_type (ConnectionTokenType): The token type to use.
8387
8488
Returns:
8589
ConnectionToken: The authentication token details, including the token
8690
value and any associated metadata.
8791
"""
88-
spec = self._retrieve_token_spec(key)
92+
spec = self._retrieve_token_spec(key, token_type)
8993
response = self.request(spec.method, url=spec.endpoint, params=spec.params)
9094
return ConnectionToken.model_validate(response.json())
9195

@@ -94,7 +98,9 @@ def retrieve_token(self, key: str) -> ConnectionToken:
9498
run_type="uipath",
9599
hide_output=True,
96100
)
97-
async def retrieve_token_async(self, key: str) -> ConnectionToken:
101+
async def retrieve_token_async(
102+
self, key: str, token_type: ConnectionTokenType = ConnectionTokenType.DIRECT
103+
) -> ConnectionToken:
98104
"""Asynchronously retrieve an authentication token for a connection.
99105
100106
This method obtains a fresh authentication token that can be used to
@@ -103,12 +109,13 @@ async def retrieve_token_async(self, key: str) -> ConnectionToken:
103109
104110
Args:
105111
key (str): The unique identifier of the connection.
112+
token_type (ConnectionTokenType): The token type to use.
106113
107114
Returns:
108115
ConnectionToken: The authentication token details, including the token
109116
value and any associated metadata.
110117
"""
111-
spec = self._retrieve_token_spec(key)
118+
spec = self._retrieve_token_spec(key, token_type)
112119
response = await self.request_async(
113120
spec.method, url=spec.endpoint, params=spec.params
114121
)
@@ -198,9 +205,11 @@ def _retrieve_spec(self, key: str) -> RequestSpec:
198205
endpoint=Endpoint(f"/connections_/api/v1/Connections/{key}"),
199206
)
200207

201-
def _retrieve_token_spec(self, key: str) -> RequestSpec:
208+
def _retrieve_token_spec(
209+
self, key: str, token_type: ConnectionTokenType = ConnectionTokenType.DIRECT
210+
) -> RequestSpec:
202211
return RequestSpec(
203212
method="GET",
204213
endpoint=Endpoint(f"/connections_/api/v1/Connections/{key}/token"),
205-
params={"tokenType": "direct"},
214+
params={"tokenType": token_type.value},
206215
)

src/uipath/agent/models/agent.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ class AgentProcessToolResourceConfig(BaseAgentToolResourceConfig):
9797
)
9898

9999

100+
class AgentIntegrationToolParameter(BaseModel):
101+
"""Agent integration tool parameter."""
102+
103+
name: str = Field(..., alias="name")
104+
type: str = Field(..., alias="type")
105+
value: Optional[Any] = Field(None, alias="value")
106+
field_location: str = Field(..., alias="fieldLocation")
107+
108+
# Useful Metadata
109+
display_name: Optional[str] = Field(None, alias="displayName")
110+
display_value: Optional[str] = Field(None, alias="displayValue")
111+
description: Optional[str] = Field(None, alias="description")
112+
position: Optional[str] = Field(None, alias="position")
113+
field_variant: Optional[str] = Field(None, alias="fieldVariant")
114+
dynamic: Optional[bool] = Field(None, alias="dynamic")
115+
is_cascading: Optional[bool] = Field(None, alias="isCascading")
116+
sort_order: Optional[int] = Field(..., alias="sortOrder")
117+
required: Optional[bool] = Field(None, alias="required")
118+
# enum_values, dynamic_behavior and reference not typed currently
119+
120+
model_config = ConfigDict(
121+
validate_by_name=True, validate_by_alias=True, extra="allow"
122+
)
123+
124+
100125
class AgentIntegrationToolProperties(BaseModel):
101126
"""Properties specific to tool configuration."""
102127

@@ -107,6 +132,7 @@ class AgentIntegrationToolProperties(BaseModel):
107132
method: str = Field(..., alias="method")
108133
connection: Connection = Field(..., alias="connection")
109134
body_structure: dict[str, Any] = Field(..., alias="bodyStructure")
135+
parameters: List[AgentIntegrationToolParameter] = Field([], alias="parameters")
110136

111137
model_config = ConfigDict(
112138
validate_by_name=True, validate_by_alias=True, extra="allow"
@@ -118,7 +144,6 @@ class AgentIntegrationToolResourceConfig(BaseAgentToolResourceConfig):
118144

119145
type: Literal[AgentToolType.INTEGRATION] = AgentToolType.INTEGRATION
120146
properties: AgentIntegrationToolProperties
121-
122147
model_config = ConfigDict(
123148
validate_by_name=True, validate_by_alias=True, extra="allow"
124149
)

src/uipath/models/connections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import Any, Optional
23

34
from pydantic import BaseModel, ConfigDict, Field
@@ -30,6 +31,11 @@ class Connection(BaseModel):
3031
element_version: Optional[str] = Field(default=None, alias="elementVersion")
3132

3233

34+
class ConnectionTokenType(str, Enum):
35+
DIRECT = "direct"
36+
BEARER = "bearer"
37+
38+
3339
class ConnectionToken(BaseModel):
3440
model_config = ConfigDict(
3541
validate_by_name=True,

0 commit comments

Comments
 (0)