Skip to content
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

Add run-on to Boefje Setup page #4061

Merged
merged 31 commits into from
Feb 7, 2025
Merged

Conversation

madelondohmen
Copy link
Contributor

@madelondohmen madelondohmen commented Feb 4, 2025

Changes

This PR adds the possibility for a user to select "Run On" to the Boefje (variant).
The user can choose one out of two options for when the Boefje should run:

  1. On a specific interval
  2. Every time an object is created and/or changed

If the user selects one of the options, the other option should be empty/None.
It is also possible for the user to not select any of the options. In that case, the default system scan frequency will be used.

Issue link

Closes #3929

Demo

Opname.2025-02-04.111401.mp4

QA notes

Check if all of this works:

  • Create a new Boefje, with:
    • An interval per minute/hour/day/week/year
    • Run on create and/or change
    • Nothing selected (should work as well)

Also check these two flows:

  • Edit an existing Boefje
  • Create a Boefje variant

Code Checklist

  • All the commits in this PR are properly PGP-signed and verified.
  • This PR only contains functionality relevant to the issue.
  • I have written unit tests for the changes or fixes I made.
  • I have checked the documentation and made changes where necessary.
  • I have performed a self-review of my code and refactored it to the best of my abilities.
  • Tickets have been created for newly discovered issues.
  • For any non-trivial functionality, I have added integration and/or end-to-end tests.
  • I have informed others of any required .env changes files if required and changed the .env-dist accordingly.
  • I have included comments in the code to elaborate on what is not self-evident from the code itself, including references to issues and discussions online, or implicit behavior of an interface.

Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

@madelondohmen madelondohmen self-assigned this Feb 4, 2025
@madelondohmen madelondohmen requested a review from a team as a code owner February 4, 2025 10:18
@underdarknl underdarknl added this to the OpenKAT v1.18 milestone Feb 4, 2025
madelondohmen and others added 4 commits February 4, 2025 12:16
…e" for future extensions

- Fix the unit and integration tests
- Fix scheduler definition
- Fix scheduler tests
jpbruinsslot
jpbruinsslot previously approved these changes Feb 5, 2025
Copy link
Contributor

@jpbruinsslot jpbruinsslot left a comment

Choose a reason for hiding this comment

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

scheduler changes lgtm!

- Allow the API to post and get a list of strings but save them as a proper PSQL Enum
- Test RunOn conversion and integration tests for the API
Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

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

Looks good, minimal remarks

CREATE_UPDATE = "create_update"

@classmethod
def from_run_ons(cls, run_ons: list[RunOn] | None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def from_run_ons(cls, run_ons: list[RunOn] | None):
def from_run_ons(cls, run_ons: list[RunOn] | None) -> RunOn | None:

Copy link
Contributor

Choose a reason for hiding this comment

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

@madelondohmen This should be Self from typing_extensions (probably) it should actually return RunOnDB | None which won't work because it references itself.

Suggested change
def from_run_ons(cls, run_ons: list[RunOn] | None):
def from_run_ons(cls, run_ons: list[RunOn] | None) -> Self | None:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Donnype is right. "RunOn | None" won't work since it returns a RunOnDB. But Self doesn't work as well. So I suggest to leave it as it was.

Copy link
Contributor

Choose a reason for hiding this comment

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

typing.Self is introduced in Python 3.11, but we still use 3.10 for development. Therefore:
def from_run_ons(cls, run_ons: list[RunOn] | None) -> "RunOnDB" | None:

@@ -232,3 +254,18 @@ def create_boefje_with_form_data(form_data, plugin_id: str, created: str | None)
oci_image=form_data["oci_image"],
oci_arguments=arguments,
)


def get_interval_minutes(interval_number, interval_frequency) -> int | None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def get_interval_minutes(interval_number, interval_frequency) -> int | None:
def get_interval_minutes(interval_number: int, interval_frequency: str) -> int | None:
  • It would be nicer to throw a ValueError on invalid parameter (e.g. unknown interval_frequency argument)
  • You can use Literal["minutes", "hours", ...] to type hint this literal of choices

@underdarknl
Copy link
Contributor

I've made the Javascript more general, and reusable for other variants of the same logic.

@ammar92
Copy link
Contributor

ammar92 commented Feb 7, 2025

Checklist for QA:

  • I have checked out this branch, and successfully ran a fresh make reset.
  • I confirmed that there are no unintended functional regressions in this branch:
    • I have managed to pass the onboarding flow
    • Objects and Findings are created properly
    • Tasks are created and completed properly
  • I confirmed that the PR's advertised feature or hotfix works as intended.
  • I checked the logs for errors and/or warnings and made issues where necessary

What works:

  • I can select either option and it will be displayed correctly in the variants list
  • I can change the option and it will be updated accordingly

Bug or feature?:

  • I still get to see both forms regardless which option I choose for the scan type:
image

@underdarknl
Copy link
Contributor

Bug or feature?:

* I still get to see both forms regardless which option I choose for the scan type:

Oops, copy paste error. Is now fixed.

Copy link

sonarqubecloud bot commented Feb 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
48.3% Coverage on New Code (required ≥ 80%)
4.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@dekkers dekkers merged commit 3888974 into main Feb 7, 2025
32 of 33 checks passed
@dekkers dekkers deleted the feature/boefje-variants-run-on- branch February 7, 2025 16:10
jpbruinsslot added a commit that referenced this pull request Feb 11, 2025
* main:
  Add run-on to Boefje Setup page (#4061)
  Translations update from Hosted Weblate (#4046)
  Remove the keiko report module (#4066)
  Add one-off jobs for report scheduler (#4045)
  Report Task List (#4059)
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.

Implement runon in user interface / boefjes variant flow
6 participants