Package: falcon-epdb
AFalcon middlewarethat wraps the excellentepdbtool and allows one to connect to a running Falcon app and use interactive debugging to step through the code.Better documentation can be found atreadthedocs.Source code can be found on GitHub atjcwilson/falcon-epdb.InstallationIf you are only planning on debugging in a development environment where access to your service is restricted to you or trusted partners, you may find theBase64backend sufficient to your purposes. You can just install the library as you would any Python library.requirements.txtfalcon-epdbpippipinstallfalcon-epdbpoetrypoetryaddfalcon-epdbHowever, if you need a little more security, you can use one of the other authenticated backends (Fernet,JWT). Choose the one that best fits your use case and install it as a Pythonextra.requirements.txtfalcon-epdb[fernet]pippipinstallfalcon-epdb[fernet,jwt]poetrypoetryaddfalcon-epdb[jwt]UsageThis library adds a middleware to your Falcon API stack, and as such will run for all requests, save those excluded byexempt_methodsprovided to theEPDBServerconstructor. If it detects a well-formed (and possibly authenticated)X-EPDBheader on the request it will start theepdbserver on the configured port and block until it establishes a connection from anepdbclient, at which point processing continues but under the control of the remote debugging session.Subsequent requests with an acceptable header will reuse the client connection and automatically drop into the remote debugging session again.Configuring the middlewareTheEPDBServe<falcon_epdb.EPDBServe>middleware accepts a handful of parameters. The most important are thebackendandserve_optionsparameters. Thebackenddetermines how a request is examined for the “secret knock” to start the remote debugging server. The included implementations assume a well-formedX-EPDBheader, but nothing precludes you from sub-classingEPDBBackend<falcon_epdb.EPDBBackend>and implementing your own.Theserve_optionsare options that are passed through to theepdb.serve()call. SeeBackendsfor details on how to add this middleware to your API.Constructing theX-EPDBheaderThe content of the header is as follows:{"epdb":{}}Depending on the backend in use, one should encode this content into the appropriate header-safe value. Then append this value to the name of the backend.X-EPDB: Base64 eyJlcGRiIjoge319Connecting the clientExample code for connecting to the waiting port:importepdbedpb.connect(host=<host>,port=9000)BackendsBase64Server side configurationepdb_middleware=EPDBServe(backend=Base64Backend(),serve_options={'port':9000})api=falcon.API(middleware=[epdb_middleware])Crafting an appropriate headerimportbase64importjsonheader_content=base64.b64encode(json.dumps({'epdb':{}}).encode()).decode()header_value='Base64{}'.format(header_content)FernetServer side configurationfernet_key=Fernet.generate_key()# The shared keyepdb_middleware=EPDBServe(backend=FernetBackend(key=fernet_key),serve_options={'port':9000})api=falcon.API(middleware=[epdb_middleware])Crafting an appropriate headerimportjsonfromcryptography.fernetimportFernetf=Fernet(<fernet_key>)# Key configured on the serverheader_content=f.encrypt(json.dumps({'epdb':{}}).encode()).decode()header_value='Fernet{}'.format(header_content)JWTServer side configurationjwt_key=uuid.uuid4().hex# The shared keyepdb_middleware=EPDBServe(backend=JWTBackend(key=jwt_key),serve_options={'port':9000})api=falcon.API(middleware=[epdb_middleware])Crafting an appropriate headerimportjwtheader_content=jwt.encode({'epdb':{}},<jwt_key>,algorithm='HS256').decode()header_value='JWT{}'.format(header_content)TroubleshootingYou must be sure to allow access to the configured port on your host. Be sure to check your security groups and firewall rules.Configure your web app to only run one worker process. If you have multiple workers, only the first one will be able to serve on the configured port. If this is not possible you will have to take steps to ensure that all requests that wish to use the remote debugging port are routed to the same worker. This will depend heavily on your HTTP stack and is beyond the scope of this documentation.Be sure to up your request timeout limit to something on the order of minutes so that the HTTP server doesn’t close your request connection or kill your worker process while you’re debugging.You may need to provide theHTTP-prefix on yourX-EPDBheader for it to be handled correctly. So instead of sendingX-EPDB, you would sendHTTP-X-EPDB.