From: Frank Brehm Date: Tue, 30 Jan 2024 11:10:04 +0000 (+0100) Subject: Reorganizing Exception classes. X-Git-Tag: 1.0.0~1^2~34 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=441849e391f616f94f775ad92ad5bf76e241a939;p=pixelpark%2Fpp-admin-tools.git Reorganizing Exception classes. --- diff --git a/lib/pp_admintools/app/__init__.py b/lib/pp_admintools/app/__init__.py index e3abc1f..0ffc86b 100644 --- a/lib/pp_admintools/app/__init__.py +++ b/lib/pp_admintools/app/__init__.py @@ -14,7 +14,6 @@ import shutil # Third party modules from fb_tools.cfg_app import FbConfigApplication -from fb_tools.errors import FbAppError from fb_tools.multi_config import BaseMultiConfig # Own modules @@ -32,21 +31,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.7.0' - - -# ============================================================================= -class DPXAppError(FbAppError): - """Base exception class for all exceptions in all LDAP using application classes.""" - - pass - - -# ============================================================================= -class AbortAppError(DPXAppError): - """Special exception class interrupting the application.""" - - pass +__version__ = '0.8.0' # ============================================================================= diff --git a/lib/pp_admintools/app/check_ldap_dn_attributes.py b/lib/pp_admintools/app/check_ldap_dn_attributes.py index f84c52f..531b993 100644 --- a/lib/pp_admintools/app/check_ldap_dn_attributes.py +++ b/lib/pp_admintools/app/check_ldap_dn_attributes.py @@ -21,26 +21,17 @@ from fb_tools.collections import CIDict, CIStringSet from fb_tools.xlate import format_list from .ldap import BaseLdapApplication -# from .ldap import LdapAppError, FatalLDAPError -from .ldap import LdapAppError from .. import pp from ..config.ldap import LdapConfiguration from ..xlate import XLATOR -__version__ = '0.3.6' +__version__ = '0.4.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class CheckLdapDnAttributesError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class CheckLdapDnAttributesApplication(BaseLdapApplication): """Application class for checking all DN-like attributes in a LDAP instance.""" diff --git a/lib/pp_admintools/app/check_ldap_pwd_schemes.py b/lib/pp_admintools/app/check_ldap_pwd_schemes.py index 12b4007..bafdbc5 100644 --- a/lib/pp_admintools/app/check_ldap_pwd_schemes.py +++ b/lib/pp_admintools/app/check_ldap_pwd_schemes.py @@ -25,27 +25,18 @@ from fb_tools.collections import CIDict, CIStringSet from fb_tools.xlate import format_list from .ldap import BaseLdapApplication -# from .ldap import LdapAppError, FatalLDAPError -from .ldap import LdapAppError from .. import pp from ..config.ldap import LdapConfiguration from ..handler.ldap_password import LdapPasswordHandler from ..xlate import XLATOR -__version__ = '0.2.3' +__version__ = '0.3.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class CheckLdapPwdSchemesError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class CheckLdapPwdSchemesApplication(BaseLdapApplication): """Application class for checking password hashing schemes in LDAP.""" diff --git a/lib/pp_admintools/app/clean_empty_ldap_groups.py b/lib/pp_admintools/app/clean_empty_ldap_groups.py index 95fc445..901e6ab 100644 --- a/lib/pp_admintools/app/clean_empty_ldap_groups.py +++ b/lib/pp_admintools/app/clean_empty_ldap_groups.py @@ -24,25 +24,16 @@ from fb_tools.xlate import format_list # Own modules from .ldap import BaseLdapApplication -# from .ldap import FatalLDAPError -from .ldap import LdapAppError from .. import pp from ..xlate import XLATOR -__version__ = '0.4.0' +__version__ = '0.5.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class CleanEmptyLdapGroupsUserError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class CleanEmptyLdapGroupsApplication(BaseLdapApplication): """Application class for removing empty groups from LDAP.""" diff --git a/lib/pp_admintools/app/dns_deploy_zones.py b/lib/pp_admintools/app/dns_deploy_zones.py index f9388dc..1a5a228 100644 --- a/lib/pp_admintools/app/dns_deploy_zones.py +++ b/lib/pp_admintools/app/dns_deploy_zones.py @@ -36,25 +36,20 @@ from pytz import UnknownTimeZoneError, timezone import six # Own modules -from .pdns import PpPDNSAppError, PpPDNSApplication +from .pdns import PpPDNSApplication from .. import __version__ as GLOBAL_VERSION from .. import pp from ..config.dns_deploy_zones import DnsDeployZonesConfig +from ..errors import DpxDeployZonesError +from ..errors import DpxPDNSAppError from ..xlate import XLATOR -__version__ = '0.8.10' +__version__ = '0.9.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext -# ============================================================================= -class PpDeployZonesError(PpPDNSAppError): - """Special exception class to use in this module.""" - - pass - - # ============================================================================= class PpDeployZonesApp(PpPDNSApplication): """ @@ -331,7 +326,7 @@ class PpDeployZonesApp(PpPDNSApplication): try: super(PpDeployZonesApp, self).pre_run() - except PpPDNSAppError as e: + except DpxPDNSAppError as e: self.exit(5, str(e)) if self.cfg.pdns_instance == 'global': @@ -584,7 +579,7 @@ class PpDeployZonesApp(PpPDNSApplication): if key_id not in self.named_keys: msg = _('Key {k!r} for zone {z!r} not found in named configuration.').format( k=key_id, z=show_name) - raise PpDeployZonesError(msg) + raise DpxDeployZonesError(msg) allow_line = '\tallow-transfer {' for key_id in zone.master_tsig_key_ids: @@ -656,9 +651,9 @@ class PpDeployZonesApp(PpPDNSApplication): def files_equal_content(self, file_src, file_tgt): """Compare two configuration files by ignoring whitespaces and comments.""" if not file_src: - raise PpDeployZonesError(_('Source file not defined.')) + raise DpxDeployZonesError(_('Source file not defined.')) if not file_tgt: - raise PpDeployZonesError(_('Target file not defined.')) + raise DpxDeployZonesError(_('Target file not defined.')) LOG.debug(_('Comparing {one!r} with {two!r} ...').format( one=str(file_src), two=str(file_tgt))) @@ -666,11 +661,11 @@ class PpDeployZonesApp(PpPDNSApplication): if not file_src.exists(): msg = _('{what} {f!r} does not exists.').format( what=_('Source file'), f=str(file_src)) - raise PpDeployZonesError(msg) + raise DpxDeployZonesError(msg) if not file_src.is_file(): msg = _('{what} {f!r} is not a regular file.').format( what=_('Source file'), f=str(file_src)) - raise PpDeployZonesError(msg) + raise DpxDeployZonesError(msg) if not file_tgt.exists(): msg = _('{what} {f!r} does not exists.').format( @@ -680,7 +675,7 @@ class PpDeployZonesApp(PpPDNSApplication): if not file_tgt.is_file(): msg = _('{what} {f!r} is not a regular file.').format( what=_('Target file'), f=str(file_tgt)) - raise PpDeployZonesError(msg) + raise DpxDeployZonesError(msg) # Reading source file content_src = '' diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 01ea148..ec77862 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -35,65 +35,30 @@ from ldap3 import BASE, SUBTREE from ldap3 import Connection, DSA, IP_V4_PREFERRED, SAFE_SYNC, Server from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from ldap3.core.exceptions import LDAPBindError +# from ldap3.core.exceptions import LDAPCommunicationError from ldap3.core.exceptions import LDAPException # Own modules -from . import BaseDPXApplication, DPXAppError +from . import BaseDPXApplication from .. import DEFAULT_CONFIG_DIR, MAX_PORT_NUMBER from .. import __version__ as GLOBAL_VERSION from .. import pp from ..config.ldap import DEFAULT_TIMEOUT from ..config.ldap import LdapConfiguration, LdapConnectionInfo +# from ..errors import DpxAppError +from ..errors import DpxDeleteLdapItemError +from ..errors import DpxLdapError +from ..errors import DpxLdapParseError +from ..errors import DpxWriteLdapItemError from ..xlate import XLATOR, format_list -__version__ = '0.12.1' +__version__ = '1.0.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class LdapAppError(DPXAppError): - """Base exception class for all exceptions in all LDAP using application classes.""" - - pass - - -# ============================================================================= -class FatalLDAPError(LdapAppError): - """Fatal errors leading to interrupt the current application.""" - - pass - - -# ============================================================================= -class LDAPExecutionError(FatalLDAPError): - """Error class in case, a LDAP operation was not successful.""" - - pass - - -# ============================================================================= -class WriteLDAPItemError(FatalLDAPError): - """Error class in case, a LDAP item could not be written.""" - - pass - - -# ============================================================================= -class DeleteLDAPItemError(FatalLDAPError): - """Error class in case, a LDAP item could not be deleted.""" - - pass - -# ============================================================================= -class LDAPParseError(FatalLDAPError): - """Error on parsing LDAP stuff.""" - - pass - - # ============================================================================= class PasswordFileOptionAction(argparse.Action): """Argparse action for a password file.""" @@ -282,19 +247,19 @@ class BaseLdapApplication(BaseDPXApplication): path = Path(value) if not path.is_absolute(): msg = _('The path {!r} must be an absolute path.').format(value) - raise LdapAppError(msg) + raise DpxLdapError(msg) if not path.exists(): msg = _('The file {!r} does not exists.').format(str(path)) - raise LdapAppError(msg) + raise DpxLdapError(msg) if not path.is_file(): msg = _('The given path {!r} exists, but is not a regular file.').format(str(path)) - raise LdapAppError(msg) + raise DpxLdapError(msg) if not os.access(str(path), os.R_OK): msg = _('The given file {!r} is not readable.').format(str(path)) - raise LdapAppError(msg) + raise DpxLdapError(msg) self._password_file = path @@ -1345,7 +1310,7 @@ class BaseLdapApplication(BaseDPXApplication): dn=dn, c=e.__class__.__name__, e=e) msg += '\nobjectClasses:\n' + pp(object_classes) msg += '\nAttributes:\n' + pp(target_entry) - raise WriteLDAPItemError(msg) + raise DpxWriteLdapItemError(msg) # Example result on a not successful modification: # { 'description': 'objectClassViolation', @@ -1365,7 +1330,7 @@ class BaseLdapApplication(BaseDPXApplication): dn=dn, desc=req_result['description'], msg=req_result['message'].strip()) msg += '\nobjectClasses:\n' + pp(object_classes) msg += '\nAttributes:\n' + pp(target_entry) - raise WriteLDAPItemError(msg) + raise DpxWriteLdapItemError(msg) LOG.debug(_('Creation successful.')) return True @@ -1392,7 +1357,7 @@ class BaseLdapApplication(BaseDPXApplication): msg = _('Modification of {dn!r} was NOT successfull - {c}: {e}').format( dn=dn, c=e.__class__.__name__, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) - raise WriteLDAPItemError(msg) + raise DpxWriteLdapItemError(msg) # Example result on a not successful modification: # { 'description': 'objectClassViolation', @@ -1411,7 +1376,7 @@ class BaseLdapApplication(BaseDPXApplication): msg = _('Modification of {dn!r} was NOT successful: {desc} - {msg}').format( dn=dn, desc=req_result['description'], msg=req_result['message'].strip()) msg += '\n' + _('Changes:') + '\n' + pp(changes) - raise WriteLDAPItemError(msg) + raise DpxWriteLdapItemError(msg) LOG.debug(_('Modification successful.')) return True @@ -1436,7 +1401,7 @@ class BaseLdapApplication(BaseDPXApplication): except LDAPException as e: msg = _('Deletion of {dn!r} was NOT successfull - {c}: {e}').format( c=e.__class__.__name__, e=e) - raise DeleteLDAPItemError(msg) + raise DpxDeleteLdapItemError(msg) if self.verbose > 1: LOG.debug(_('Deletion status: {!r}.').format(req_status)) @@ -1446,7 +1411,7 @@ class BaseLdapApplication(BaseDPXApplication): if not req_status: msg = _('Deletion of {dn!r} was NOT successful: {desc} - {msg}').format( dn=dn, desc=req_result['description'], msg=req_result['message'].strip()) - raise DeleteLDAPItemError(msg) + raise DpxDeleteLdapItemError(msg) LOG.debug(_('Deletion successful.')) @@ -1629,7 +1594,7 @@ class BaseLdapApplication(BaseDPXApplication): match = self.re_dntoken.match(first_dn_token) if not match: msg = _('Could not detect RDN from DN {!r}.').format(dn) - raise LDAPParseError(msg) + raise DpxLdapParseError(msg) rdn = match.group(1) if self.verbose > 2: msg = _('Found RDN attribute {!r}.').format(rdn) diff --git a/lib/pp_admintools/app/mail.py b/lib/pp_admintools/app/mail.py index fd4c82c..b337d5a 100644 --- a/lib/pp_admintools/app/mail.py +++ b/lib/pp_admintools/app/mail.py @@ -23,7 +23,7 @@ from fb_tools import MailAddress from fb_tools.xlate import format_list # Own modules -from . import BaseDPXApplication, DPXAppError +from . import BaseDPXApplication from .. import DEFAULT_CONFIG_DIR, MAX_PORT_NUMBER from .. import __version__ as GLOBAL_VERSION from .. import pp @@ -31,20 +31,13 @@ from ..argparse_actions import PortOptionAction from ..config.mail import MailConfiguration from ..xlate import XLATOR -__version__ = '0.3.4' +__version__ = '0.4.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class MailAppError(DPXAppError): - """Base exception class for all exceptions in all mail sending application classes.""" - - pass - - # ============================================================================= class BaseMailApplication(BaseDPXApplication): """Base class for all mail sending application classes.""" diff --git a/lib/pp_admintools/app/mirror_ldap.py b/lib/pp_admintools/app/mirror_ldap.py index dbd4008..0bd2e46 100644 --- a/lib/pp_admintools/app/mirror_ldap.py +++ b/lib/pp_admintools/app/mirror_ldap.py @@ -25,29 +25,20 @@ from fb_tools.xlate import format_list from ldap3 import ALL_ATTRIBUTES # Own modules -# from .ldap import LdapAppError, FatalLDAPError from .ldap import BaseLdapApplication -from .ldap import LdapAppError from .. import pp from ..argparse_actions import LimitedFloatOptionAction from ..argparse_actions import NonNegativeIntegerOptionAction from ..config.mirror_ldap import MirrorLdapConfiguration from ..xlate import XLATOR -__version__ = '0.9.2' +__version__ = '1.0.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class MirrorLdapError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class MirrorLdapApplication(BaseLdapApplication): """Application class for mirroring one LDAP instance to another.""" diff --git a/lib/pp_admintools/app/mk_ldap_passwd.py b/lib/pp_admintools/app/mk_ldap_passwd.py index f3e221f..f908a98 100644 --- a/lib/pp_admintools/app/mk_ldap_passwd.py +++ b/lib/pp_admintools/app/mk_ldap_passwd.py @@ -17,27 +17,19 @@ from fb_tools.app import BaseApplication # Own modules from .. import pp -from ..errors import PpAppError from ..handler.ldap_password import LdapPasswordHandler from ..handler.ldap_password import WrongPwdSchemaError from ..handler.ldap_password import WrongRoundsError from ..handler.ldap_password import WrongSaltError from ..xlate import XLATOR -__version__ = '0.1.5' +__version__ = '0.2.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class MkLdapPasswdError(PpAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class MkLdapPasswdApplication(BaseApplication): """Application class for the mkldappasswd application.""" diff --git a/lib/pp_admintools/app/pdns.py b/lib/pp_admintools/app/pdns.py index 8bf78b2..c0f12fa 100644 --- a/lib/pp_admintools/app/pdns.py +++ b/lib/pp_admintools/app/pdns.py @@ -33,32 +33,22 @@ import psutil import requests # Own modules -from .mail import BaseMailApplication, MailAppError +from .mail import BaseMailApplication from .. import __version__ as GLOBAL_VERSION from .. import pp from ..argparse_actions import PortOptionAction from ..config.pdns import PdnsConfiguration # from ..config.pdns import PdnsConfigError, PdnsConfiguration +# from ..errors import DpxMailAppError +from ..errors import DpxPDNSAppError from ..xlate import XLATOR -__version__ = '0.10.0' +__version__ = '1.0.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext -# ============================================================================= -class PpPDNSAppError(MailAppError): - """ - Base error class for this module. - - It is intended for all exceptions happened during - execution this configured application. - """ - - pass - - # ============================================================================= class PpPDNSApplication(BaseMailApplication): """Class for configured application objects related to PowerDNS.""" @@ -101,7 +91,7 @@ class PpPDNSApplication(BaseMailApplication): if not self.cfg: msg = _('Configuration not available.') - raise PpPDNSAppError(msg) + raise DpxPDNSAppError(msg) self.eval_instance(instance) @@ -114,7 +104,7 @@ class PpPDNSApplication(BaseMailApplication): @api_key.setter def api_key(self, value): if value is None or str(value).strip() == '': - raise PpPDNSAppError(_('Invalid API key {!r} given.').format(value)) + raise DpxPDNSAppError(_('Invalid API key {!r} given.').format(value)) self._api_key = str(value).strip() # ----------------------------------------------------------- @@ -126,7 +116,7 @@ class PpPDNSApplication(BaseMailApplication): @api_host.setter def api_host(self, value): if value is None or str(value).strip() == '': - raise PpPDNSAppError(_('Invalid API host {!r} given.').format(value)) + raise DpxPDNSAppError(_('Invalid API host {!r} given.').format(value)) self._api_host = str(value).strip().lower() # ----------------------------------------------------------- @@ -139,7 +129,7 @@ class PpPDNSApplication(BaseMailApplication): def api_port(self, value): v = int(value) if v < 1: - raise PpPDNSAppError(_('Invalid API port {!r} given.').format(value)) + raise DpxPDNSAppError(_('Invalid API port {!r} given.').format(value)) self._api_port = v # ----------------------------------------------------------- @@ -151,7 +141,7 @@ class PpPDNSApplication(BaseMailApplication): @api_servername.setter def api_servername(self, value): if value is None or str(value).strip() == '': - raise PpPDNSAppError(_('Invalid API server name {!r} given.').format(value)) + raise DpxPDNSAppError(_('Invalid API server name {!r} given.').format(value)) self._api_servername = str(value).strip() # ----------------------------------------------------------- @@ -169,10 +159,10 @@ class PpPDNSApplication(BaseMailApplication): @instance.setter def instance(self, value): if value is None: - raise PpPDNSAppError(_('Invalid instance {!r} given.').format(None)) + raise DpxPDNSAppError(_('Invalid instance {!r} given.').format(None)) v = str(value).strip().lower() if v not in self.api_keys.keys(): - raise PpPDNSAppError(_('Invalid instance {!r} given.').format(value)) + raise DpxPDNSAppError(_('Invalid instance {!r} given.').format(value)) self.eval_instance(v) @@ -185,11 +175,11 @@ class PpPDNSApplication(BaseMailApplication): if not self.cfg: msg = _('Configuration not available.') - raise PpPDNSAppError(msg) + raise DpxPDNSAppError(msg) if inst_name not in self.cfg.pdns_api_instances: msg = _('PDNS instance {!r} is not configured.').format(inst_name) - raise PpPDNSAppError(msg) + raise DpxPDNSAppError(msg) self._instance = inst_name if self.cfg.pdns_host: @@ -429,9 +419,9 @@ class PpPDNSApplication(BaseMailApplication): """Try to get the version of the requested PowerDNS server.""" try: if not self.pdns: - raise PpPDNSAppError(_('The PDNS server object does not exists.')) + raise DpxPDNSAppError(_('The PDNS server object does not exists.')) if not self.pdns.initialized: - raise PpPDNSAppError(_('The PDNS server object is not initialized.')) + raise DpxPDNSAppError(_('The PDNS server object is not initialized.')) return self.pdns.get_api_server_version() @@ -441,7 +431,7 @@ class PpPDNSApplication(BaseMailApplication): msg = _('Got a {} during evaluating the PDNS server version from API:').format( e.__class__.__name__) msg += ' ' + str(e) - raise PpPDNSAppError(msg) + raise DpxPDNSAppError(msg) # ------------------------------------------------------------------------- def _build_url(self, path): @@ -458,9 +448,9 @@ class PpPDNSApplication(BaseMailApplication): def perform_request(self, path, method='GET', data=None, headers=None, may_simulate=False): """Perform the underlying API request.""" if not self.pdns: - raise PpPDNSAppError(_('The PDNS server object does not exists.')) + raise DpxPDNSAppError(_('The PDNS server object does not exists.')) if not self.pdns.initialized: - raise PpPDNSAppError(_('The PDNS server object is not initialized.')) + raise DpxPDNSAppError(_('The PDNS server object is not initialized.')) return self.pdns.perform_request( path, method=method, data=data, headers=headers, may_simulate=may_simulate) @@ -469,9 +459,9 @@ class PpPDNSApplication(BaseMailApplication): def get_api_zones(self): """Try to get the list of supported DNS zones from PDNS-Server.""" if not self.pdns: - raise PpPDNSAppError(_('The PDNS server object does not exists.')) + raise DpxPDNSAppError(_('The PDNS server object does not exists.')) if not self.pdns.initialized: - raise PpPDNSAppError(_('The PDNS server object is not initialized.')) + raise DpxPDNSAppError(_('The PDNS server object is not initialized.')) try: return self.pdns.get_api_zones() @@ -483,9 +473,9 @@ class PpPDNSApplication(BaseMailApplication): def get_api_zone(self, zone_name): """Try to get the given DNS zone from PDNS-Server.""" if not self.pdns: - raise PpPDNSAppError(_('The PDNS server object does not exists.')) + raise DpxPDNSAppError(_('The PDNS server object does not exists.')) if not self.pdns.initialized: - raise PpPDNSAppError(_('The PDNS server object is not initialized.')) + raise DpxPDNSAppError(_('The PDNS server object is not initialized.')) zone_unicode = zone_name json_response = None diff --git a/lib/pp_admintools/app/remove_ldap_user.py b/lib/pp_admintools/app/remove_ldap_user.py index 28223c0..56168ae 100644 --- a/lib/pp_admintools/app/remove_ldap_user.py +++ b/lib/pp_admintools/app/remove_ldap_user.py @@ -22,24 +22,17 @@ from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE # Own modules from .ldap import BaseLdapApplication -from .ldap import FatalLDAPError, LdapAppError from .. import pp +from ..errors import DpxFatalLdapError from ..xlate import XLATOR -__version__ = '0.6.3' +__version__ = '0.7.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class RemoveLdapUserError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class RemoveLdapUserApplication(BaseLdapApplication): """Application class for disabling or removing a user from LDAP.""" @@ -403,7 +396,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): if not self.deactivate: try: self.delete_entry(inst, dn) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing user {dn!r}: {e}').format( c=e.__class__.__name__, dn=dn, e=e) LOG.error(msg) @@ -443,7 +436,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): dn=dn, inst=connect_info.url)) try: self.modify_entry(inst, dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on deactivating user {dn!r}: {e}').format( c=e.__class__.__name__, dn=dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) @@ -470,7 +463,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): changes = {'member': [(MODIFY_DELETE, dn)], } try: self.modify_entry(inst, group_dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing user {dn!r} from group {g!r}: {e}').format( c=e.__class__.__name__, dn=dn, g=group_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) @@ -497,7 +490,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): changes = {'uniqueMember': [(MODIFY_DELETE, dn)], } try: self.modify_entry(inst, group_dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing user {dn!r} from group {g!r}: {e}').format( c=e.__class__.__name__, dn=dn, g=group_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) @@ -528,7 +521,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): changes = {'memberUid': [(MODIFY_DELETE, uid)], } try: self.modify_entry(inst, group_dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing user {dn!r} from group {g!r}: {e}').format( c=e.__class__.__name__, dn=uid, g=group_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) @@ -559,7 +552,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): changes = {'sudoUser': [(MODIFY_DELETE, uid)], } try: self.modify_entry(inst, group_dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing user {dn!r} from group {g!r}: {e}').format( c=e.__class__.__name__, dn=uid, g=group_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) @@ -675,7 +668,7 @@ class RemoveLdapUserApplication(BaseLdapApplication): try: self.modify_entry(inst, list_dn, changes) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on removing mail {mail!r} from {dn!r}: {e}').format( c=e.__class__.__name__, mail=address, dn=list_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) diff --git a/lib/pp_admintools/app/set_ldap_password.py b/lib/pp_admintools/app/set_ldap_password.py index f50b370..ddfb702 100644 --- a/lib/pp_admintools/app/set_ldap_password.py +++ b/lib/pp_admintools/app/set_ldap_password.py @@ -24,10 +24,9 @@ from ldap3.core.exceptions import LDAPBindError # Own modules from .ldap import BaseLdapApplication -from .ldap import FatalLDAPError -from .ldap import LdapAppError from .ldap import PasswordFileOptionAction from .. import pp +from ..errors import DpxFatalLdapError from ..handler.ldap_password import HAS_CRACKLIB from ..handler.ldap_password import LdapPasswordHandler from ..handler.ldap_password import WrongPwdSchemaError @@ -35,20 +34,13 @@ from ..handler.ldap_password import WrongRoundsError from ..handler.ldap_password import WrongSaltError from ..xlate import XLATOR -__version__ = '0.8.4' +__version__ = '0.9.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -class SetLdapPasswordError(LdapAppError): - """Special exception class for exceptions inside this module.""" - - pass - - # ============================================================================= class SetLdapPasswordApplication(BaseLdapApplication): """Application class for setting a LDAP password.""" @@ -512,7 +504,7 @@ class SetLdapPasswordApplication(BaseLdapApplication): try: self.modify_entry(inst, self.user_dn, changes, ldap=self.user_connection) - except FatalLDAPError as e: + except DpxFatalLdapError as e: msg = _('{c} on setting password of user {dn!r}: {e}').format( c=e.__class__.__name__, dn=self.user_dn, e=e) msg += '\n' + _('Changes:') + '\n' + pp(changes) diff --git a/lib/pp_admintools/config/__init__.py b/lib/pp_admintools/config/__init__.py index 2deb3b3..cb30e7a 100644 --- a/lib/pp_admintools/config/__init__.py +++ b/lib/pp_admintools/config/__init__.py @@ -24,11 +24,11 @@ from fb_tools.multi_config import DEFAULT_ENCODING from fb_tools.multi_config import MultiConfigError # Own modules -from ..errors import PpError +from ..errors import DpxError from ..xlate import XLATOR CONFIG_DIR = 'pixelpark' -__version__ = '0.2.3' +__version__ = '0.3.0' LOG = logging.getLogger(__name__) VALID_MAIL_METHODS = ('smtp', 'sendmail') DEFAULT_DOMAIN = 'pixelpark.com' @@ -39,7 +39,7 @@ _ = XLATOR.gettext # ============================================================================= -class PpConfigurationError(PpError, MultiConfigError): +class PpConfigurationError(DpxError, MultiConfigError): """Base error class for all exceptions happened during evaluation of configuration.""" pass diff --git a/lib/pp_admintools/errors.py b/lib/pp_admintools/errors.py index 7175caf..8b8b11a 100644 --- a/lib/pp_admintools/errors.py +++ b/lib/pp_admintools/errors.py @@ -10,22 +10,97 @@ from fb_tools.errors import FbAppError, FbError -__version__ = '0.6.1' +__version__ = '0.7.0' # ============================================================================= -class PpError(FbError): +class DpxError(FbError): """Base error class for all other self defined exceptions.""" pass # ============================================================================= -class PpAppError(FbAppError): +class DpxAppError(DpxError, FbAppError): """Base error class for all self defined exceptions in applications.""" pass +# ============================================================================= +class DpxAbortAppError(DpxAppError): + """Special exception class interrupting the application.""" + + pass + +# ============================================================================= +class DpxLdapError(DpxAppError): + """Base exception class for all exceptions in all LDAP using application classes.""" + + pass + + +# ============================================================================= +class DpxFatalLdapError(DpxLdapError): + """Fatal errors leading to interrupt the current application.""" + + pass + + +# ============================================================================= +class DpxLdapExecError(DpxFatalLdapError): + """Error class in case, a LDAP operation was not successful.""" + + pass + + +# ============================================================================= +class DpxWriteLdapItemError(DpxFatalLdapError): + """Error class in case, a LDAP item could not be written.""" + + pass + + +# ============================================================================= +class DpxDeleteLdapItemError(DpxFatalLdapError): + """Error class in case, a LDAP item could not be deleted.""" + + pass + + +# ============================================================================= +class DpxLdapParseError(DpxFatalLdapError): + """Error on parsing LDAP stuff.""" + + pass + + +# ============================================================================= +class DpxMailAppError(DpxAppError): + """Base exception class for all exceptions in all mail sending application classes.""" + + pass + + +# ============================================================================= +class DpxPDNSAppError(DpxMailAppError): + """Base error class for PowerDNS handling modules.""" + + pass + + +# ============================================================================= +class DpxDeployZonesError(DpxPDNSAppError): + """Special exception class to use in this module app.dns_deploy_zones.""" + + pass + +# ============================================================================= +class CheckLdapDnAttributesError(DpxLdapError): + """Special exception class for exceptions in module app.check_ldap_dn_attributes.""" + + pass + + # ============================================================================= if __name__ == '__main__':