Skip to content

Commit

Permalink
Add likelihood endpoint for attack paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 5, 2024
1 parent 479add6 commit 1e5ce90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ def save(self, *args, **kwargs):
self.folder = self.ebios_rm_study.folder
super().save(*args, **kwargs)

@property
def risk_matrix(self):
return self.ebios_rm_study.risk_matrix

@property
def parsed_matrix(self):
return self.risk_matrix.parse_json_translated()


class OperationalScenario(AbstractBaseModel, FolderMixin):
ebios_rm_study = models.ForeignKey(
Expand Down
19 changes: 19 additions & 0 deletions backend/ebios_rm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ def category(self, request):
class AttackPathViewSet(BaseModelViewSet):
model = AttackPath

@action(detail=True, name="Get risk matrix", url_path="risk-matrix")
def risk_matrix(self, request, pk=None):
attack_path = self.get_object()
return Response(RiskMatrixReadSerializer(attack_path.risk_matrix).data)

@method_decorator(cache_page(60 * LONG_CACHE_TTL))
@action(detail=True, name="Get likelihood choices")
def likelihood(self, request, pk):
attack_path: AttackPath = self.get_object()
undefined = dict([(-1, "--")])
_choices = dict(
zip(
list(range(0, 64)),
[x["name"] for x in attack_path.parsed_matrix["probability"]],
)
)
choices = undefined | _choices
return Response(choices)


class OperationalScenarioViewSet(BaseModelViewSet):
model = OperationalScenario

0 comments on commit 1e5ce90

Please sign in to comment.