Webserver

Our webserver is implemented with Quart, an ASGI Flask-like web framework. We use voluptuous for data validation.

See:

The package is laid out as follows:

webserver/
├── app.py          # Contains the app factory.
├── util.py         # Utility functions for Quart routes.
├── validators.py   # Custom voluptuous validators.
└── routes/         # The routes registered on the server.

The endpoints are documented at Server API.

Utility Functions

This module contains various helper functions, endpoint decorators, and utilities for the web application package.

Functions:

check_auth([csrf])

Ensure that the wrapped function can only be accessed by a request that passes a valid APIKey in the header.

validate_data(schema)

This decorates a quart endpoint.

src.webserver.util.check_auth(csrf=False)

Ensure that the wrapped function can only be accessed by a request that passes a valid APIKey in the header. If the API Key is not present or incorrect, a HTTPException with a status code of 401 will be raised.

Parameters

func (Callable) – The function to be decorated.

Returns

The decorated function.

Return type

Callable

Raises

HTTPException

src.webserver.util.validate_data(schema)

This decorates a quart endpoint. Given a voluptuous schema, this returns a decorator that parses the argument/form data, depending on the request method, and validates it against the schema. If the schema is valid, then the function will be called, expanding the schema keys as keyword arguments. If the schema is invalid, a HTTPException with a status code of 400 will be raised.

Parameters

schema (voluptuous.Schema) – The schema to validate against.

Returns

A decorator that will validate against the provided schema.

Return type

Callable

Raises

HTTPException

Custom Validators

Functions:

StringBool(value)

Given a string “true” or “false”, return the associated boolean.

src.webserver.validators.StringBool(value)

Given a string “true” or “false”, return the associated boolean.

Parameters

value (str) – The string to convert!

Return type

bool

Returns

The converted boolean.