Skip to content

Add Input Validation to CLI Commands Based on Server Request Models - #17

Merged
virajbhartiya merged 2 commits into
mainfrom
feature/cli-input-validation
Jul 20, 2025
Merged

Add Input Validation to CLI Commands Based on Server Request Models#17
virajbhartiya merged 2 commits into
mainfrom
feature/cli-input-validation

Conversation

@virajbhartiya

Copy link
Copy Markdown
Member

Summary

This PR adds comprehensive input validation to all CLI commands in the parity-client, ensuring that user inputs match the expected request body structures from the parity-server API.

Changes Made

New Validation Utilities (internal/utils/validation.go)

  • Ethereum Address Validation: Validates format and checksum
  • Private Key Validation: Validates hex format and length
  • Amount Validation: Ensures positive values with minimum thresholds
  • URL Validation: Validates HTTP/HTTPS URLs
  • Device ID Validation: Ensures proper length and format
  • Task Parameter Validation: Title, description, Docker image, reward validation
  • LLM Parameter Validation: Model names, prompts, max tokens validation
  • Federated Learning Validation: Session names, rounds, participants, dataset CIDs
  • Storage Validation: File paths, CIDs, output paths

Enhanced CLI Commands

  • Auth Command: Validates private key format and length
  • Stake Command: Validates stake amount with minimum threshold
  • LLM Commands: Validates model names and prompts
  • Federated Learning Commands: Validates session parameters, learning rates, batch sizes
  • Storage Commands: Validates file paths and CIDs
  • Reputation Commands: Validates device IDs and runner parameters

Error Handling

  • Custom ValidationError type with field-specific error messages
  • Descriptive error messages that guide users to correct input
  • Consistent error format across all commands

Benefits

  1. Improved User Experience: Clear error messages help users understand what went wrong
  2. API Consistency: CLI inputs now match server-side validation requirements
  3. Reduced Server Errors: Invalid requests are caught client-side before reaching the server
  4. Better Security: Input validation prevents malformed data from being processed
  5. Maintainability: Centralized validation logic makes it easy to update validation rules

- Add validation utilities for Ethereum addresses, private keys, amounts, URLs, device IDs
- Integrate validation into auth, stake, balance, LLM, federated learning, storage, and reputation commands
- Add validation for task parameters, model names, prompts, dataset CIDs, and FL session parameters
- Improve error handling with descriptive validation error messages
- Add comprehensive test coverage for all validation functions
@virajbhartiya virajbhartiya self-assigned this Jul 20, 2025
@virajbhartiya virajbhartiya moved this from Todo to Ready in Parity Protocol Jul 20, 2025
@virajbhartiya
virajbhartiya merged commit 0f2fc7e into main Jul 20, 2025
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Parity Protocol Jul 20, 2025
@virajbhartiya
virajbhartiya deleted the feature/cli-input-validation branch July 20, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant