Skip to content

fix: validate name argument in admin create/delete commands#398

Open
raballew wants to merge 1 commit intojumpstarter-dev:mainfrom
raballew:029-fix-cli-name-validation
Open

fix: validate name argument in admin create/delete commands#398
raballew wants to merge 1 commit intojumpstarter-dev:mainfrom
raballew:029-fix-cli-name-validation

Conversation

@raballew
Copy link
Copy Markdown
Contributor

Summary

  • jmp admin delete client/exporter and jmp admin create client/exporter crashed with a raw Python traceback when invoked without a name argument
  • Adds a shared validate_name() helper in jumpstarter_cli_common.opt that raises a clear UsageError("Missing required argument 'NAME'.") when name is None, empty, or whitespace-only
  • Both create.py and delete.py import and use the shared helper

Test plan

  • 4 new tests for validate_name in cli-common (None, empty, whitespace, valid name)
  • All 69 cli-admin and 18 cli-common tests pass with no regressions

Closes #364

🤖 Generated with Claude Code

The admin delete client/exporter and create client/exporter commands
crashed with a Python traceback when invoked without a name argument.

Adds a shared validate_name() helper in jumpstarter_cli_common.opt
that raises a clear UsageError with the message "Missing required
argument 'NAME'" when name is None, empty, or whitespace-only.

Closes jumpstarter-dev#364

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for jumpstarter-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 326ce79
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/69cbd3476c632600087d4858

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Input validation was added to prevent executing create and delete commands without a name parameter. A new validate_name helper function raises an error for empty or whitespace-only names, and it is now called at the start of create_client, create_exporter, delete_client, and delete_exporter.

Changes

Cohort / File(s) Summary
Input Validation Helper
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py
Added new validate_name(name: Optional[str]) -> None function that raises click.UsageError for empty, whitespace-only, or None names.
Create Commands
python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py
Added validate_name(name) invocations at the start of create_client and create_exporter functions, before TLS confirmation and Kubernetes API context managers.
Delete Commands
python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/delete.py
Added validate_name(name) invocations at the start of delete_client and delete_exporter functions, before attempting Kubernetes API deletions.
Validation Tests
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt_test.py
Updated module docstring, expanded imports, and added TestValidateName class with test cases covering None, empty string, whitespace-only inputs, and valid names.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A name must exist, cannot be bare,
No empty strings or spaces to spare,
When validate_name takes a peek,
It ensures your arguments aren't weak!
Now commands catch errors with grace,
Before crashing deep in Kubernetes space!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding name validation to admin create/delete commands to prevent crashes.
Description check ✅ Passed The description is directly related to the changeset, detailing the problem, solution, and test coverage for the name validation fix.
Linked Issues check ✅ Passed The PR fully addresses issue #364 by implementing client-side validation that prevents crashes when NAME argument is missing in admin create/delete commands.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing name validation in admin commands and their tests; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py (1)

116-119: Consider normalizing NAME before returning from validate_name.

Right now, surrounding whitespace is accepted (e.g. " my-client "), which can still defer failure to server-side validation. Returning a stripped value from validate_name would keep this class of input handling fully client-side.

♻️ Proposed refactor
-def validate_name(name: Optional[str]) -> None:
-    if not name or not name.strip():
+def validate_name(name: Optional[str]) -> str:
+    normalized = (name or "").strip()
+    if not normalized:
         raise click.UsageError("Missing required argument 'NAME'.")
+    return normalized

Then at call sites:

-validate_name(name)
+name = validate_name(name)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py` around
lines 116 - 119, The validate_name function currently only checks for
missing/blank names but accepts surrounding whitespace; change
validate_name(name: Optional[str]) to return the normalized (stripped) name
(update signature to -> str), perform the existing empty check on name.strip(),
and return name.strip(); then update all call sites that previously relied on
validate_name for side-effects to capture the returned value (e.g., use name =
validate_name(name)) so callers work with the normalized NAME going forward.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py`:
- Around line 116-119: The validate_name function currently only checks for
missing/blank names but accepts surrounding whitespace; change
validate_name(name: Optional[str]) to return the normalized (stripped) name
(update signature to -> str), perform the existing empty check on name.strip(),
and return name.strip(); then update all call sites that previously relied on
validate_name for side-effects to capture the returned value (e.g., use name =
validate_name(name)) so callers work with the normalized NAME going forward.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3a9e2cc-c7f4-49f3-8bf6-54a752c6e4c3

📥 Commits

Reviewing files that changed from the base of the PR and between 03fc412 and 326ce79.

📒 Files selected for processing (4)
  • python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py
  • python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/delete.py
  • python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py
  • python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crash with traceback while issuing jmp admin delete commands with no name

1 participant