ahriman.web.views package

Subpackages

Submodules

ahriman.web.views.base module

class BaseView(request: None)

Bases: View, CorsViewMixin

base web view to make things typed

OPTIONS_PERMISSION

(class attribute) options permissions of self

Type:

UserAccess

ROUTES

(class attribute) list of supported routes

Type:

list[str]

static get_non_empty(extractor: Callable[[str], T | None], key: str) T

get non-empty value from request parameters

Parameters:
  • extractor (Callable[[str], T | None]) – function to get value

  • key (str) – key to extract value

Returns:

extracted values if it is presented and not empty

Return type:

T

Raises:

KeyError – in case if key was not found or value is empty

async classmethod get_permission(request: Request) UserAccess

retrieve user permission from the request

Parameters:

request (Request) – request object

Returns:

extracted permission

Return type:

UserAccess

async head() StreamResponse

HEAD method implementation based on the result of GET method

Raises:

HTTPMethodNotAllowed – in case if there is no GET method implemented

page() tuple[int, int]

parse limit and offset and return values

Returns:

limit and offset from request

Return type:

tuple[int, int]

Raises:

HTTPBadRequest – if supplied parameters are invalid

repository_id() RepositoryId

extract repository from request

Returns:

repository if possible to construct and first one otherwise

Return type:

RepositoryIde

classmethod routes(configuration: Configuration) list[str]

extract routes list for the view

Parameters:

configuration (Configuration) – configuration instance

Returns:

list of routes defined for the view. By default, it tries to read ROUTES option if set and returns empty list otherwise

Return type:

list[str]

service(repository_id: RepositoryId | None = None) Watcher

get status watcher instance

Parameters:

repository_id (RepositoryId | None, optional) – repository unique identifier (Default value = None)

Returns:

build status watcher instance. If no repository provided, it will return the first one

Return type:

Watcher

Raises:

HTTPNotFound – if no repository found

async username() str | None

extract username from request if any

Returns:

authorized username if any and None otherwise (e.g. if authorization is disabled)

Return type:

str | None

property configuration: Configuration

get configuration instance

Returns:

configuration instance

Return type:

Configuration

property services: dict[RepositoryId, Watcher]

get all loaded watchers

Returns:

map of loaded watchers per known repository

Return type:

dict[RepositoryId, Watcher]

property sign: GPG

get GPG control instance

Returns:

GPG wrapper instance

Return type:

GPG

property spawner: Spawn

get process spawner instance

Returns:

external process spawner instance

Return type:

Spawn

property validator: Auth

get authorization instance

Returns:

authorization service instance

Return type:

Auth

property workers: WorkersCache

get workers cache instance

Returns:

workers service

Return type:

WorkersCache

ahriman.web.views.index module

class IndexView(request: None)

Bases: BaseView

root view

It uses jinja2 templates for report generation, the following variables are allowed:

  • auth - authorization descriptor, required
    • control - HTML to insert for login control, HTML string, required

    • enabled - whether authorization is enabled by configuration or not, boolean, required

    • username - authenticated username if any, string, null means not authenticated

  • index_url - url to the repository index, string, optional

  • repositories - list of repositories unique identifiers, required
    • id - unique repository identifier, string, required

    • repository - repository name, string, required

    • architecture - repository architecture, string, required

GET_PERMISSION

(class attribute) get permissions of self

Type:

UserAccess

async get() dict[str, Any]

process get request. No parameters supported here

Returns:

parameters for jinja template

Return type:

dict[str, Any]

ahriman.web.views.static module

class StaticView(request: None)

Bases: BaseView

special workaround for static files redirection (e.g. favicon)

GET_PERMISSION

(class attribute) get permissions of self

Type:

UserAccess

async get() None

process get request. No parameters supported here

Raises:
  • HTTPFound – on success response

  • HTTPNotFound – if path is invalid or unknown

ahriman.web.views.status_view_guard module

class StatusViewGuard

Bases: object

helper for check if status routes are enabled

classmethod routes(configuration: Configuration) list[str]

extract routes list for the view

Parameters:

configuration (Configuration) – configuration instance

Returns:

list of routes defined for the view. By default, it tries to read ROUTES option if set and returns empty list otherwise

Return type:

list[str]

Module contents