Skip to main content
https://travis-ci.org/willnx/vlab_api_common.svg?branch=master

vlab_api_common

Common logic used by every API within vLab - things like making response shapes consistent, providing functionality for the describe parameter, etc.

The requires and deny decorators

These decorators are used together to create an Access Control List for your Flask API. You can layer these directorates however you want, but beware - “With great power comes great responsibility.”

Examples

Here are some examples of using the requires and deny decorators.

Basic Syntax

To use the requires or deny decorators in your Flask API, simply add them to your function before @app.route. You should also accpet **kwargs because additional information like the token and validation information will be passed along.

This example will allow any user with a valid token access:

from vlab_api_common import requires, deny
@requires()
@app.route('/api/1/foo')
def hello(**kwargs):
  return "hello world"

While this example shows how to forbid jordan access:

from vlab_api_common import requires, deny
@deny(username='jordan')
@app.route('/api/1/foo')
def hello(**kwargs):
  return "hello world"

Verifying

In this example, any user with a valid authentication token will be able to perform an HTTP GET on the API end point.

@requires(verify=False)
@app.route('/api/1/foo')
def hello(**kwargs):
  return "hello world!"

The difference in this next example is that the requires decorator will check with the configured vLab Authentication Service to ensure that the user has not deleted their token:

@requires()
@app.route('/api/1/foo')
def hello(**kwargs):
  return "hello world!"

Notice how this is the default behavior. If you have a resource that’s not very sensitive, and have extremely high requirements on availability, consider explicitly setting verify=False on the requires and deny decorators.

The verify keyword argument applies to both the requires and deny decorators.

OR-ing identities

You can specify multiple values in the requires and deny decorators. When you specify more than one value in a single decorator, the identities are OR ed. In other words, the moment an identity in the token matches a defined value, the user is granted access.

In this example, if the user is named bob but he is not part of Department A, then the user is still granted access:

@requires(username=('bob', 'sarah'), memberOf='Department A')
@app.route('/api/1/foo')
def hello(**kwargs):
  return "Hello World!"

AND-ing identities

When you layer multiple requires and/or deny decorators together, you AND those decoratores. In other words, all decorators must return successfully for the user to be granted access.

In this example, only forest and jenny from Department A will be granted access. All other members within Department A will not be granted access

@requires(username=('forest', 'jenny'))
@requires(memberOf='Department A')
@app.route('/api/1/foo')
def hello(**kwargs):
  return "hello forest or jenny from Department A!"

Metadata

Release files for vlab-api-common 2020.12.29

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for vlab-api-common 2020.12.29
File Interpreter ABI Platform Actions
vlab_api_common-2020.12.29-py2.py3-none-any.whl Python 3, Python 2 none any Details for vlab_api_common-2020.12.29-py2.py3-none-any.whl

Release files / vlab_api_common-2020.12.29-py2.py3-none-any.whl

Download URL vlab_api_common-2020.12.29-py2.py3-none-any.whl
Size 14.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f45dc02a0aa86098612c367d49f9f4743ccebc03fdc36d2243eec9fe537a6bfc
BLAKE2b-256 checksum
How to use checksums
fd7f153449e502e930db0542774da9e3591002b194b0faeccc14ccdd589b7506
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.9

Security for vlab-api-common 2020.12.29

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page