Skip to content
Snippets Groups Projects
Commit 7c89b12f authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Fix linting warnings

parent 4dc5f41d
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ def register_cli(app):
db.session.add(instance)
try:
db.session.commit()
except sa.exc.IntegrityError as e:
except sa.exc.IntegrityError:
db.session.rollback()
app.logger.debug(f"{instance} already exists")
......
......@@ -932,7 +932,7 @@ class Network(CreatedMixin, db.Model):
if string is None:
return None
if VLAN_NAME_RE.fullmatch(string) is None:
raise ValidationError("Vlan name shall match [A-Za-z0-9\-]{3,25}")
raise ValidationError(r"Vlan name shall match [A-Za-z0-9\-]{3,25}")
return string
def to_dict(self, recursive=False):
......@@ -1257,7 +1257,7 @@ class Host(CreatedMixin, SearchableMixin, db.Model):
# Force the string to lowercase
lower_string = string.lower()
if HOST_NAME_RE.fullmatch(lower_string) is None:
raise ValidationError("Host name shall match [a-z0-9\-]{2,20}")
raise ValidationError(r"Host name shall match [a-z0-9\-]{2,20}")
existing_cname = Cname.query.filter_by(name=lower_string).first()
if existing_cname:
raise ValidationError(f"Host name matches an existing cname")
......@@ -1360,7 +1360,7 @@ class Interface(CreatedMixin, db.Model):
# Force the string to lowercase
lower_string = string.lower()
if HOST_NAME_RE.fullmatch(lower_string) is None:
raise ValidationError("Interface name shall match [a-z0-9\-]{2,20}")
raise ValidationError(r"Interface name shall match [a-z0-9\-]{2,20}")
if self.host and not lower_string.startswith(self.host.name):
raise ValidationError(
f"Interface name shall start with the host name '{self.host}'"
......@@ -1494,7 +1494,7 @@ class Cname(CreatedMixin, db.Model):
# Force the string to lowercase
lower_string = string.lower()
if HOST_NAME_RE.fullmatch(lower_string) is None:
raise ValidationError("cname shall match [a-z0-9\-]{2,20}")
raise ValidationError(r"cname shall match [a-z0-9\-]{2,20}")
existing_interface = Interface.query.filter_by(name=lower_string).first()
if existing_interface:
raise ValidationError(f"cname matches an existing interface")
......
......@@ -155,6 +155,7 @@ def get_query(query, **kwargs):
try:
query = query.filter_by(**kwargs)
except (sa.exc.InvalidRequestError, AttributeError) as e:
current_app.logger.warning(f"Invalid query arguments: {e}")
raise CSEntryError("Invalid query arguments", status_code=422)
return query
......
......@@ -14,11 +14,11 @@ import re
import sqlalchemy as sa
from wtforms import ValidationError, SelectField
ICS_ID_RE = re.compile("[A-Z]{3}[0-9]{3}")
HOST_NAME_RE = re.compile("^[a-z0-9\-]{2,20}$")
VLAN_NAME_RE = re.compile("^[A-Za-z0-9\-]{3,25}$")
MAC_ADDRESS_RE = re.compile("^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$")
DEVICE_TYPE_RE = re.compile("^[A-Za-z0-9]{3,25}$")
ICS_ID_RE = re.compile(r"[A-Z]{3}[0-9]{3}")
HOST_NAME_RE = re.compile(r"^[a-z0-9\-]{2,20}$")
VLAN_NAME_RE = re.compile(r"^[A-Za-z0-9\-]{3,25}$")
MAC_ADDRESS_RE = re.compile(r"^(?:[0-9a-fA-F]{2}[:-]?){5}[0-9a-fA-F]{2}$")
DEVICE_TYPE_RE = re.compile(r"^[A-Za-z0-9]{3,25}$")
class NoValidateSelectField(SelectField):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment