Skip to content

Commit

Permalink
Merge branch 'main' into feature/upload-multiple-files-at-once-to-bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Donnype authored Sep 10, 2024
2 parents 7ad0fdb + b098d8d commit d182714
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 62 deletions.
17 changes: 17 additions & 0 deletions boefjes/boefjes/job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,23 @@ def handle(self, normalizer_meta: NormalizerMeta) -> None:
)
)

if (
normalizer_meta.raw_data.boefje_meta.input_ooi # No input OOI means no deletion propagation
and not (results.observations or results.declarations or results.affirmations)
):
# There were no results found, which we still need to signal to Octopoes for deletion propagation

connector.save_observation(
Observation(
method=normalizer_meta.normalizer.id,
source=Reference.from_str(normalizer_meta.raw_data.boefje_meta.input_ooi),
source_method=normalizer_meta.raw_data.boefje_meta.boefje.id,
task_id=normalizer_meta.id,
valid_time=normalizer_meta.raw_data.boefje_meta.ended_at,
result=[],
)
)

corrected_scan_profiles = []
for profile in results.scan_profiles:
profile.level = ScanLevel(
Expand Down
12 changes: 6 additions & 6 deletions rocky/katalogus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,22 @@ def get_normalizers(self) -> list[Plugin]:
def get_boefjes(self) -> list[Plugin]:
return self.get_plugins(plugin_type="boefje")

def enable_boefje(self, plugin: Plugin) -> None:
self._patch_boefje_state(plugin.id, True)
def enable_plugin(self, plugin: Plugin) -> None:
self._patch_plugin_state(plugin.id, True)

def enable_boefje_by_id(self, boefje_id: str) -> None:
self.enable_boefje(self.get_plugin(boefje_id))
self.enable_plugin(self.get_plugin(boefje_id))

def disable_boefje(self, plugin: Plugin) -> None:
self._patch_boefje_state(plugin.id, False)
def disable_plugin(self, plugin: Plugin) -> None:
self._patch_plugin_state(plugin.id, False)

def get_enabled_boefjes(self) -> list[Plugin]:
return [plugin for plugin in self.get_boefjes() if plugin.enabled]

def get_enabled_normalizers(self) -> list[Plugin]:
return [plugin for plugin in self.get_normalizers() if plugin.enabled]

def _patch_boefje_state(self, boefje_id: str, enabled: bool) -> None:
def _patch_plugin_state(self, boefje_id: str, enabled: bool) -> None:
logger.info("Toggle plugin state", plugin_id=boefje_id, enabled=enabled)

response = self.session.patch(
Expand Down
49 changes: 3 additions & 46 deletions rocky/katalogus/views/plugin_enable_disable.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,25 @@
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from httpx import HTTPError

from katalogus.views.mixins import SinglePluginView


class PluginEnableDisableView(SinglePluginView):
def check_required_settings(self, settings: dict):
if self.plugin_schema is None or "required" not in self.plugin_schema:
return True

return all([field in settings for field in self.plugin_schema["required"]])

def post(self, request, *args, **kwargs):
plugin_state = kwargs["plugin_state"]

if plugin_state == "True":
self.katalogus_client.disable_boefje(self.plugin)
self.katalogus_client.disable_plugin(self.plugin)
messages.add_message(
self.request,
messages.WARNING,
_("{} '{}' disabled.").format(self.plugin.type.title(), self.plugin.name),
)
return HttpResponseRedirect(request.POST.get("current_url"))

try:
plugin_settings = self.katalogus_client.get_plugin_settings(self.plugin.id)
except HTTPError:
messages.add_message(
self.request,
messages.ERROR,
_("Failed fetching settings for {}. Is the Katalogus up?").format(self.plugin.name),
)
return redirect(
reverse(
"boefje_detail",
kwargs={
"organization_code": self.organization.code,
"plugin_id": self.plugin.id,
},
)
)

if not self.check_required_settings(plugin_settings):
messages.add_message(
self.request,
messages.INFO,
_("Before enabling, please set the required settings for '{}'.").format(self.plugin.name),
)
return redirect(
reverse(
"plugin_settings_add",
kwargs={
"organization_code": self.organization.code,
"plugin_id": self.plugin.id,
"plugin_type": self.plugin.type,
},
)
)

if self.plugin.can_scan(self.organization_member):
self.katalogus_client.enable_boefje(self.plugin)
self.katalogus_client.enable_plugin(self.plugin)
messages.add_message(
self.request,
messages.SUCCESS,
Expand Down
2 changes: 1 addition & 1 deletion rocky/katalogus/views/plugin_settings_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def form_valid(self, form):

if "add-enable" in self.request.POST:
try:
self.katalogus_client.enable_boefje(self.plugin)
self.katalogus_client.enable_plugin(self.plugin)
except HTTPError:
messages.add_message(self.request, messages.ERROR, _("Enabling {} failed").format(self.plugin.name))
return redirect(self.get_success_url())
Expand Down
10 changes: 1 addition & 9 deletions rocky/rocky/locale/django.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-05 08:44+0000\n"
"POT-Creation-Date: 2024-09-06 08:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -1198,14 +1198,6 @@ msgstr ""
msgid "{} '{}' disabled."
msgstr ""

#: katalogus/views/plugin_enable_disable.py
msgid "Failed fetching settings for {}. Is the Katalogus up?"
msgstr ""

#: katalogus/views/plugin_enable_disable.py
msgid "Before enabling, please set the required settings for '{}'."
msgstr ""

#: katalogus/views/plugin_enable_disable.py
msgid "{} '{}' enabled."
msgstr ""
Expand Down

0 comments on commit d182714

Please sign in to comment.