[ reiser @ 17.02.2017. 14:44 ] @
Imam prosti Twistd-Klein server, sa ukljucenim globalnim HTTP basic authom: Code: from klein import Klein import attr from zope.interface import implementer from twisted.cred.portal import IRealm from twisted.internet.defer import succeed from twisted.cred.portal import Portal from twisted.cred.checkers import FilePasswordDB from twisted.web.resource import IResource from twisted.web.guard import HTTPAuthSessionWrapper, BasicCredentialFactory app = Klein() # health check @app.route('/health', methods=['GET']) def health_check(request): return '' # dataset query API @app.route('/query/<path:expression>', methods=['GET']) def query(request, expression): response = evaluate_expression(expression) return response @implementer(IRealm) @attr.s class HTTPAuthRealm(object): resource = attr.ib() def requestAvatar(self, avatarId, mind, *interfaces): return succeed((IResource, self.resource, lambda: None)) def resource(): realm = HTTPAuthRealm(resource=app.resource()) portal = Portal(realm, [FilePasswordDB('./configs/server-auth.db')]) credential_factory = BasicCredentialFactory('Authentication required') return HTTPAuthSessionWrapper(portal, [credential_factory]) Jel neko zna kako da iskljucim auth za npr /heath API, a da za ostale auth ostane ukljucen? Citam dokumente ali mi nikako ne ide u glavu: https://twistedmatrix.com/documents/14.0.1/core/howto/cred.html [Ovu poruku je menjao reiser dana 17.02.2017. u 16:05 GMT+1] |