[ADD]Initial commit with radicale odoo auth plugin

This commit is contained in:
Fabien BOURGEOIS 2018-05-04 12:43:21 +02:00
commit b54d005919
3 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
""" 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

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
""" Odoo Radicale Storage Plugin """
from radicale.storage import BaseCollection
class Collection(BaseCollection):
""" BaseCollection implementation for Odoo Radicale Storage """
pass

6
setup.py Normal file
View File

@ -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"])