Skip to content

Common

airvpn.web.services.common

ClientService

Base class for AJAX-based clients against an AirVPN endpoint.

Provides shared CSRF-token handling and a generic AJAX request/edit interface that endpoint-specific managers (like PortManager or APIManager) can build on.

Attributes:

Name Type Description
session WebSession

The authenticated web session used for all requests made by this service.

ecsrf str | None

CSRF token scraped from the endpoint's page, used to authorize AJAX requests. Lazily fetched on first use.

endpoint str

URL of the AirVPN page this service issues AJAX requests against.

edit_request(name, value, **kwargs)

Send a generic edit_<name> action to the endpoint.

Convenience wrapper around request for the common pattern of editing a single field by name.

Parameters:

Name Type Description Default
name

Name of the field to edit; sent as the edit_{name} action.

required
value

New value to set for the field.

required
**kwargs

Additional form fields to send along with the request (e.g. an id or port identifying the target record).

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.

request(action: str, is_act: bool = False, **kwargs)

Send an AJAX action request to the endpoint.

Automatically attaches the CSRF token (fetching it first if not already known) and requests an AJAX-rendered response.

Parameters:

Name Type Description Default
action str

Name of the action to perform.

required
is_act bool

If the action param is act instead.

False
**kwargs

Additional form fields to send along with the request.

{}

Returns:

Type Description

The parsed JSON response from the server.

Raises:

Type Description
APIError

If the response is a dict containing a non-None "error" field.