Dns
airvpn.web.services.dns
DnsManager
Bases: ClientService
Manages the authenticated user's custom DNS configuration.
Wraps the AJAX endpoints behind https://airvpn.org/dns/ to view
available DNS lists and toggle or edit the user's custom DNS selection.
Attributes:
| Name | Type | Description |
|---|---|---|
lists |
list[Dns]
|
All DNS lists currently available. |
current |
Current
|
The user's currently active DNS configuration. |
device |
str | None
|
The device this configuration applies to, if any. |
add_answer(host: str, type: AnswerType = AnswerType.EXACT, action: ActionType = ActionType.DENY, records: list[Record] | None = None) -> Answer
Create a new answer rule and add it to the current configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The hostname or pattern the rule matches against. |
required |
type
|
AnswerType
|
How |
EXACT
|
action
|
ActionType
|
The action to take when the rule matches (e.g. allow,
deny). Defaults to |
DENY
|
records
|
list[Record] | None
|
Initial list of |
None
|
Returns:
| Type | Description |
|---|---|
Answer
|
The newly created |
add_list(dns: DnsList | list[DnsList] | list[str] | str)
add_record(answer: Answer, type: RecordType, value: str) -> Record
Create a record, attach it to an answer, and save the change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer
|
Answer
|
The |
required |
type
|
RecordType
|
The |
required |
value
|
str
|
The record's value (e.g. an IP address or hostname). |
required |
Returns:
| Type | Description |
|---|---|
Record
|
The |
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 |
required | |
value
|
New value to set for the field. |
required | |
**kwargs
|
Additional form fields to send along with the request
(e.g. an |
{}
|
Returns:
| Type | Description |
|---|---|
|
The parsed JSON response from the server. |
Raises:
| Type | Description |
|---|---|
APIError
|
If the response is a dict containing a non- |
from_dns(session: WebSession, device: str)
classmethod
Create a DnsManager scoped to a specific device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
WebSession
|
The |
required |
device
|
str
|
The device identifier to scope the configuration to. |
required |
Returns:
| Type | Description |
|---|---|
|
A new |
get_list(dns: DnsList | str)
Resolve a DNS list to a Dns instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dns
|
DnsList | str
|
|
required |
Returns:
| Type | Description |
|---|---|
|
The matching |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
remove_answer(answer: Answer)
Remove an answer from the current DNS configuration and save the change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer
|
Answer
|
The |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
remove_list(dns: DnsList)
Remove a DNS list from the current configuration and save the change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dns
|
DnsList
|
The DNS list code (str) to remove from the current selection. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
remove_record(answer: Answer, record: Record)
Remove a record from an answer's record list and save the change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer
|
Answer
|
The |
required |
record
|
Record
|
The |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
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- |
save()
Persist the current DNS configuration to the server.
toggle()
Toggle custom DNS on or off and save the change.
update()
Refresh lists and current from the server.
Fetches the DNS page and parses the embedded JSON data to
repopulate lists, the internal DNS lookup map, current,
and device.