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 a function,
`set_flask_metadata`, and a class, `APIFlask`.

The function is designed to add the metadata route to an existing Flask
app, and the class is designed to return a subclass of
`flask.Flask` which has the metadata route already baked into it.

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

The class has a second method, `return_metadata`, which returns the
JSON representation of the class's metadata.

## 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.0.8.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

sqre_apikit-0.0.8-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sqre-apikit-0.0.8.tar.gz.

File metadata

  • Download URL: sqre-apikit-0.0.8.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sqre-apikit-0.0.8.tar.gz
Algorithm Hash digest
SHA256 3948ab7ac5034e63c998ec53f7ca4d7a28bc122291292991e1519a7bd8c3e7e9
MD5 0d8ff5a15a15ae36eda09816e58b47eb
BLAKE2b-256 73cef8cbbb9ad1d21d2bfe4770022bd63a345e6ada5c8edd2dd209aa92b8fd6f

See more details on using hashes here.

File details

Details for the file sqre_apikit-0.0.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sqre_apikit-0.0.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 73f4095f7e801748fa091c923a12b111acb48942b2e77d0efe8c0d10e354ec01
MD5 9b204cb6e7f03e05c9ebca34dbd0cb66
BLAKE2b-256 ff4db36ea337d14b7a877544e16eaf3482f1624b3811283b20d69b7062de07b5

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