mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-05 05:37:50 +02:00
Run black on py
This commit is contained in:
@@ -6,23 +6,16 @@ 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
|
||||
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
|
||||
protocol="IPv4", default="255.255.255.0", blank=True, null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
@@ -31,8 +24,7 @@ class DriverConfiguration(SingletonModel):
|
||||
def clean(self, *args, **kwargs):
|
||||
if self.network:
|
||||
try:
|
||||
IPv4Network(
|
||||
"{0}/{1}".format(self.network, self.subnet_mask))
|
||||
IPv4Network("{0}/{1}".format(self.network, self.subnet_mask))
|
||||
except ValueError as e:
|
||||
raise ValidationError(e)
|
||||
super().clean(*args, **kwargs)
|
||||
|
@@ -7,7 +7,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.permissions import (
|
||||
IsAuthenticated,
|
||||
BasePermission,
|
||||
SAFE_METHODS
|
||||
SAFE_METHODS,
|
||||
)
|
||||
|
||||
from ram.parsers import PlainTextParser
|
||||
@@ -40,16 +40,15 @@ class Firewall(BasePermission):
|
||||
if not config.network:
|
||||
return request.method in SAFE_METHODS
|
||||
|
||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
|
||||
if x_forwarded_for:
|
||||
ip = IPv4Address(x_forwarded_for.split(',')[0])
|
||||
ip = IPv4Address(x_forwarded_for.split(",")[0])
|
||||
else:
|
||||
ip = IPv4Address(request.META.get("REMOTE_ADDR"))
|
||||
|
||||
network = IPv4Network("{0}/{1}".format(
|
||||
config.network,
|
||||
config.subnet_mask
|
||||
))
|
||||
network = IPv4Network(
|
||||
"{0}/{1}".format(config.network, config.subnet_mask)
|
||||
)
|
||||
|
||||
# accept IP configured is settings or localhost
|
||||
if ip in network or ip in IPv4Network("127.0.0.0/8"):
|
||||
@@ -101,6 +100,7 @@ class Function(APIView):
|
||||
"""
|
||||
Send "Function" commands to a valid DCC address
|
||||
"""
|
||||
|
||||
permission_classes = [IsAuthenticated | Firewall]
|
||||
|
||||
def put(self, request, address):
|
||||
@@ -117,6 +117,7 @@ class Cab(APIView):
|
||||
"""
|
||||
Send "Cab" commands to a valid DCC address
|
||||
"""
|
||||
|
||||
permission_classes = [IsAuthenticated | Firewall]
|
||||
|
||||
def put(self, request, address):
|
||||
@@ -132,6 +133,7 @@ class Infra(APIView):
|
||||
"""
|
||||
Send "Infra" commands to a valid DCC address
|
||||
"""
|
||||
|
||||
permission_classes = [IsAuthenticated | Firewall]
|
||||
|
||||
def put(self, request):
|
||||
@@ -147,6 +149,7 @@ class Emergency(APIView):
|
||||
"""
|
||||
Send an "Emergency" stop, no matter the HTTP method used
|
||||
"""
|
||||
|
||||
permission_classes = [IsAuthenticated | Firewall]
|
||||
|
||||
def put(self, request):
|
||||
|
Reference in New Issue
Block a user