From b54d005919f84108500bd9818b990972d2d9a749 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Fri, 4 May 2018 12:43:21 +0200 Subject: [PATCH] [ADD]Initial commit with radicale odoo auth plugin --- radicale_odoo_auth/__init__.py | 51 +++++++++++++++++++++++++++++++ radicale_odoo_storage/__init__.py | 25 +++++++++++++++ setup.py | 6 ++++ 3 files changed, 82 insertions(+) create mode 100644 radicale_odoo_auth/__init__.py create mode 100644 radicale_odoo_storage/__init__.py create mode 100644 setup.py diff --git a/radicale_odoo_auth/__init__.py b/radicale_odoo_auth/__init__.py new file mode 100644 index 0000000..3e46f7d --- /dev/null +++ b/radicale_odoo_auth/__init__.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" Odoo Radicale Authentication Plugin """ + +from configparser import Error +from odoorpc import ODOO +from odoorpc.error import RPCError +from radicale.auth import BaseAuth + + +class Auth(BaseAuth): + """ BaseAuth implementation for Odoo Radicale Authentication """ + + def is_authenticated(self, user, password): + """ Is authenticated main function """ + host = self.configuration.get('auth', 'host', fallback='127.0.0.1') + port = self.configuration.get('auth', 'port', fallback=8069) + 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.logger.info('Login successfull for {} on database {}'.format(user, database)) + return True + except RPCError as rpcerr: + self.logger.error('Login problem for {} on database {}'.format(user, database)) + self.logger.error(rpcerr) + raise RuntimeError(rpcerr) + return False diff --git a/radicale_odoo_storage/__init__.py b/radicale_odoo_storage/__init__.py new file mode 100644 index 0000000..9460b13 --- /dev/null +++ b/radicale_odoo_storage/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" Odoo Radicale Storage Plugin """ + +from radicale.storage import BaseCollection + + +class Collection(BaseCollection): + """ BaseCollection implementation for Odoo Radicale Storage """ + pass diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..897440d --- /dev/null +++ b/setup.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from distutils.core import setup + +setup(name="radicale_odoo_auth", packages=["radicale_odoo_auth"]) +setup(name="radicale_odoo_storage", packages=["radicale_odoo_storage"])