mirror of
https://github.com/fuckpiracyshield/data-model.git
synced 2024-11-14 17:57:16 +01:00
Various fixes.
This commit is contained in:
parent
c38cd3f855
commit
3a83d89088
9 changed files with 114 additions and 13 deletions
|
@ -10,6 +10,6 @@ class ForensicArchiveRule:
|
|||
|
||||
NAME = [
|
||||
Required(),
|
||||
String(allowed = '.-_'),
|
||||
Length(minimum = 6, maximum = 128)
|
||||
String(allowed = ' .-_'),
|
||||
Length(minimum = 6, maximum = 320)
|
||||
]
|
||||
|
|
|
@ -205,7 +205,7 @@ class TicketItemModel(BaseModel):
|
|||
validator.validate()
|
||||
|
||||
if not validator.is_valid():
|
||||
raise TicketItemModelProviderIdentifierException(validator.errors)
|
||||
raise TicketItemModelProviderIdentifierNonValidException(validator.errors)
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ class TicketModel(BaseModel):
|
|||
self.assigned_to = self._validate_assigned_to(assigned_to) if assigned_to else None
|
||||
|
||||
# ticket initial status
|
||||
self.status = TicketStatusModel.CREATED.value
|
||||
self.status = TicketStatusModel.CREATING.value
|
||||
|
||||
# this is a blocking ticket
|
||||
self.genre = TicketGenreModel.BLOCKING.value
|
||||
|
|
|
@ -19,7 +19,7 @@ class TicketRule:
|
|||
|
||||
DESCRIPTION = [
|
||||
Required(),
|
||||
String(' .,-_@'),
|
||||
String(' .,-_@/\'"'),
|
||||
Length(minimum = 3, maximum = 255)
|
||||
]
|
||||
|
||||
|
|
|
@ -6,8 +6,12 @@ class TicketStatusModel(Enum):
|
|||
Ticket status types with relative identifier.
|
||||
"""
|
||||
|
||||
CREATING = 'creating'
|
||||
|
||||
CREATED = 'created'
|
||||
|
||||
OPEN = 'open'
|
||||
|
||||
CLOSED = 'closed'
|
||||
|
||||
FAILED = 'failed'
|
||||
|
|
1
src/piracyshield_data_model/whitelist/genre/__init__.py
Normal file
1
src/piracyshield_data_model/whitelist/genre/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
|
17
src/piracyshield_data_model/whitelist/genre/model.py
Normal file
17
src/piracyshield_data_model/whitelist/genre/model.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from enum import Enum
|
||||
|
||||
class WhitelistGenreModel(Enum):
|
||||
|
||||
"""
|
||||
Whitelist item genres.
|
||||
"""
|
||||
|
||||
FQDN = 'fqdn'
|
||||
|
||||
IPV4 = 'ipv4'
|
||||
|
||||
IPV6 = 'ipv6'
|
||||
|
||||
CIDR_IPV4 = 'cidr_ipv4'
|
||||
|
||||
CIDR_IPV6 = 'cidr_ipv6'
|
|
@ -2,8 +2,7 @@ from piracyshield_data_model.base import BaseModel
|
|||
|
||||
from piracyshield_component.validation.validator import Validator
|
||||
|
||||
from piracyshield_data_model.ticket.item.genre.model import TicketItemGenreModel
|
||||
|
||||
from piracyshield_data_model.whitelist.genre.model import WhitelistGenreModel
|
||||
from piracyshield_data_model.whitelist.rule import WhitelistRule
|
||||
from piracyshield_data_model.ticket.rule import TicketRule
|
||||
|
||||
|
@ -27,26 +26,34 @@ class WhitelistModel(BaseModel):
|
|||
"""
|
||||
Validates the parameters.
|
||||
|
||||
:param genre: FQDN, IPv4 or IPv6 type.
|
||||
:param genre: FQDN, IPv4, IPv6 or a CIDR IPv4/IPv6 class.
|
||||
:param value: value of the item.
|
||||
:param is_active: if the item is already active or not.
|
||||
:param registrar: registrar of the FQDN item.
|
||||
:param as_code: AS code of the IPv4 or IPv6 item.
|
||||
:param as_code: AS code of the IPv4, IPv6 or CIDR classes.
|
||||
"""
|
||||
|
||||
match genre:
|
||||
case TicketItemGenreModel.FQDN.value:
|
||||
case WhitelistGenreModel.FQDN.value:
|
||||
self.value = self._validate_fqdn(value)
|
||||
self.registrar = self._validate_registrar(registrar)
|
||||
|
||||
case TicketItemGenreModel.IPV4.value:
|
||||
case WhitelistGenreModel.IPV4.value:
|
||||
self.value = self._validate_ipv4(value)
|
||||
self.as_code = self._validate_as_code(as_code)
|
||||
|
||||
case TicketItemGenreModel.IPV6.value:
|
||||
case WhitelistGenreModel.IPV6.value:
|
||||
self.value = self._validate_ipv6(value)
|
||||
self.as_code = self._validate_as_code(as_code)
|
||||
|
||||
case WhitelistGenreModel.CIDR_IPV4.value:
|
||||
self.value = self._validate_cidr_ipv4(value)
|
||||
self.as_code = self._validate_as_code(as_code)
|
||||
|
||||
case WhitelistGenreModel.CIDR_IPV6.value:
|
||||
self.value = self._validate_cidr_ipv6(value)
|
||||
self.as_code = self._validate_as_code(as_code)
|
||||
|
||||
case _:
|
||||
raise WhitelistModelGenreException()
|
||||
|
||||
|
@ -114,6 +121,46 @@ class WhitelistModel(BaseModel):
|
|||
|
||||
return value
|
||||
|
||||
def _validate_cidr_ipv4(self, value: str) -> str | Exception:
|
||||
"""
|
||||
Validates the CIDR IPv4 class.
|
||||
|
||||
:param value: a valid CIDR IPv4 class.
|
||||
:return: the same value.
|
||||
"""
|
||||
|
||||
if not value or not len(value):
|
||||
raise WhitelistModelCIDRIPv4MissingException()
|
||||
|
||||
validator = Validator(value, WhitelistRule.CIDR_IPV4)
|
||||
|
||||
validator.validate()
|
||||
|
||||
if not validator.is_valid():
|
||||
raise WhitelistModelCIDRIPv4NonValidException(validator.errors)
|
||||
|
||||
return value
|
||||
|
||||
def _validate_cidr_ipv6(self, value: str) -> str | Exception:
|
||||
"""
|
||||
Validates the CIDR IPv6 class.
|
||||
|
||||
:param value: a valid CIDR IPv6 class.
|
||||
:return: the same value.
|
||||
"""
|
||||
|
||||
if not value or not len(value):
|
||||
raise WhitelistModelCIDRIPv6MissingException()
|
||||
|
||||
validator = Validator(value, WhitelistRule.CIDR_IPV6)
|
||||
|
||||
validator.validate()
|
||||
|
||||
if not validator.is_valid():
|
||||
raise WhitelistModelCIDRIPv6NonValidException(validator.errors)
|
||||
|
||||
return value
|
||||
|
||||
def _validate_registrar(self, value: str) -> str | Exception:
|
||||
"""
|
||||
Validates the registrar of a FQDN item.
|
||||
|
@ -226,6 +273,38 @@ class WhitelistModelIPv6NonValidException(Exception):
|
|||
|
||||
pass
|
||||
|
||||
class WhitelistModelCIDRIPv4MissingException(Exception):
|
||||
|
||||
"""
|
||||
No CIDR IPv4 class passed.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
class WhitelistModelCIDRIPv4NonValidException(Exception):
|
||||
|
||||
"""
|
||||
Non valid CIDR IPv4 class.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
class WhitelistModelCIDRIPv6MissingException(Exception):
|
||||
|
||||
"""
|
||||
No CIDR IPv6 class passed.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
class WhitelistModelCIDRIPv6NonValidException(Exception):
|
||||
|
||||
"""
|
||||
Non valid CIDR IPv6 class.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
class WhitelistModelRegistrarNonValidException(Exception):
|
||||
|
||||
"""
|
||||
|
|
|
@ -13,7 +13,7 @@ class WhitelistRule:
|
|||
|
||||
REGISTRAR = [
|
||||
Required(),
|
||||
String(allowed = ' -'),
|
||||
String(allowed = ' .,-_'),
|
||||
Length(minimum = 3, maximum = 255)
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue