Apache infrastructure

Clone this repo:
  1. 8e4dc7c Cleanup application construction (#30) by Thomas Neidhart · 2 months ago main
  2. 401039b Update pyproject.toml, bump dev version to 0.1.11 by Daniel Gruno · 3 months ago
  3. b2fbe33 Merge pull request #27 from apache/bump-asfpy by Thomas Neidhart · 3 months ago 0.1.10
  4. a4abe40 keep version specifier by Thomas Neidhart · 3 months ago
  5. b21390a Add sections about installing and building asfquart by Thomas Neidhart · 3 months ago

asfquart - a Quart framework for the ASF

This is a Quart framework for ASF web applications.

On top of Quart, this package layers a lot of functionality, much of which is specific to the ASF and its infrastructure and preferred approaches for website application development.

asfquart adds the following items to basic quart:

  • simple construction of the APP
  • default config.yaml
  • watching the .py and config for changes, to cause a restart/reload
  • watch SIGINT to halt and SIGUSR2 to restart/reload
  • template watching and rendering for EZT templates
  • URL path routing for pages and API endpoints
  • Oauth with our ASF provider for authn
  • LDAP group testing for authz
  • long-running tasks and their lifecycle management

Current (known, public) users of asfquart:

Future users of asfquart:

  • Apache STeVe
  • Identity management (replaces the old id.a.o)
  • Gitbox UI
  • ??

Primer

See the documentation page for more information.

import asfquart
from asfquart.auth import Requirements as R

def my_app() -> asfquart.base.QuartApp:
    # Construct the quart service. By default, the oauth gateway is enabled at /oauth.
    app = asfquart.construct("my_app_service")

    @app.route("/")
    async def homepage():
        return "Hello!"

    @app.route("/secret")
    @asfquart.auth.require(R.committer)
    async def secret_page():
      return "Secret stuff!"

    return app

if __name__ == "__main__":
    app = my_app()

    # Run the application in an extended debug mode:
    #  - reload the app when any source / config file get changed
    app.runx(port=8000)
else:
    # Serve the application via an ASGI server, e.g. hypercorn
    app = my_app()

Installation

Create and activate a virtual environment and then install asfquart using pip:

$ pip install "asfquart"

Note: Adding the [aioldap] extra will install optional dependencies for LDAP support that will require additional system dependencies:

$ pip install "asfquart[aioldap]"

Building asfquart package

Prerequisites:

  • poetry: install e.g. with pipx pipx install poetry

Building the package:

$ poetry build

Running the tests:

$ poetry run pytest

Examples

There is a simple test application included (./examples/snippets/simple_app.py) to outline the basic setup. To run the application in development mode, type:

$ make example-dev

to run it with an ASGI server for production, type:

$ make example-run