You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
3.2 KiB

# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
import sys
from splunk.clilib.bundle_paths import make_splunkhome_path
sys.path.append(make_splunkhome_path(['etc', 'apps', 'SA-ITOA', 'lib']))
from itsi.data_integrations.data_integrations_constants import STATUS_CODE_LOGGING_KEY
"""
Contains different defined exceptions
ITOA-8115: remove dependencies of SA-ITOA from SA-ITSI-Licensechecker.
Manually copied to apps/SA-ITSI-Licensechecker/lib/ITOA/itoa_exceptions.py
If you change this file, make sure to also update the copy.
"""
class ItoaError(Exception):
"""
Generic exception class with some generic defaults
If it gets the logger passed into it, it will also log the
error appropriately
"""
def __init__(self, message, logger, log_prefix='[ITOA Error]', status_code=500, uid='', context=None):
super(ItoaError, self).__init__(message, uid, context)
self.message = message
self.uid = uid
self.context = context
# if this error ends up making it up to REST, allow a status code to be declared
self.status_code = status_code
if logger is not None:
logger.error(log_prefix + message, props={STATUS_CODE_LOGGING_KEY: status_code})
def __str__(self):
return self.message
class UnsupportedObjectTypeError(ItoaError):
"""
Indicates that the object type passed in is unsupported
"""
def __init__(self, message, logger=None, status_code=400):
super(UnsupportedObjectTypeError, self).__init__(message, logger, status_code=status_code)
class ItoaValidationError(ItoaError):
""" Bad request exception result in 400 error """
def __init__(self, message, logger, log_prefix='[ITOA Validation Error]', status_code=400,
uid='', context=None):
super(ItoaValidationError, self).__init__(message, logger, log_prefix, status_code,
uid, context)
class ItoaNotFoundError(ItoaError):
""" Not found exception result in 404 error """
def __init__(self, message, logger, log_prefix='[ITOA Not Found Error]', status_code=404):
super(ItoaNotFoundError, self).__init__(message, logger, log_prefix, status_code)
class ItoaAlreadyExistsError(ItoaError):
""" Already exists exception result in 409 error """
def __init__(self, message, logger, log_prefix='[ITOA Already Exists Error]', status_code=409):
super(ItoaAlreadyExistsError, self).__init__(message, logger, log_prefix, status_code)
class ItoaDatamodelContextError(ItoaError):
"""
Indicates that the datamodel context(for datamodel, its objects or fields) being looked up could not be found
"""
def __init__(self, message, logger, log_prefix='[ITOA Datamodel Context Error]', status_code=400):
super(ItoaDatamodelContextError, self).__init__(message, logger, log_prefix, status_code)
class ItoaAccessDeniedError(ItoaError):
def __init__(self, message, logger, log_prefix='[ITOA Access Denied Error]', status_code=403):
if 'access denied' not in message.lower():
message = 'Access denied. %s' % message
super(ItoaAccessDeniedError, self).__init__(message, logger, log_prefix, status_code)