1
0
Fork 0

Start work on XML-RPC functionality

* provide an XMLRPC server start script (bin/gvaserver) (addresses #5)
 * encapsulate XMLRPC visible code in gnuviechadmin.xmlrpc.XMLRPCFacade
 * start implementation of authkit compatible Users implementation
   gnuviechadmin.xmlrpc.users.GVAUsers (addresses #17)


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@256 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2008-06-06 16:06:05 +00:00
parent 6d33a0e147
commit 7c4d25da43
4 changed files with 204 additions and 0 deletions

58
bin/gvaserver Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
import sys, os, logging.config
from gnuviechadmin.util.passwordutils import md5_crypt_password
logcfgs = ('gnuviechadmin/logging.cfg', '/etc/gnuviechadmin/logging.cfg',
os.path.expanduser('~/.gva-logging.cfg'))
for cfg in [x for x in logcfgs if os.path.exists(x)]:
logging.config.fileConfig(cfg)
def usage():
print """%s <host> <port>
where host and port specify the connection parameters. Host is the
hostname or ip address to listen on.
""" % sys.argv[0]
def main():
if (sys.argv.__len__() < 3):
usage()
sys.exit()
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer(("localhost", 9999), allow_none=True)
server.register_introspection_functions()
from gnuviechadmin.xmlrpc import XMLRPCFacade
from gnuviechadmin.xmlrpc.users import \
ClientUserProvider, MailuserUserProvider, SysuserUserProvider
server.register_instance(XMLRPCFacade('data',
[ClientUserProvider,
MailuserUserProvider,
SysuserUserProvider],
md5_crypt_password))
server.serve_forever()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,31 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
"""This file defines a facade for exporting gnuviechadmin
functionality via XMLRPC."""
from gnuviechadmin.xmlrpc.users import GVAUsers
class XMLRPCFacade(GVAUsers):
"""This class provides access to selected gnuviechadmin
functionality for use via XMLRPC."""
pass

View File

@ -0,0 +1,28 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
"""This is the gnuviechadmin.xmlrpc package.
This package provides modules for the XMLRPC interface of the
gnuviechadmin server administration suite."""
from XMLRPCFacade import XMLRPCFacade

View File

@ -0,0 +1,87 @@
# -*- python -*-
# -*- coding: utf-8 -*-
from authkit.users import Users, AuthKitNoSuchUserError
import logging
log = logging.getLogger(__name__)
class UserProvider(Users):
def _get_user(self, username, password, role):
return {
'username' : username,
'group' : None,
'password' : password,
'roles' : [role]
}
class ClientUserProvider(UserProvider):
def user(self, username):
print 'checking %s' % username
if username == 'dummy':
return self._get_user(username, username, 'client')
return AuthKitNoSuchUserError()
def list_roles(self):
return ['client']
class MailuserUserProvider(UserProvider):
def user(self, username):
raise AuthKitNoSuchUserError()
def list_roles(self):
return ['mailuser']
class SysuserUserProvider(UserProvider):
def user(self, username):
raise AuthKitNoSuchUserError()
def list_roles(self):
return ['sysuser']
class GVAUsers(Users):
def __init__(self, data, userproviders = [], encrypt = None):
"""Initialize the GVAXMLRPCUsers instance."""
Users.__init__(self, data, encrypt)
self.userproviders = [prov(self.data) for prov in userproviders]
def list_roles(self):
"""Returns a lowercase list of all role names ordered
alphabetically."""
roles = []
for prov in self.userproviders:
for role in prov.list_roles():
if not role in roles:
roles.append(role)
roles.sort()
return roles
def role_exists(self, role):
"""Returns ``True`` if the role exists, ``False``
otherwise. Roles are case insensitive."""
for prov in self.userproviders:
if prov.role_exists(role):
return True
return False
def user(self, username):
"""Returns a dictionary in the following format:
.. code-block :: Python
{
'username': username,
'group': group,
'password': password,
'roles': [role1,role2,role3... etc]
}
The role names are ordered alphabetically
Raises an exception if the user doesn't exist."""
for prov in self.userproviders:
try:
return prov.user(username)
except Exception, e:
print e
log.debug("Backend %s didn't find user %s" % (backend,
username))
raise AuthKitNoSuchUserError()