Skip to main content

LSST Data Management SQuaRE microservice tools

Project description

[![Build Status](https://travis-ci.org/lsst-sqre/sqre-apikit.svg?branch=master)](https://travis-ci.org/lsst-sqre/sqre-apikit)

# sqre-apikit

LSST DM SQuaRE microservice convenience tools.

## Rationale

In order to create a microservice hosted behind https://api.lsst.codes,
a service will need to provide a route on `/metadata` and
`/v{{api_version}}/metadata`. That route must serve appropriate
metadata about the service.

### Metadata format

The metadata served must be a JSON object, and must contain the
following fields:

`name`: `str`

`version`: `str`

`repository`: `str`

`description`: `str`

`api_version`: `str`

`auth`: `str`

The fields `name`, `version`, `api_version`, and `description` are
arbitrary, although semantic versioning is strongly encouraged, and the
API version should reflect the version of the `api.lsst.codes` API in
use (currently `1.0`, documentation pending).

Auth must be one of `none`, `basic`, or `bitly-proxy`. It represents
the way in which the microservice will authenticate to GitHub: either it
doesn't need to, it uses HTTP Basic Auth with a username and service
token, or it uses the Bitly OAuth2 Proxy with a username, a password,
and the proxy starting-OAuth2 endpoint.

## Provided Functionality

`sqre-apikit` provides one module, `apikit`, which contains three
functions, `set_flask_metadata`, `add_metadata_route`, and
`return_metadata`, and a class, `APIFlask`.

The `set_flask_metadata` sets metadata on an existing Flask app and adds
metadata routes. `add_metadata_route` is designed to add routing for
each component in the route list to an existing Flask app.
`return_metadata` returns the JSON representation of the metadata for
the service.

The `APIFlask` class creates an instance of a subclass of `flask.Flask`
which has the metadata added and the route(s) already baked into it.

The class comes with a method, `add_route_prefix`, which adds the
metadata route underneath another route. This is useful, for instance,
if wiring the microservice up through Kubernetes and its Ingress
resources, which provide routing but not rewriting.

## Installation

`sqre-apikit` runs on Python 2.7 or 3.5. You can install it with

```bash
pip install sqre-apikit
```

This will also install the dependency `Flask`.

## Example usage

### `apikit.set_flask_metadata()`

```python
import apikit
import flask

app = flask.Flask("Hello")
apikit.set_flask_metadata(app,
version="0.0.1",
repository="http://example.repo",
description="Hello World App")
```

### `apikit.APIFlask`

```python
import apikit

app = apikit.APIFlask(name="Hello",
version="0.0.1",
repository="http://example.repo",
description="Hello World App")
```

## Development

To develop apikit, create a Python virtual environment, and

```bash
git clone https://github.com/lsst-sqre/sqre-apikit.git
cd sqre-apikit
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt
python setup.py develop
```
Tests can be run with [pytest](http://pytest.org/latest/):

```bash
py.test tests
```


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqre-apikit-0.1.2b1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distributions

sqre_apikit-0.1.2b1-py3.5.egg (15.8 kB view details)

Uploaded Source

sqre_apikit-0.1.2b1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file sqre-apikit-0.1.2b1.tar.gz.

File metadata

File hashes

Hashes for sqre-apikit-0.1.2b1.tar.gz
Algorithm Hash digest
SHA256 15240ff23f3daab064d0b2f686f5fb1b64ae9b1cd046e44c41e8b41b2bf10a6c
MD5 480ca28ee69d869dfa2cb78042cc12a7
BLAKE2b-256 7c41967ff6293471ac9444ee4c616e7c446bce14588764a924e0413d6be5a995

See more details on using hashes here.

File details

Details for the file sqre_apikit-0.1.2b1-py3.5.egg.

File metadata

File hashes

Hashes for sqre_apikit-0.1.2b1-py3.5.egg
Algorithm Hash digest
SHA256 8bddad4a2aac21227db1fa109e28778394926b3428a7182ef1a94c44833da1f9
MD5 3ac69f982354fb17311242243bea72f7
BLAKE2b-256 4fdfe7d60538f4833dd89a1e1c850781314dc1a22ab1486ce57192da7b9e3439

See more details on using hashes here.

File details

Details for the file sqre_apikit-0.1.2b1-py3-none-any.whl.

File metadata

File hashes

Hashes for sqre_apikit-0.1.2b1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb9737c619b678cdb2e677956cbe74780845d9ac20a47df6cf8c41271f7189d1
MD5 d13c444d26dd045b004d163a9eb1ef69
BLAKE2b-256 a422921f4841b671ad8e0e7be89045de96b06d9275495ef13acbfa56d3841273

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page