config.py - Configuring Runestone BookServer
Many thing about Runestone BookServer are configurable. This is the place to change the configuration for most things. Private things should be configured in the environment so they are not accidentally committed to Github. Defaults provided here may be overridden by environment variables Per.
Imports
These are listed in the order prescribed by PEP 8.
Standard library
Third-party imports
Local application imports
Settings
Define the possible bookserver configurations. The values assigned must be strings, since Pydantic will match these with environment variables.
A enum for the type of database in use.
Pydantic provides a wonderful utility to handle settings. The beauty of it
is that you can specify variables with or without default values, and Pydantic
will check your environment variables in a case-insensitive way. So that
if you have PROD_DBURL`
set in the environment it will be set as the value
for prod_dburl`
in settings.
This is a really nice way to keep from
committing any data you want to keep private.
Provide a path to the book server files. The leading underscore prevents environment variables from affecting this value. See the docs, which don’t say this explicitly, but testing confirms it.
The path to the Runestone application inside web2py.
book_path: specify the directory to serve books from. For now, default to serving from the same place as the Runestone server, since the server uses some of these files.
The path to store error logs.
Define the mode of operation for the webserver, taken from BookServerConfig`
. This looks a bit odd, since the string value will be parsed by Pydantic into a Config.
warning
When using an Enum for a configuration setting you cannot compare against
a string. The value will actually be BookServerConfig.development`
or whatever.
Our style will be to compare against the Enum not the .name
attribute.
Database setup: this must be an standard (synchronous) connection; for example:
sqlite:///./runestone.db
postgresql://postgres:bully@localhost/runestone
Given a sync database URI, return its async equivalent.
Determine the synchronous database URL based on the book_server_config
and the dburls above.
Return the async equivalent of the URI from sync_database_url
.
Determine the database type from the URL.
Setting db_echo to True makes for a LOT of sqlalchemy output - it gives you the SQL for every query!
The docker-compose.yml file will set the REDIS_URI environment variable
Select normal mode or a high-stakes assessment mode (for administering a examination). In this mode, answers to supported question types are not shown.
This module provides “/auth/login” but it is super basic For now, logins are meant to be handled by the parallel runestone server. For production usage set the LOGIN_URL to /runestone/default/user
Configure ads. TODO: Link to the place in the Runestone Components where this is used.
This is the secret key used for generating the JWT token.
This is the private key web2py uses for hashing passwords.
Put the cache here; above the def, it produces TypeError: unhashable type: 'Settings'
.
if you want to reinitialize your database set this to Yes
.
All data in the database will be lost! This will only work for
development and test book_server_config
settings.