Add firewall and auth on driver API

This commit is contained in:
2022-04-10 18:33:49 +02:00
parent 28d2f5a68e
commit 9abdf55488
8 changed files with 164 additions and 4 deletions

View File

@@ -1,16 +1,41 @@
from django.db import models
from django.core.exceptions import ValidationError
from ipaddress import IPv4Address, IPv4Network
from solo.models import SingletonModel
class DriverConfiguration(SingletonModel):
remote_host = models.GenericIPAddressField(
protocol="IPv4", default="192.168.4.1"
protocol="IPv4",
default="192.168.4.1"
)
remote_port = models.SmallIntegerField(default=2560)
timeout = models.SmallIntegerField(default=250)
network = models.GenericIPAddressField(
protocol="IPv4",
default="192.168.4.0",
blank=True,
null=True
)
subnet_mask = models.GenericIPAddressField(
protocol="IPv4",
default="255.255.255.0",
blank=True,
null=True
)
def __str__(self):
return "Configuration"
def clean(self, *args, **kwargs):
if self.network:
try:
IPv4Network(
"{0}/{1}".format(self.network, self.subnet_mask))
except ValueError as e:
raise ValidationError(e)
super().clean(*args, **kwargs)
class Meta:
verbose_name = "Configuration"