Skip to content

Commit 473629b

Browse files
committed
feat: force option for cli auth + get process by package version
1 parent c309caa commit 473629b

File tree

6 files changed

+56
-30
lines changed

6 files changed

+56
-30
lines changed

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.0.50"
3+
version = "2.0.51"
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/_cli/_utils/_processes.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,38 @@
88

99
console = ConsoleLogger()
1010
client = httpx.Client(follow_redirects=True, timeout=30.0)
11+
odata_top_filter = 25
1112

1213

1314
def get_release_info(
14-
base_url: str, token: str, package_name: str, folder_id: str
15+
base_url: str,
16+
token: str,
17+
package_name: str,
18+
package_version: str,
19+
folder_id: str,
1520
) -> None | tuple[Any, Any] | tuple[None, None]:
1621
headers = {
1722
"Authorization": f"Bearer {token}",
1823
"x-uipath-organizationunitid": str(folder_id),
1924
}
2025

21-
release_url = f"{base_url}/orchestrator_/odata/Releases/UiPath.Server.Configuration.OData.ListReleases?$select=Id,Key&$top=1&$filter=Name%20eq%20%27{urllib.parse.quote(package_name)}%27"
26+
release_url = f"{base_url}/orchestrator_/odata/Releases/UiPath.Server.Configuration.OData.ListReleases?$select=Id,Key,ProcessVersion&$top={odata_top_filter}&$filter=ProcessKey%20eq%20%27{urllib.parse.quote(package_name)}%27"
2227
response = client.get(release_url, headers=headers)
2328
if response.status_code == 200:
2429
try:
2530
data = json.loads(response.text)
26-
release_id = data["value"][0]["Id"]
27-
release_key = data["value"][0]["Key"]
31+
process = next(
32+
process
33+
for process in data["value"]
34+
if process["ProcessVersion"] == package_version
35+
)
36+
release_id = process["Id"]
37+
release_key = process["Key"]
2838
return release_id, release_key
2939
except KeyError:
3040
console.warning("Warning: Failed to deserialize release data")
3141
return None, None
32-
except IndexError:
42+
except StopIteration:
3343
console.error(
3444
f"Error: No process with name '{package_name}' found in your workspace. Please publish the process first."
3545
)

src/uipath/_cli/cli_auth.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,34 @@ def set_port():
5656

5757
@click.command()
5858
@environment_options
59-
def auth(domain="alpha"):
59+
@click.option(
60+
"-f",
61+
"--force",
62+
is_flag=True,
63+
required=False,
64+
help="Force new token",
65+
)
66+
def auth(domain, force: None | bool = False):
6067
"""Authenticate with UiPath Cloud Platform."""
6168
with console.spinner("Authenticating with UiPath ..."):
6269
portal_service = PortalService(domain)
63-
if (
64-
os.getenv("UIPATH_URL")
65-
and os.getenv("UIPATH_TENANT_ID")
66-
and os.getenv("UIPATH_ORGANIZATION_ID")
67-
):
68-
try:
69-
portal_service.ensure_valid_token()
70-
console.success(
71-
"Authentication successful.",
72-
)
73-
return
74-
except Exception:
75-
console.info(
76-
"Authentication token is invalid. Please reauthenticate.",
77-
)
70+
71+
if not force:
72+
if (
73+
os.getenv("UIPATH_URL")
74+
and os.getenv("UIPATH_TENANT_ID")
75+
and os.getenv("UIPATH_ORGANIZATION_ID")
76+
):
77+
try:
78+
portal_service.ensure_valid_token()
79+
console.success(
80+
"Authentication successful.",
81+
)
82+
return
83+
except Exception:
84+
console.info(
85+
"Authentication token is invalid. Please reauthenticate.",
86+
)
7887

7988
auth_url, code_verifier, state = get_auth_url(domain)
8089

src/uipath/_cli/cli_invoke.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
client = httpx.Client(follow_redirects=True, timeout=30.0)
2525

2626

27-
def _read_project_name() -> str:
27+
def _read_project_details() -> [str, str]:
2828
current_path = os.getcwd()
2929
toml_path = os.path.join(current_path, "pyproject.toml")
3030
if not os.path.isfile(toml_path):
@@ -37,7 +37,7 @@ def _read_project_name() -> str:
3737
if "name" not in content["project"]:
3838
console.error("pyproject.toml is missing the required field: project.name.")
3939

40-
return content["project"]["name"]
40+
return content["project"]["name"], content["project"]["version"]
4141

4242

4343
@click.command()
@@ -67,15 +67,15 @@ def invoke(
6767

6868
url = f"{base_url}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs"
6969
_, personal_workspace_folder_id = get_personal_workspace_info(base_url, token)
70-
project_name = _read_project_name()
70+
project_name, project_version = _read_project_details()
7171

7272
if not personal_workspace_folder_id:
7373
console.error(
7474
"No personal workspace found for user. Please try reauthenticating."
7575
)
7676

7777
_, release_key = get_release_info(
78-
base_url, token, project_name, personal_workspace_folder_id
78+
base_url, token, project_name, project_version, personal_workspace_folder_id
7979
)
8080
payload = {
8181
"StartInfo": {

src/uipath/_cli/cli_publish.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,22 @@ def publish(feed):
129129
console.success("Package published successfully!")
130130

131131
if is_personal_workspace:
132+
package_name = None
133+
package_version = None
132134
try:
133-
data = json.loads(response.text)
134-
package_name = json.loads(data["value"][0]["Body"])["Id"]
135+
data = json.loads(response.text)["value"][0]["Body"]
136+
package_name = json.loads(data)["Id"]
137+
package_version = json.loads(data)["Version"]
135138
except json.decoder.JSONDecodeError:
136139
console.warning("Failed to deserialize package name")
137140
if package_name is not None:
138141
with console.spinner("Getting process information ..."):
139142
release_id, _ = get_release_info(
140-
base_url, token, package_name, personal_workspace_feed_id
143+
base_url,
144+
token,
145+
package_name,
146+
package_version,
147+
personal_workspace_feed_id,
141148
)
142149
if release_id:
143150
process_url = f"{base_url}/orchestrator_/processes/{release_id}/edit?fid={personal_workspace_folder_id}"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)