Added an error when trying to retrieve a checksum from an empty list. Small other fixes.

This commit is contained in:
Daniele Maglie 2024-01-24 12:12:56 +01:00
parent c82d4683b9
commit 579ed1de04
16 changed files with 60 additions and 5 deletions

View file

@ -11,6 +11,7 @@ python_requires = >= 3.10
install_requires =
redis
rq
python-dateutil
[options.packages.find]
where = src

View file

@ -53,7 +53,7 @@ class AccountSessionGetCurrentByAccountService(BaseService):
# TODO: need to deal with this in the storage.
# let's save the long session as well
long_session = self.data_memory.get_session(f'session:{account_id}:long:{session.get('refresh_token')}')
long_session = self.data_memory.get_session(f"session:{account_id}:long:{session.get('refresh_token')}")
long_session['token'] = session.get('refresh_token')

View file

@ -129,6 +129,7 @@ class TicketCreateService(BaseService):
)
# proceed to build the relation item <-> provider
# this part provides a check for duplicates, whitelisted items and error tickets
(fqdn_ticket_items, ipv4_ticket_items, ipv6_ticket_items) = self.ticket_relation_establish_service.execute(
ticket_id = model.get('ticket_id'),
providers = model.get('assigned_to'),
@ -150,7 +151,8 @@ class TicketCreateService(BaseService):
ipv6 = ipv6,
now = Time.now_iso8601(),
created_by = created_by,
tasks = [ # append the task id so we can cancel its execution if needed
tasks = [
# append the task id so we can cancel its execution if needed
initialize_job_id,
autoclose_job_id
]

View file

@ -23,6 +23,8 @@ class TicketItemErrorCode:
TICKET_ITEM_UPDATE_TIME_EXCEEDED = '5010'
TICKET_ITEM_EMPTY_CHECKSUM = '5011'
class TicketItemErrorMessage:
GENERIC = 'Error during the creation of the ticket item.'
@ -46,3 +48,5 @@ class TicketItemErrorMessage:
TICKET_ITEM_REASON_NON_VALID = 'Non valid unprocessed reason.'
TICKET_ITEM_UPDATE_TIME_EXCEEDED = 'Cannot update the ticket item: max update time has been exceeded.'
TICKET_ITEM_EMPTY_CHECKSUM = 'No ticket item available to generate a checksum.'

View file

@ -39,6 +39,10 @@ class TicketItemFQDNGetAllByTicketChecksumService(BaseService):
ticket_id = ticket_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -40,6 +40,10 @@ class TicketItemFQDNGetAllByTicketChecksumForProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -28,7 +28,7 @@ class TicketItemFQDNGetAllChecksumService(BaseService):
self._prepare_modules()
def execute(self, ticket_id: str) -> dict | Exception:
def execute(self) -> dict | Exception:
"""
Get the checksum of all the FQDN items in the database.
@ -37,6 +37,10 @@ class TicketItemFQDNGetAllChecksumService(BaseService):
response = self.ticket_item_fqdn_get_all_service.execute()
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -39,6 +39,10 @@ class TicketItemFQDNGetAllChecksumByProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -39,6 +39,10 @@ class TicketItemIPv4GetAllByTicketChecksumService(BaseService):
ticket_id = ticket_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -40,6 +40,10 @@ class TicketItemIPv4GetAllByTicketChecksumForProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -28,7 +28,7 @@ class TicketItemIPv4GetAllChecksumService(BaseService):
self._prepare_modules()
def execute(self, ticket_id: str) -> dict | Exception:
def execute(self) -> dict | Exception:
"""
Get the checksum of all the IPv4 items in the database.
@ -37,6 +37,10 @@ class TicketItemIPv4GetAllChecksumService(BaseService):
response = self.ticket_item_ipv4_get_all_service.execute()
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -39,6 +39,10 @@ class TicketItemIPv4GetAllChecksumByProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -37,6 +37,10 @@ class TicketItemIPv6GetAllByTicketChecksumService(BaseService):
response = self.get_ipv6_all_by_ticket(ticket_id)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -40,6 +40,10 @@ class TicketItemIPv6GetAllByTicketChecksumForProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -28,7 +28,7 @@ class TicketItemIPv6GetAllChecksumService(BaseService):
self._prepare_modules()
def execute(self, ticket_id: str) -> dict | Exception:
def execute(self) -> dict | Exception:
"""
Get the checksum of all the IPv6 items in the database.
@ -37,6 +37,10 @@ class TicketItemIPv6GetAllChecksumService(BaseService):
response = self.ticket_item_ipv6_get_all_service.execute()
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try:

View file

@ -39,6 +39,10 @@ class TicketItemIPv6GetAllChecksumByProviderService(BaseService):
account_id = account_id
)
# we don't have any data to work on
if not len(response):
raise ApplicationException(TicketItemErrorCode.TICKET_ITEM_EMPTY_CHECKSUM, TicketItemErrorMessage.TICKET_ITEM_EMPTY_CHECKSUM)
data = '\n'.join(response)
try: