Package: unikold.connector
unikold.connectorPlone-Addon for making cachable queries to API endpoints supporting following protocols:Plain XMLSOAP (using a fast and modern Python SOAP client:zeep)LDAPCan be easily extended.FeaturesSOAP requests are cached (lifetime can be specified)Live-View to test your SOAP requests:test_soap:https://raw.githubusercontent.com/mbarde/unikold.connector/master/docs/connector.gifSpecific queries (LSFQuery,LSFSearchQuery) to easily connect to products ofHIS eGvia their SOAP API (dbinterface)Plain XML requests (also supports basic authentication)LDAP search queriesInstallationAddunikold.connectorto your buildoutInstall viaprefs_install_products_formCreate aSOAPQueriesFolderFor security reasonsSOAPQueriesFolderare not globally   addable by default - to be able to add it you need to allow adding this content type at the desired location temporarilyIn this folder all queries will be storedMaybe you also want to exclude it from navigationSet path to this folder in@@unikold-connector-controlpanelIf you want to make use of LSF-Queries you also have to define settings in@@unikold-connector-lsf-controlpanelIf you want to make use of LDAP-Queries you also have to define settings in@@unikold-connector-ldap-controlpanelExamplesSoap RequestsAfter installing this addon you can make SOAP requests like this:fromunikold.connector.soapimportSOAPConnectorsoapConnector=SOAPConnector('http://webservices.daehosting.com/services/isbnservice.wso?WSDL',# URL to WSDL file'IsValidISBN13',# name of the method'9783492700764',# method parameter24# lifetime of this request in hours)response=soapConnector.get()If the request already exists and its lifetime did not expiresoapConnectorsimply returns the stored response.
If the request exists but is outdated it will be updated before returning the response.
If the request does not yet exist, a new object will be created. Its path will be{SOAP-Queries-Folder}.{WSDL-URL}.{Methodname}.{Parameter}(where{SOAP-Queries-Folder}has to be specified in the controlpanel of this addon - otherwise a folder will be created at your sites' root).To get the corresponding query object:queryObject=soapConnector.getQuery()Above example without this addon would look like this (remember no persistent objects, no caching):fromzeepimportClienturl='http://webservices.daehosting.com/services/isbnservice.wso?WSDL'client=Client(url)response=client.service.IsValidISBN13('9783492700764')XML RequestsMake a XML request (which will be cached 24 hours):fromunikold.connector.xmlimportXMLConnectorxmlConnector=XMLConnector('https://www.w3schools.com/xml/note.xml',24,queryParams=['prename=Peter','surname=Lustig'],# query parameters (optional)basicAuthCredentials=('username','password')# credentials for basic authentication (optional))xmlData=xmlConnector.get()# xmlData is a lxml.etree object:print(etree.tostring(xmlData))LDAP Requestsfromunikold.connector.ldapimportLDAPSearchConnectorsearchFilter='mail=mbarde@uni-koblenz.de'ldapConnector=LDAPSearchConnector(searchFilter=searchFilter)resultList=ldapConnector.get()This example only works if you set the LDAP default options in@@unikold-connector-ldap-controlpanel.If you did not set defaults or want to use different values for these options you can also set them explicitly for each query:fromunikold.connector.ldapimportLDAPSearchConnectorsearchFilter='mail=mbarde@uni-koblenz.de'ldapConnector=LDAPSearchConnector(address='ldap://[...]',port=389,baseDN='dc=[...]',searchFilter=searchFilter,username='uid=[...]',password='****',queryLifetimeInHours=24,excludeFromAutoUpdate=True)resultList=ldapConnector.get()Automate updating of queriesUse Zope clock server to callunikold.connector.update(user must have permissioncmf.ManagePortal):[client2]
zope-conf-additional =
    <clock-server>
       method /SiteName/unikold.connector.update
       period 2880
       user username
       password *****
       host hostname.com
    </clock-server>Parameters explained in detail here:https://docs.plone.org/develop/plone/misc/asyncronoustasks.html#clock-serverUpdating big amounts of queries can take a while so its advisable to run the task on a dedicated client.To create a query which should be excluded from automatic updates you have to passexcludeFromAutoUpdate=Trueto the corresponding connector.Automate cleanup of stale queriesAnalogous to the usage ofunikold.connector.updateyou can use the endpointunikold.connector.cleanupto remove stale query objects. After how many days a query is considered as stale can be specified at@@unikold-connector-controlpanel.Error loggingBy default errors in requests generated by this addon are handled quietly to ensure full functionality even when requested endpoints are not reachable or broken.
Nevertheless you can addcollective.sentryto your buildout in order to log those errors.TestingBefore you can run the tests you need to create a file calledconfig.pyin thetestsfolder,
containing following constants:# -*- coding: utf-8 -*-soap_test_url=u'http://webservices.daehosting.com/services/isbnservice.wso?WSDL'soap_test_method=u'IsValidISBN13'soap_test_method_parameter=u'9783492700764'xml_test_url=u'https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Rick_and_Morty'# config data needed for XML auth testsxml_basic_auth_url=u''xml_basic_auth_username=u''xml_basic_auth_password=u''# config data needed for LSF testslsf_wsdl_url=u'[...]/qisserver/services/dbinterface?WSDL'lsf_test_object_type=u''# LSF object typelsf_test_conditions=[]lsf_auth_test_object_type=u''lsf_auth_test_conditions=[]lsf_wsdl_search_url=u'[...]/qisserver/services/soapsearch?WSDL'lsf_search_test_method_parameter=u''lsf_auth_username=u''lsf_auth_password=u''# config data needed for LDAP testsldap_server_address=u'ldap://[...]'ldap_server_port=389ldap_server_base_dn=u''ldap_search_username=u''ldap_search_password=u''bin/testbin/code-analysisTypeError: string indices must be integersMake sure this fix has been applied to zeep:https://github.com/mvantellingen/python-zeep/pull/657/commits/a2b7ec0296bcb0ac47a5d15669dcb769447820ebLicenseThe project is licensed under the GPLv2.ContributorsMatthias Barde,mbarde@uni-koblenz.deChangelog2.0Dropped Python 2.7 support1.0a1 (unreleased)Initial release.
[mbarde]