-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Signals to cascade VulnerabilityAssignment on Asset deletion, Fix #…
- Loading branch information
1 parent
c079305
commit 5571465
Showing
6 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.db.models.signals import post_delete | ||
from django.dispatch import receiver | ||
from django.contrib.contenttypes.models import ContentType | ||
from netbox.plugins.utils import get_plugin_config | ||
|
||
|
||
from . import models | ||
|
||
@receiver(post_delete) | ||
def handle_vulnerable_asset_delete(sender,instance, **kwargs): | ||
|
||
supported_model_class = False | ||
supported_assets = get_plugin_config("nb_risk", "supported_assets") | ||
additional_assets = get_plugin_config("nb_risk", "additional_assets") | ||
supported_assets = supported_assets + additional_assets | ||
|
||
for asset in supported_assets: | ||
app_label, model = asset.split(".") | ||
model = ContentType.objects.get(app_label=app_label, model=model).model_class() | ||
if isinstance(instance, model): | ||
supported_model_class = True | ||
break | ||
|
||
if supported_model_class: | ||
related_VulAssings = models.VulnerabilityAssignment.objects.filter( | ||
asset_object_type=ContentType.objects.get_for_model(instance), | ||
asset_id=instance.id ) | ||
for vulnAssign in related_VulAssings: | ||
vulnAssign.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters