Skip to content

TrendMicroVisionOne: Validate entrypoint arguments via Pydantic#2885

Open
PierrickV wants to merge 1 commit into
developfrom
fix-trendmicrovisionone-guards
Open

TrendMicroVisionOne: Validate entrypoint arguments via Pydantic#2885
PierrickV wants to merge 1 commit into
developfrom
fix-trendmicrovisionone-guards

Conversation

@PierrickV

@PierrickV PierrickV commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

Validate TrendMicroVisionOne's action arguments via Pydantic v2 models before each action runs, so missing/blank/malformed input fails immediately with a clear validation error instead of calling the API with bad data.

Changes

  • agent_guidslist[UUID] with Field(min_length=1)
  • agent_guidUUID
  • process_idField(gt=0)
  • alert_id, note, file_pathNonEmptyStr

Testing

  • pytest and black pass.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds shared required-argument validation to TrendMicro VisionOne actions so missing or empty entrypoint arguments short‑circuit execution before any HTTP/API calls, and backfills regression tests plus versioning/changelog updates.

Sequence diagram for required-argument guard in TrendMicroVisionOne actions

sequenceDiagram
    actor Orchestrator
    participant AddAlertNoteAction
    participant TrendMicroVisionOneBaseAction

    Orchestrator->>AddAlertNoteAction: run(arguments)
    AddAlertNoteAction->>TrendMicroVisionOneBaseAction: get_required_argument(arguments, alert_id, "Alert ID is required")

    alt [missing_or_empty_alert_id]
        TrendMicroVisionOneBaseAction->>AddAlertNoteAction: error("Alert ID is required")
        AddAlertNoteAction-->>Orchestrator: return None
    else [alert_id_present]
        AddAlertNoteAction->>TrendMicroVisionOneBaseAction: get_required_argument(arguments, note, "Note is required")
        alt [missing_or_empty_note]
            TrendMicroVisionOneBaseAction->>AddAlertNoteAction: error("Note is required")
            AddAlertNoteAction-->>Orchestrator: return None
        else [note_present]
            AddAlertNoteAction-->>Orchestrator: [HTTP_request_and_followup]
        end
    end
Loading

File-Level Changes

Change Details Files
Introduce shared helper for required argument validation and use it across six TrendMicro VisionOne actions.
  • Add get_required_argument helper to TrendMicroVisionOneBaseAction to validate presence and non-emptiness of required arguments, emit error messages, and return None on failure.
  • Refactor AddAlertNoteAction, CollectFileAction, TerminateProcessAction, DeIsolateMachineAction, IsolateMachineAction, and UpdateAlertAction.run methods to use get_required_argument instead of direct dict indexing for required fields.
  • Ensure actions early-return before constructing URLs or invoking the API client when required arguments are missing or empty.
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_base.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_add_alert_note.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_collect_file.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_terminate_process.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_deisolate_machine.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_isolate_machine.py
TrendMicroVisionOne/trendmicro_visionone_modules/action_vision_one_update_alert.py
Add regression tests to assert required-argument guards prevent HTTP calls when entrypoint arguments are missing or empty.
  • Use pytest parametrization to cover combinations of missing, empty, or zero-valued arguments for alert notes, file collection, machine isolation/deisolation, process termination, and alert updates.
  • Mock action.error with unittest.mock.Mock to assert the correct error message is emitted once per invalid invocation.
  • Wrap each test in requests_mock.Mocker and assert no requests were recorded in mock.request_history when validation fails.
  • Import Mock from unittest.mock to support error handler mocking.
TrendMicroVisionOne/tests/test_actions.py
Update module versioning and changelog for the bugfix release.
  • Add 0.1.4 "Fixed" entry to CHANGELOG describing the new required-argument guards for the six actions.
  • Bump manifest.json version from 0.1.3 to 0.1.4.
TrendMicroVisionOne/CHANGELOG.md
TrendMicroVisionOne/manifest.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The generic get_required_argument helper relies on a truthiness check, which may inadvertently reject valid falsy values in future (e.g., 0 or False); consider making the validation explicit per expected type (string empty, list length, etc.) or allowing callers to pass a predicate.
  • For arguments that are conceptually lists like agent_guids, the helper currently only guards against empty values; if individual GUIDs must also be non-empty strings, consider adding a simple element-level validation to avoid silently accepting invalid entries.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The generic `get_required_argument` helper relies on a truthiness check, which may inadvertently reject valid falsy values in future (e.g., `0` or `False`); consider making the validation explicit per expected type (string empty, list length, etc.) or allowing callers to pass a predicate.
- For arguments that are conceptually lists like `agent_guids`, the helper currently only guards against empty values; if individual GUIDs must also be non-empty strings, consider adding a simple element-level validation to avoid silently accepting invalid entries.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@PierrickV
PierrickV force-pushed the fix-trendmicrovisionone-guards branch from 1017290 to ff9bf29 Compare July 10, 2026 15:26
@PierrickV

Copy link
Copy Markdown
Contributor Author

Updated this PR to complete the native Pydantic v2 migration for TrendMicroVisionOne.

  • bumped sekoia-automation-sdk from 1.19.2 to 1.23.1 (and aligned the module Python constraint to 3.11+ for SDK compatibility)
  • migrated these files off the pydantic.v1 shim: trendmicro_visionone_modules/models.py, action_vision_one_update_alert.py, action_vision_one_collect_file.py, action_vision_one_isolate_machine.py, action_vision_one_deisolate_machine.py, action_vision_one_terminate_process.py, action_vision_one_add_alert_note.py, and tests/test_actions.py
  • kept the existing guard behavior intact (including rejecting process_id=0 and empty agent_guids before any API call)
  • validation is clean: poetry run pytest tests -q (29 passed), poetry run mypy trendmicro_visionone_modules --ignore-missing-imports passed, and poetry run black --check trendmicro_visionone_modules tests passed

There are no remaining pydantic.v1 imports in this module, and the v1/v2 model-mixing warning is gone.

@PierrickV PierrickV changed the title TrendMicroVisionOne: guard against missing/empty entrypoint arguments TrendMicroVisionOne: Validate entrypoint arguments via Pydantic Jul 11, 2026
@PierrickV
PierrickV requested a review from a team July 11, 2026 05:38
@PierrickV

Copy link
Copy Markdown
Contributor Author

Updated the TrendMicroVisionOne action argument models to use native Pydantic constraints instead of custom validators. In particular, agent_guids is now typed as list[UUID] with min_length=1, and agent_guid is now a UUID, which preserves the non-empty requirement and adds real UUID-shape validation. I kept alert_id, note, and file_path as trimmed non-empty strings because the fixtures show those are opaque, free-text, or path values rather than UUIDs, and simplified process_id to a native gt=0 numeric constraint.

@PierrickV

Copy link
Copy Markdown
Contributor Author

Consolidated the CHANGELOG: merged the two stacked version entries (0.1.4/0.1.5) into a single 0.1.4 entry.

…nning the action

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PierrickV
PierrickV force-pushed the fix-trendmicrovisionone-guards branch from 3148fa7 to b445498 Compare July 13, 2026 07:39
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.

1 participant