How to use talisman with flask restful Api

121 Views Asked by At

I have a flask-based backend service and plan to migrate to https to improve safety.

Here is the structure of the service from front end to backend.

ui_server.py(front end)

def main():
  server = ThreadingHTTPServer(('0.0.0.0', 8000), CacheHandler)
  os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/ui")
  sys.stdout.flush()
  server.serve_forever()

if __name__ == "__main__":
  sys.exit(main())

/ui directory contains html and js classes.

Backend service.py

  from flask import Flask, request
  from flask_restful import Api
  from flask_cors import CORS

  import argparse
  import apis

  def create_app(config):
    app = Flask(__name__)
    api = Api(app)
    api.add_resource(apis.Envs, '/envs')

  def init_app(app, app_config):
    app.config.update(app_config)
    CORS(app)

    db.init_app(app)
    migrate.init_app(app, db)

 app = create_app(conf.config)
 init_app(app, conf.config["app_config"])

 if __name__ == '__main__':
   app.run(**run_config)

api.py

class Envs(Resource):
  """Request methods for multiple environments service data."""

  def __init__(self):
    self.list_env_settings = get_service_config('list_env_settings', False)

  def get(self):
    """Get data from all environments."""
    <business logic>

My question is how I can add talisman with regard to the use of add_resource as the routing logic?

I saw an example:

 @app.route('/', methods=['GET', 'POST'])
 def index():
    message = request.form.get('message', None)
    return render_template('index.html', message=message)

but I don't think it fits my use case with add_resource.

0

There are 0 best solutions below