fietsboek.config module

Configuration parsing for Fietsboek.

Fietsboek mostly relies on pyramid’s INI parsing to get its configuration, however, there are quite a a few custom values that we add/need. Instead of manually sprinkling settings.get(...) all over the code, we’d rather just do it once at application startup, make sure that the values are well-formed, provide the user with good feedback if they aren’t, and set the default values in a single place.

Most of the logic is handled by pydantic.

class fietsboek.config.Config(**data)

Bases: BaseModel

Object representing the Fietsboek configuration.

available_locales: Annotated[list]

Available locales.

data_dir: Annotated[Path]

Fietsboek data directory.

default_tile_layers: Annotated[list]

The subset of the default tile layers that should be enabled.

By default, that’s all of them.

derive_secret(what_for)

Derive a secret for other parts of the application.

All secrets are derived from secret_key in a deterministic way. See https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/security.html#admonishment-against-secret-sharing on why secret_key should not be used directly.

Parameters:

what_for (str) – What the secret is used for. Passing the same “use case” will generate the same secret.

Returns:

The generated secret.

Return type:

str

disable_tile_proxy: bool

Disable the tile proxy.

email_from: str

Email sender address.

email_password: SecretStr

SMTP password (optional).

email_smtp_url: str

Email SMTP server.

email_username: str

SMTP username (optional).

enable_account_registration: bool

Enable registration of new accounts.

enable_image_uploads: bool

Allow track uploaders to also upload images for tracks.

hittekaart_autogenerate: Annotated[list]

Overlay maps to automatically generate.

hittekaart_bin: str

Path to the hittekaart binary.

hittekaart_threads: int

Number of threads that hittekaart should use.

Defaults to 0, which makes it use as many threads as there are CPU cores.

language_packs: Annotated[list]

Additional language packs to load.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pages: Annotated[list]

Custom pages.

redis_url: str

Redis URL.

session_key: str

Session key.

sqlalchemy_url: str

SQLAlchemy URL.

stamen_maps: Annotated[list]

Enabled stamen maps.

thunderforest_access: LayerAccess

Thunderforest access restriction.

thunderforest_key: SecretStr

API key for the Thunderforest integration.

thunderforest_maps: Annotated[list]

List of enabled Thunderforest maps.

tile_layers: List[TileLayerConfig]

Tile layers.

class fietsboek.config.LayerAccess(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enum discerning whether a layer is publicly accessible or restriced to logged-in users.

Note that in the future, a finer-grained distinction might be possible.

PUBLIC = 'public'
RESTRICTED = 'restricted'
class fietsboek.config.LayerType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Enum to distinguish base layers and overlay layers.

BASE = 'base'
OVERLAY = 'overlay'
class fietsboek.config.TileLayerConfig(**data)

Bases: BaseModel

Object representing a single tile layer.

access: LayerAccess

Layer access restriction.

attribution: str

Attribution of the layer copyright.

layer_id: str

ID of the layer.

layer_type: LayerType

Type of the layer.

model_config: ClassVar[ConfigDict] = {'populate_by_name': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str

Human-readable name of the layer.

url: AnyUrl

URL of the layer tiles (with placeholders).

zoom: Optional[int]

Maximum zoom factor of the layer.

exception fietsboek.config.ValidationError(errors)

Bases: Exception

Exception for malformed configurations.

This provides a nice str() representation that can be printed out.

fietsboek.config.parse(config)

Parses the configuration into a Config.

Parameters:

config (dict) – The configuration dict to parse.

Return type:

Config

Returns:

The parsed (and validated) configuration.

Raises:

ValidationError – When the configuration is malformed.