mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Finished small tweaks to get new ipaserver.xmlrpc() mod_python handler working
This commit is contained in:
committed by
Rob Crittenden
parent
c2b0c80140
commit
3274577cd6
@@ -433,7 +433,6 @@ class Env(object):
|
||||
self.script = path.abspath(sys.argv[0])
|
||||
self.bin = path.dirname(self.script)
|
||||
self.home = os.environ.get('HOME', None)
|
||||
self.etc = path.join('/', 'etc', 'ipa')
|
||||
self.dot_ipa = self._join('home', '.ipa')
|
||||
self._merge(**overrides)
|
||||
if 'in_tree' not in self:
|
||||
|
@@ -137,12 +137,14 @@ def xml_dumps(params, methodname=None, methodresponse=False, encoding='UTF-8'):
|
||||
allow_none=True,
|
||||
)
|
||||
|
||||
|
||||
def decode_fault(e, encoding='UTF-8'):
|
||||
assert isinstance(e, Fault)
|
||||
if type(e.faultString) is str:
|
||||
return Fault(e.faultCode, e.faultString.decode(encoding))
|
||||
return e
|
||||
|
||||
|
||||
def xml_loads(data, encoding='UTF-8'):
|
||||
"""
|
||||
Decode the XML-RPC packet in ``data``, transparently unwrapping its params.
|
||||
|
@@ -24,27 +24,51 @@ Package containing server backend.
|
||||
from xmlrpclib import dumps, Fault
|
||||
from ipalib import api
|
||||
|
||||
|
||||
# This is a simple way to ensure that ipalib.api is only initialized
|
||||
# when ipaserver is imported from within the Apache process:
|
||||
try:
|
||||
from mod_python import apache
|
||||
api.bootstrap(context='server', log=None, debug=True)
|
||||
api.bootstrap(context='server', debug=True, log=None)
|
||||
api.finalize()
|
||||
api.log.info('*** PROCESS START ***')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def xmlrpc(req):
|
||||
"""
|
||||
mod_python handler for XML-RPC requests.
|
||||
"""
|
||||
if req.method != 'POST':
|
||||
req.allow_methods(['POST'], 1)
|
||||
return apache.HTTP_METHOD_NOT_ALLOWED
|
||||
|
||||
if apache.mpm_query(apache.AP_MPMQ_IS_THREADED):
|
||||
response = dumps(
|
||||
Fault(3, 'Apache must use the forked model'), methodresponse=True
|
||||
Fault(3, 'Apache must use the forked model'),
|
||||
methodresponse=True,
|
||||
)
|
||||
else:
|
||||
response = api.Backend.xmlserver.marshaled_dispatch(req.read(), None)
|
||||
req.add_common_vars()
|
||||
response = api.Backend.xmlserver.marshaled_dispatch(
|
||||
req.read(),
|
||||
req.subprocess_env.get('KRB5CCNAME'),
|
||||
)
|
||||
|
||||
req.content_type = 'text/xml'
|
||||
req.set_content_length(len(response))
|
||||
req.write(response)
|
||||
return apache.OK
|
||||
|
||||
|
||||
def jsonrpc(req):
|
||||
"""
|
||||
mod_python handler for JSON-RPC requests (place holder).
|
||||
"""
|
||||
|
||||
|
||||
def webui(req):
|
||||
"""
|
||||
mod_python handler for web-UI requests (place holder).
|
||||
"""
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
"""
|
||||
Production XML-RPC server using mod_python.
|
||||
|
||||
This module is depreciated. See the `ipaserver.xmlrpc()` function.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
@@ -55,20 +55,20 @@ class xmlserver(Executioner):
|
||||
super(xmlserver, self).finalize()
|
||||
|
||||
def listMethods(self, *params):
|
||||
return tuple(name.encode('UTF-8') for name in self.Command)
|
||||
return tuple(name.decode('UTF-8') for name in self.Command)
|
||||
|
||||
def methodSignature(self, *params):
|
||||
return 'methodSignature not supported'
|
||||
return u'methodSignature not implemented'
|
||||
|
||||
def methodHelp(self, *params):
|
||||
return 'methodHelp not supported'
|
||||
return u'methodHelp not implemented'
|
||||
|
||||
def marshaled_dispatch(self, data, ccache):
|
||||
"""
|
||||
Execute the XML-RPC request in contained in ``data``.
|
||||
Execute the XML-RPC request contained in ``data``.
|
||||
"""
|
||||
try:
|
||||
#self.create_context(ccache=ccache)
|
||||
self.create_context(ccache=ccache)
|
||||
(params, name) = xml_loads(data)
|
||||
if name in self.__system:
|
||||
response = (self.__system[name](*params),)
|
||||
|
@@ -29,18 +29,6 @@ import krbV
|
||||
from ipalib import api
|
||||
|
||||
|
||||
class Instance(object):
|
||||
"""
|
||||
Just used for `Instance._listMethods()`.
|
||||
"""
|
||||
|
||||
def _listMethods(self):
|
||||
"""
|
||||
Provides list of names for ``system.listMethods``.
|
||||
"""
|
||||
return list(api.Command)
|
||||
|
||||
|
||||
class Server(SimpleXMLRPCServer):
|
||||
"""
|
||||
Custom server implementing `Server._marshaled_dispatch()`.
|
||||
@@ -79,8 +67,7 @@ server = Server(('', api.env.lite_xmlrpc_port), **kw)
|
||||
|
||||
api.log.info('Logging to file %r', api.env.log)
|
||||
api.log.info('Listening on port %d', api.env.lite_xmlrpc_port)
|
||||
server.register_introspection_functions()
|
||||
server.register_instance(Instance())
|
||||
|
||||
|
||||
try:
|
||||
server.serve_forever()
|
||||
|
Reference in New Issue
Block a user