Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/nibbles
Browse files Browse the repository at this point in the history
  • Loading branch information
originalsouth committed Dec 23, 2024
2 parents 7cd694f + 945ba6e commit acc8bbc
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 160 deletions.
28 changes: 25 additions & 3 deletions rocky/katalogus/views/plugin_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from katalogus.client import Boefje, Normalizer
from katalogus.views.plugin_settings_list import PluginSettingsListView
from octopoes.models import OOI
from rocky.scheduler import ScheduleResponse
from rocky.views.tasks import TaskListView


Expand Down Expand Up @@ -72,10 +74,12 @@ def get_oois(self, selected_oois: list[str]) -> dict[str, Any]:
oois_without_clearance = []
for ooi in selected_oois:
ooi_object = self.get_single_ooi(pk=ooi)

if ooi_object.scan_profile and ooi_object.scan_profile.level >= self.plugin.scan_level.value:
oois_with_clearance.append(ooi_object)
else:
oois_without_clearance.append(ooi_object.primary_key)

return {"oois_with_clearance": oois_with_clearance, "oois_without_clearance": oois_without_clearance}

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -153,11 +157,29 @@ def get_context_data(self, **kwargs):

def get_form_consumable_oois(self):
"""Get all available OOIS that plugin can consume."""
return self.octopoes_api_connector.list_objects(
oois = self.octopoes_api_connector.list_objects(
self.plugin.consumes, valid_time=datetime.now(timezone.utc), limit=self.limit_ooi_list
).items

oois_with_schedule: list[tuple[OOI, ScheduleResponse]] = []

for ooi in oois:
schedules = self.scheduler_client.post_schedule_search(
{
"filters": [
{"column": "data", "field": "boefje__id", "operator": "eq", "value": self.plugin.id},
{"column": "data", "field": "input_ooi", "operator": "eq", "value": ooi.primary_key},
]
}
)

if schedules.count > 0:
schedule: ScheduleResponse = schedules.results[0]

oois_with_schedule.append((ooi, schedule))
return oois_with_schedule

def get_form_filtered_consumable_oois(self):
"""Return a list of oois that is filtered for oois that meets clearance level."""
oois = self.get_form_consumable_oois()
return [ooi for ooi in oois if ooi.scan_profile.level >= self.plugin.scan_level.value]
oois_with_schedule = self.get_form_consumable_oois()
return [ooi for ooi in oois_with_schedule if ooi[0].scan_profile.level >= self.plugin.scan_level.value]
61 changes: 16 additions & 45 deletions rocky/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rocky/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ opentelemetry-semantic-conventions = "^0.49b2"
opentelemetry-util-http = "^0.49b2"
structlog = "^24.2.0"
django-structlog = "^8.1.0"
cron-descriptor = "^1.4.5"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def to_representation(self, instance):


class ReportRecipeSerializer(serializers.Serializer):
id = serializers.UUIDField(source="recipe_id", read_only=True)
id = serializers.UUIDField(source="recipe_id", required=False)
report_name_format = serializers.CharField()
subreport_name_format = serializers.CharField(required=False, allow_blank=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{{ schedule.deadline_at }}
{% endif %}
</td>
<td class="nowrap">{{ schedule.cron }}</td>
<td class="nowrap">{{ schedule.cron|get_cron_description }}</td>
<td class="nowrap">
{% if schedule.enabled %}
<span class="label system-tag color-2">{% translate "Enabled" %}</span>
Expand Down
6 changes: 6 additions & 0 deletions rocky/reports/templatetags/report_extra.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

from cron_descriptor import get_description
from django import template

from reports.report_types.helpers import get_report_by_id
Expand All @@ -25,3 +26,8 @@ def get_report_type_name(report_type_id: str):
@register.filter
def get_report_type_label_style(report_type_id: str):
return get_report_by_id(report_type_id).label_style


@register.filter
def get_cron_description(cron_expression: str) -> str:
return get_description(cron_expression)
Loading

0 comments on commit acc8bbc

Please sign in to comment.