Skip to content

fix(pack): validate project params #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
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
2 changes: 1 addition & 1 deletion src/uipath/_cli/cli_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def generate_env_file(target_directory):
click.echo(f"Created {relative_path} file.")
with open(env_path, "w") as f:
f.write("UIPATH_ACCESS_TOKEN=YOUR_TOKEN_HERE\n")
f.write("UIPATH_URL=https://alpha.uipath.com/ACCOUNT_NAME/TENANT_NAME\n")
f.write("UIPATH_URL=https://cloud.uipath.com/ACCOUNT_NAME/TENANT_NAME\n")


def get_user_script(directory: str, entrypoint: Optional[str] = None) -> Optional[str]:
Expand Down
29 changes: 29 additions & 0 deletions src/uipath/_cli/cli_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ def pack_fn(projectName, description, entryPoints, version, authors, directory):
def read_toml_project(file_path: str) -> dict[str, any]:
with open(file_path, "rb") as f:
content = tomllib.load(f)
if "project" not in content:
raise Exception("pyproject.toml is missing the required field: project")
if "name" not in content["project"]:
raise Exception(
"pyproject.toml is missing the required field: project.name"
)
if "description" not in content["project"]:
raise Exception(
"pyproject.toml is missing the required field: project.description"
)
if "version" not in content["project"]:
raise Exception(
"pyproject.toml is missing the required field: project.version"
)

return {
"name": content["project"]["name"],
"description": content["project"]["description"],
Expand Down Expand Up @@ -320,6 +335,20 @@ def pack(root):
)
return
config = check_config(root)
if not config["project_name"] or config["project_name"].strip() == "":
raise Exception("Project name cannot be empty")

if not config["description"] or config["description"].strip() == "":
raise Exception("Project description cannot be empty")

invalid_chars = ["&", "<", ">", '"', "'", ";"]
for char in invalid_chars:
if char in config["project_name"]:
raise Exception(f"Project name contains invalid character: '{char}'")

for char in invalid_chars:
if char in config["description"]:
raise Exception(f"Project description contains invalid character: '{char}'")
click.echo(
f"Packaging project {config['project_name']}:{version or config['version']} description {config['description']} authored by {config['authors']}"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_init_env_file_creation(runner: CliRunner, temp_dir: str) -> None:
content = f.read()
assert "UIPATH_ACCESS_TOKEN=YOUR_TOKEN_HERE" in content
assert (
"UIPATH_URL=https://alpha.uipath.com/ACCOUNT_NAME/TENANT_NAME"
"UIPATH_URL=https://cloud.uipath.com/ACCOUNT_NAME/TENANT_NAME"
in content
)

Expand Down