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

Create CRUD endpoints for RO/TO couples, stakeholders, attack paths, operational scenarios #1126

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from core.serializers import (
BaseModelSerializer,
FieldsRelatedField,
AssessmentReadSerializer,
)
from core.models import StoredLibrary, RiskMatrix
from .models import EbiosRMStudy, FearedEvent
from .models import (
EbiosRMStudy,
FearedEvent,
RoTo,
Stakeholder,
AttackPath,
OperationalScenario,
)
from rest_framework import serializers
import logging

Expand Down Expand Up @@ -72,3 +78,80 @@ class FearedEventReadSerializer(BaseModelSerializer):
class Meta:
model = FearedEvent
fields = "__all__"


class RoToWriteSerializer(BaseModelSerializer):
class Meta:
model = RoTo
exclude = ["created_at", "updated_at", "folder"]


class RoToReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
folder = FieldsRelatedField()
feared_events = FieldsRelatedField(many=True)

class Meta:
model = RoTo
fields = "__all__"


class StakeholderWriteSerializer(BaseModelSerializer):
current_criticality = serializers.IntegerField(read_only=True)
residual_criticality = serializers.IntegerField(read_only=True)

class Meta:
model = Stakeholder
exclude = ["created_at", "updated_at", "folder"]


class StakeholderReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
folder = FieldsRelatedField()
entity = FieldsRelatedField()
applied_controls = FieldsRelatedField(many=True)

current_criticality = serializers.IntegerField()
residual_criticality = serializers.IntegerField()

class Meta:
model = Stakeholder
fields = "__all__"


class AttackPathWriteSerializer(BaseModelSerializer):
class Meta:
model = AttackPath
exclude = ["created_at", "updated_at", "folder"]


class AttackPathReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
folder = FieldsRelatedField()
ro_to_couple = FieldsRelatedField()
stakeholders = FieldsRelatedField(many=True)

class Meta:
model = AttackPath
fields = "__all__"


class OperationalScenarioWriteSerializer(BaseModelSerializer):
class Meta:
model = OperationalScenario
exclude = ["created_at", "updated_at", "folder"]


class OperationalScenarioReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
ebios_rm_study = FieldsRelatedField()
folder = FieldsRelatedField()
attack_paths = FieldsRelatedField(many=True)
threats = FieldsRelatedField(many=True)

class Meta:
model = OperationalScenario
fields = "__all__"
17 changes: 16 additions & 1 deletion backend/ebios_rm/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
from django.urls import include, path
from rest_framework import routers

from ebios_rm.views import EbiosRMStudyViewSet, FearedEventViewSet
from ebios_rm.views import (
EbiosRMStudyViewSet,
FearedEventViewSet,
RoToViewSet,
StakeholderViewSet,
AttackPathViewSet,
OperationalScenarioViewSet,
)

router = routers.DefaultRouter()

router.register(r"studies", EbiosRMStudyViewSet, basename="studies")
router.register(r"feared-events", FearedEventViewSet, basename="feared-events")
router.register(r"ro-to", RoToViewSet, basename="ro-to")
router.register(r"stakeholders", StakeholderViewSet, basename="stakeholders")
router.register(r"attack-paths", AttackPathViewSet, basename="attack-paths")
router.register(
r"operational-scenarios",
OperationalScenarioViewSet,
basename="operational-scenarios",
)

urlpatterns = [
path("", include(router.urls)),
Expand Down
45 changes: 44 additions & 1 deletion backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from core.views import BaseModelViewSet as AbstractBaseModelViewSet
from .models import EbiosRMStudy, FearedEvent
from .models import (
EbiosRMStudy,
FearedEvent,
RoTo,
Stakeholder,
AttackPath,
OperationalScenario,
)
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.decorators import action
Expand Down Expand Up @@ -27,3 +34,39 @@ def status(self, request):

class FearedEventViewSet(BaseModelViewSet):
model = FearedEvent


class RoToViewSet(BaseModelViewSet):
model = RoTo

@action(detail=False, name="Get risk origin choices", url_path="risk-origin")
def risk_origin(self, request):
return Response(dict(RoTo.RiskOrigin.choices))

@action(detail=False, name="Get motivation choices")
def motivation(self, request):
return Response(dict(RoTo.Motivation.choices))

@action(detail=False, name="Get resources choices")
def resources(self, request):
return Response(dict(RoTo.Resources.choices))

@action(detail=False, name="Get pertinence choices")
def pertinence(self, request):
return Response(dict(RoTo.Pertinence.choices))


class StakeholderViewSet(BaseModelViewSet):
model = Stakeholder

@action(detail=False, name="Get category choices")
def category(self, request):
return Response(dict(Stakeholder.Category.choices))


class AttackPathViewSet(BaseModelViewSet):
model = AttackPath


class OperationalScenarioViewSet(BaseModelViewSet):
model = OperationalScenario
Loading