Skip to content

mbonakda/adsabs-webservices-blueprint

 
 

Repository files navigation

Build Status

adsabs-webservices-blueprint

A sample Flask application for backend adsabs (micro) web services. To integrate into the ADS-API, an application must expose a /resources route that advertises that application's resources, scopes, and rate limits.

GET on /resources should return JSON that looks like:

{
    "/route": {
        "scopes": ["red","green"],
        "rate_limit": [1000,86400],
        "description": "docstring for this route",
        "methods": ["HEAD","OPTIONS","GET"],
    }
}

To facilitate that, one can define that route explitictly/manually or by using flask-discoverer. This blueprint is pre-configured to do just this.

development

For convenience, a Vagrantfile and puppet manifest are available to facilitate development within a virtual machine. To use the vagrant VM defined here you will need to install Vagrant and VirtualBox.

To load and enter the VM: vagrant up && vagrant ssh

Alternatively, you can follow these simple steps:

  • virtualenv virtualenv
  • source virtualenv/bin/activate
  • pip install -r dev-requirements.txt
  • pip install -r requirements.txt
  • python cors.py

Note: cors.py will start the microservice in a simple HTTP webserver with approparite CORS headers (so that you can access localhost:5000/.... from a browser). Normally, you would run python wsgi.py or use a faster gunicorn to start wsgi.py.

database migrations (only relevant when a database is managed by the application)

To make changes to the database schema associated with the application:

  • Update the database model in models.py
  • execute: python manage.py db migrate
  • if necessary, make manual changes in the migration scripts generated in migrations/versions (see notes below)
  • execute: python manage.py db upgrade

Notes:

  1. Installation of Flask-Migrate created the directory migrations. If the application uses SQLALCHEMY_DATABASE_URI as database URI, you can ignore the following remark. If the application uses SQLALCHEMY_BINDS to define the database URI, the script migrations/env.py needs a manual update: replace current_app.config.get('SQLALCHEMY_DATABASE_URI') by current_app.config.get('SQLALCHEMY_BINDS')['sample']
  2. After running the migrate step, some manual editing of the migration script will be necessary because of the definition of one of the table columns: the column Column(postgresql.ARRAY(String)) gets translated into sa.Column('bar', postgresql.ARRAY(String()), nullable=True) in the migration, which will throw an exception if left unedited. The entry String() has to be changed into sa.String(). This is true in general for all types used in ARRAY.

About

Sample Flask application that is easy to integerate in ADS's SOA

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 91.3%
  • Puppet 6.5%
  • Mako 2.2%