Skip to content

Commit

Permalink
Fixes #20, #22, Add changelog file, Add case sensitive constrain to v…
Browse files Browse the repository at this point in the history
…ulnerability names
  • Loading branch information
renatoalmeidaoliveira committed Aug 20, 2023
1 parent 00d4af1 commit 48ed783
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## 35.1.0 (18/08/2023)

* Add case sensitive name constrain to Vulnerability model
* Change the import path of get_plugin_config() to extras.plugins.utils [13368](https://github.com/netbox-community/netbox/commit/f5a1f83f9fa9d98c945d21eb0f7ccb8cd37fbf59)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PYTHON_VER?=3.10
NETBOX_VER?=v3.5.1
NETBOX_VER?=v3.5.8


COMPOSE_FILE=./develop/docker-compose.yml
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Netbox Nbrisk
[Netbox](https://github.com/netbox-community/netbox) Plugin inspired in NIST 800-30 Risk Management **BETA VERSION**
[Netbox](https://github.com/netbox-community/netbox) Plugin inspired in NIST 800-30 Risk Management


## Compatibility
Expand All @@ -13,11 +13,15 @@ To ensure NBRisk plugin is automatically re-installed during future upgrades, cr

### For NetBox 3.4.x
```shell
# echo "NbRisk==^34.0.0" >> local_requirements.txt
# echo "NbRisk==34.*" >> local_requirements.txt
```
### For NetBox 3.5.x
### For NetBox 3.5.0 to 3.5.7
```shell
# echo "NbRisk==^35.0.0" >> local_requirements.txt
# echo "NbRisk==35.0.*" >> local_requirements.txt
```
### For NetBox 3.5.8 or grater
```shell
# echo "NbRisk==35.1.*" >> local_requirements.txt
```

Once installed, the plugin needs to be enabled in your configuration.py
Expand Down
2 changes: 1 addition & 1 deletion develop/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG python_ver=3.10
FROM python:${python_ver}

ARG netbox_ver=v3.5.1
ARG netbox_ver=v3.5.8
ENV PYTHONUNBUFFERED 1

RUN mkdir -p /opt
Expand Down
18 changes: 18 additions & 0 deletions nb_risk/migrations/0005_alter_vulnerability_cvssbasescore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.9 on 2023-05-13 16:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nb_risk', '0004_alter_vulnerability_options'),
]

operations = [
migrations.AlterField(
model_name='vulnerability',
name='cvssbaseScore',
field=models.FloatField(blank=True, max_length=100, null=True),
),
]
17 changes: 17 additions & 0 deletions nb_risk/migrations/0006_vulnerability_unique_vuln_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.1.9 on 2023-05-13 17:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nb_risk', '0005_alter_vulnerability_cvssbasescore'),
]

operations = [
migrations.AddConstraint(
model_name='vulnerability',
constraint=models.UniqueConstraint(fields=('name',), name='unique_vuln_name'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.1.10 on 2023-08-20 02:18

from django.db import migrations, models
import django.db.models.functions.text


class Migration(migrations.Migration):

dependencies = [
('nb_risk', '0006_vulnerability_unique_vuln_name'),
]

operations = [
migrations.RemoveConstraint(
model_name='vulnerability',
name='unique_vuln_name',
),
migrations.AddConstraint(
model_name='vulnerability',
constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('name'), name='unique_vuln_name'),
),
]
9 changes: 8 additions & 1 deletion nb_risk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.urls import reverse
from django.db.models.functions import Lower

from netbox.models import NetBoxModel
from . import choices
Expand Down Expand Up @@ -63,7 +64,7 @@ class Vulnerability(NetBoxModel):
cvssavailabilityImpact = models.CharField(
"Availability Impact (A)", max_length=100, blank=True
)
cvssbaseScore = models.FloatField("Base Score", max_length=100, blank=True)
cvssbaseScore = models.FloatField("Base Score", max_length=100, blank=True, null=True,)

def affected_assets(self):
return self.vulnerability_assignments.count()
Expand All @@ -77,6 +78,12 @@ def get_absolute_url(self):
class Meta:
verbose_name = "Vulnerability"
verbose_name_plural = "Vulnerabilities"
constraints = (
models.UniqueConstraint(
Lower('name'),
name="unique_vuln_name"
),
)


# VulnearbilityAssingment Model
Expand Down
3 changes: 2 additions & 1 deletion nb_risk/template_content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from extras.plugins import PluginTemplateExtension, get_plugin_config
from extras.plugins import PluginTemplateExtension
from extras.plugins.utils import get_plugin_config
from django.conf import settings
from packaging import version

Expand Down
2 changes: 1 addition & 1 deletion nb_risk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "35.0.2"
__version__ = "35.1.0"
2 changes: 1 addition & 1 deletion nb_risk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tenancy.models import Tenant
from virtualization.models import VirtualMachine

from extras.plugins import get_plugin_config
from extras.plugins.utils import get_plugin_config
from utilities.views import ViewTab, register_model_view
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import get_object_or_404
Expand Down

0 comments on commit 48ed783

Please sign in to comment.