TheHiveV5: Validate entrypoint arguments via Pydantic#2880
Conversation
Reviewer's GuideThe PR adds input validation guards to TheHive V5 actions (add observable, upload logs, add comment) to handle missing or empty entrypoint arguments, updates tests accordingly, and bumps the module version with changelog documentation. Sequence diagram for TheHiveV5 action guards on alert_id and messagesequenceDiagram
actor AutomationPlatform
participant TheHiveCreateCommentV5
participant TheHiveConnector
AutomationPlatform->>TheHiveCreateCommentV5: run(arguments)
alt [missing or empty alert_id]
TheHiveCreateCommentV5->>TheHiveCreateCommentV5: error("Alert ID is required")
TheHiveCreateCommentV5-->>AutomationPlatform: None
else [missing or empty message]
TheHiveCreateCommentV5->>TheHiveCreateCommentV5: error("Comment message is required")
TheHiveCreateCommentV5-->>AutomationPlatform: None
else [arguments valid]
TheHiveCreateCommentV5->>TheHiveConnector: TheHiveConnector(base_url, apikey, verify)
TheHiveCreateCommentV5-->>AutomationPlatform: OutputComment
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
alert_idandmessageguards use truthiness checks (if not arguments.get(...)), which will also reject falsy but potentially valid values (e.g.,0); if those IDs/messages can be non-empty falsy values, consider explicitly checking forNone/empty string instead. - The
alert_idvalidation logic is now duplicated acrossadd_observable,upload_logs, andadd_comment; consider extracting a small shared helper or base-method for required-argument validation to keep the checks consistent and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `alert_id` and `message` guards use truthiness checks (`if not arguments.get(...)`), which will also reject falsy but potentially valid values (e.g., `0`); if those IDs/messages can be non-empty falsy values, consider explicitly checking for `None`/empty string instead.
- The `alert_id` validation logic is now duplicated across `add_observable`, `upload_logs`, and `add_comment`; consider extracting a small shared helper or base-method for required-argument validation to keep the checks consistent and easier to maintain.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
9b771ee to
076997e
Compare
|
Updated this PR to migrate TheHiveV5 to native Pydantic v2 validation and bump the SDK from 1.13.0 to 1.23.1. Migrated files:
Local validation:
CI note: codecov/project still fails overall, but codecov/patch/TheHive and codecov/project/TheHive are both passing, so the remaining repo-wide coverage failure looks unrelated to this module. |
|
Simplified the TheHiveV5 argument guards by replacing the custom blank-check @field_validator methods with a shared Pydantic v2 NonEmptyStr alias (Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]). I intentionally kept these fields as non-empty strings rather than tightening their types: TheHive alert_id uses TheHive's own ~-prefixed internal identifier format (for example ~12345, not an RFC-4122 UUID), add_comment.message is free text, and upload_logs.filepath is a local path string. In add_observable, the only required opaque string field here is alert_id; the observable payload itself stays polymorphic via the existing events structure. |
…action Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b7ea111 to
cb376b5
Compare
What
Validate TheHiveV5's action arguments via Pydantic v2 models before each action runs, so missing/blank required input fails immediately with a clear validation error instead of the action calling the API with bad data.
Changes
alert_id,message,filepath→NonEmptyStr(kept as plain non-empty strings — TheHive alert IDs use an opaque~-prefixed format, not a UUID)Testing
pytestandblackpass.