Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ def create_ssl_context(cafile: str):

def get_httpx_client_kwargs(
headers: Dict[str, str] | None = None,
timeout: float = 30.0,
) -> Dict[str, Any]:
Comment thread
hamarg marked this conversation as resolved.
"""Get standardized httpx client configuration.

Args:
headers: Optional headers to merge with platform headers (e.g. licensing).
Caller headers take priority on key conflicts.
timeout: Request timeout in seconds. Defaults to 30.0.
"""
client_kwargs: Dict[str, Any] = {"follow_redirects": True, "timeout": 30.0}
client_kwargs: Dict[str, Any] = {"follow_redirects": True, "timeout": timeout}

ca_bundle = get_ca_bundle_path()
client_kwargs["verify"] = create_ssl_context(ca_bundle) if ca_bundle else False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
content: str | bytes,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,
) -> uuid.UUID: ...

@overload
Expand All @@ -461,6 +462,7 @@
source_path: str,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,
) -> uuid.UUID: ...

@traced(
Expand All @@ -476,6 +478,7 @@
source_path: str | None = None,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,
) -> uuid.UUID:
"""Upload a file or content to UiPath as an attachment.

Expand All @@ -488,6 +491,7 @@
source_path (str | None): The local path of the file to upload.
folder_key (str | None): The key of the folder. Override the default one set in the SDK config.
folder_path (str | None): The path of the folder. Override the default one set in the SDK config.
timeout (float): Request timeout in seconds. Defaults to 30.0.

Returns:
uuid.UUID: The UUID of the created attachment.
Expand Down Expand Up @@ -556,10 +560,16 @@
file_content = file.read()
if result["BlobFileAccess"]["RequiresAuth"]:
self.request(
"PUT", upload_uri, headers=headers, content=file_content
"PUT",
upload_uri,
headers=headers,
content=file_content,
timeout=timeout,
)
else:
with httpx.Client(**get_httpx_client_kwargs()) as client:
with httpx.Client(
**get_httpx_client_kwargs(timeout=timeout)
) as client:
client.put(upload_uri, headers=headers, content=file_content)
else:
# Upload from memory
Expand All @@ -568,9 +578,15 @@
content = content.encode("utf-8")

if result["BlobFileAccess"]["RequiresAuth"]:
self.request("PUT", upload_uri, headers=headers, content=content)
self.request(
"PUT",
upload_uri,
headers=headers,
content=content,
timeout=timeout,
)
else:
with httpx.Client(**get_httpx_client_kwargs()) as client:
with httpx.Client(**get_httpx_client_kwargs(timeout=timeout)) as client:
client.put(upload_uri, headers=headers, content=content)

return attachment_key
Expand All @@ -583,6 +599,7 @@
content: str | bytes,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,

Check warning on line 602 in packages/uipath-platform/src/uipath/platform/orchestrator/_attachments_service.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this "timeout" parameter and use a timeout context manager instead.

See more on https://sonarcloud.io/project/issues?id=UiPath_uipath-python&issues=AaAcWvAdtgn_9F94f4-s&open=AaAcWvAdtgn_9F94f4-s&pullRequest=1841
) -> uuid.UUID: ...

@overload
Expand All @@ -593,6 +610,7 @@
source_path: str,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,

Check warning on line 613 in packages/uipath-platform/src/uipath/platform/orchestrator/_attachments_service.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this "timeout" parameter and use a timeout context manager instead.

See more on https://sonarcloud.io/project/issues?id=UiPath_uipath-python&issues=AaAcWvAdtgn_9F94f4-t&open=AaAcWvAdtgn_9F94f4-t&pullRequest=1841
) -> uuid.UUID: ...

@traced(
Expand All @@ -608,6 +626,7 @@
source_path: str | None = None,
folder_key: str | None = None,
folder_path: str | None = None,
timeout: float = 30.0,

Check warning on line 629 in packages/uipath-platform/src/uipath/platform/orchestrator/_attachments_service.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this "timeout" parameter and use a timeout context manager instead.

See more on https://sonarcloud.io/project/issues?id=UiPath_uipath-python&issues=AaAcWvAdtgn_9F94f4-u&open=AaAcWvAdtgn_9F94f4-u&pullRequest=1841
) -> uuid.UUID:
"""Upload a file or content to UiPath as an attachment asynchronously.

Expand All @@ -620,6 +639,7 @@
source_path (str | None): The local path of the file to upload.
folder_key (str | None): The key of the folder. Override the default one set in the SDK config.
folder_path (str | None): The path of the folder. Override the default one set in the SDK config.
timeout (float): Request timeout in seconds. Defaults to 30.0.

Returns:
uuid.UUID: The UUID of the created attachment.
Expand Down Expand Up @@ -692,11 +712,19 @@
file_content = file.read()
if result["BlobFileAccess"]["RequiresAuth"]:
await self.request_async(
"PUT", upload_uri, headers=headers, content=file_content
"PUT",
upload_uri,
headers=headers,
content=file_content,
timeout=timeout,
)
else:
with httpx.Client(**get_httpx_client_kwargs()) as client:
client.put(upload_uri, headers=headers, content=file_content)
async with httpx.AsyncClient(
**get_httpx_client_kwargs(timeout=timeout)
) as client:
await client.put(
upload_uri, headers=headers, content=file_content
)
else:
# Upload from memory
# Convert string to bytes if needed
Expand All @@ -705,11 +733,17 @@

if result["BlobFileAccess"]["RequiresAuth"]:
await self.request_async(
"PUT", upload_uri, headers=headers, content=content
"PUT",
upload_uri,
headers=headers,
content=content,
timeout=timeout,
)
else:
with httpx.Client(**get_httpx_client_kwargs()) as client:
client.put(upload_uri, headers=headers, content=content)
async with httpx.AsyncClient(
**get_httpx_client_kwargs(timeout=timeout)
) as client:
await client.put(upload_uri, headers=headers, content=content)

return attachment_key

Expand Down
Loading
Loading