diff --git a/radicale_odoo_auth/__init__.py b/radicale_odoo_auth/__init__.py index 3e46f7d..3fd3de3 100644 --- a/radicale_odoo_auth/__init__.py +++ b/radicale_odoo_auth/__init__.py @@ -26,22 +26,25 @@ from radicale.auth import BaseAuth class Auth(BaseAuth): """ BaseAuth implementation for Odoo Radicale Authentication """ - def is_authenticated(self, user, password): - """ Is authenticated main function """ + def __init__(self, configuration, logger): + super(Auth, self).__init__(configuration, logger) host = self.configuration.get('auth', 'host', fallback='127.0.0.1') port = self.configuration.get('auth', 'port', fallback=8069) + try: + self.odoo = ODOO(host, port=port) + except RPCError as rpcerr: + self.logger.error(rpcerr) + raise RuntimeError(rpcerr) + + def is_authenticated(self, user, password): + """ Is authenticated main function """ if not self.configuration.has_option('auth', 'database'): raise RuntimeError('Database is needed for Odoo Authentication') database = self.configuration.get('auth', 'database') if not user or not password: return False try: - odoo = ODOO(host, port=port) - except RPCError as rpcerr: - self.logger.error(rpcerr) - raise RuntimeError(rpcerr) - try: - odoo.login(database, user, password) + self.odoo.login(database, user, password) self.logger.info('Login successfull for {} on database {}'.format(user, database)) return True except RPCError as rpcerr: