configuration.core module

Configuring Runestone Servers

Many things about Runestone servers 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.

class configuration.core.BookServerConfig(value)

Bases: Enum

An enumeration.

development = 'development'
production = 'production'
test = 'test'
class configuration.core.DatabaseType(value)

Bases: Enum

An enumeration.

PostgreSQL = 1
SQLite = 0
class configuration.core.Settings(_case_sensitive: bool | None = None, _env_prefix: str | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_nested_delimiter: str | None = None, _secrets_dir: str | Path | None = None, *, google_ga: str = '', runestone_path: PosixPath = PosixPath('/usr'), book_path: Path = PosixPath('/usr/books'), error_path: Path = PosixPath('/usr/books/tickets'), server_config: str = 'development', book_server_config: BookServerConfig = 'development', dburl: str = 'sqlite:////usr/runestone.db', dev_dburl: str = 'sqlite:////usr/runestone_dev.db', test_dburl: str = 'sqlite:////usr/runestone_test.db', db_echo: bool = False, redis_uri: str = 'redis://localhost:6379/0', is_exam: bool = False, login_url: str = '/auth/login', adsenseid: str = '', num_banners: int = 0, serve_ad: bool = False, academy_mode: bool = True, lti_only_mode: bool = False, jwt_secret: bytes = b'supersecret', drop_tables: str = 'No', spaces_key: str = 'key', spaces_secret: str = 'secret', region: str = 'nyc3', bucket: str = 'runestonefiles', log_level: str = 'DEBUG', **values: Any)

Bases: BaseSettings

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.

academy_mode: bool
adsenseid: str
book_path: Path
book_server_config: BookServerConfig
bucket: str
property database_type: DatabaseType
property database_url: str
db_echo: bool
dburl: str
dev_dburl: str
drop_tables: str
error_path: Path
google_ga: str
is_exam: bool
jwt_secret: bytes
log_level: str
login_url: str
lti_only_mode: bool
model_config: ClassVar[SettingsConfigDict] = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'env_file': '.env', 'env_file_encoding': 'utf-8', 'env_nested_delimiter': None, 'env_prefix': '', 'extra': 'allow', 'protected_namespaces': ('model_', 'settings_'), 'secrets_dir': None, 'validate_default': True}

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

model_fields: ClassVar[dict[str, FieldInfo]] = {'academy_mode': FieldInfo(annotation=bool, required=False, default=True), 'adsenseid': FieldInfo(annotation=str, required=False, default=''), 'book_path': FieldInfo(annotation=Path, required=False, default=PosixPath('/usr/books')), 'book_server_config': FieldInfo(annotation=BookServerConfig, required=False, default='development'), 'bucket': FieldInfo(annotation=str, required=False, default='runestonefiles'), 'db_echo': FieldInfo(annotation=bool, required=False, default=False), 'dburl': FieldInfo(annotation=str, required=False, default='sqlite:////usr/runestone.db'), 'dev_dburl': FieldInfo(annotation=str, required=False, default='sqlite:////usr/runestone_dev.db'), 'drop_tables': FieldInfo(annotation=str, required=False, default='No'), 'error_path': FieldInfo(annotation=Path, required=False, default=PosixPath('/usr/books/tickets')), 'google_ga': FieldInfo(annotation=str, required=False, default=''), 'is_exam': FieldInfo(annotation=bool, required=False, default=False), 'jwt_secret': FieldInfo(annotation=bytes, required=False, default=b'supersecret'), 'log_level': FieldInfo(annotation=str, required=False, default='DEBUG'), 'login_url': FieldInfo(annotation=str, required=False, default='/auth/login'), 'lti_only_mode': FieldInfo(annotation=bool, required=False, default=False), 'num_banners': FieldInfo(annotation=int, required=False, default=0), 'redis_uri': FieldInfo(annotation=str, required=False, default='redis://localhost:6379/0'), 'region': FieldInfo(annotation=str, required=False, default='nyc3'), 'runestone_path': FieldInfo(annotation=PosixPath, required=False, default=PosixPath('/usr')), 'serve_ad': FieldInfo(annotation=bool, required=False, default=False), 'server_config': FieldInfo(annotation=str, required=False, default='development'), 'spaces_key': FieldInfo(annotation=str, required=False, default='key'), 'spaces_secret': FieldInfo(annotation=str, required=False, default='secret'), 'test_dburl': FieldInfo(annotation=str, required=False, default='sqlite:////usr/runestone_test.db')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

num_banners: int
redis_uri: str
region: str
runestone_path: PosixPath
serve_ad: bool
server_config: str
spaces_key: str
spaces_secret: str
test_dburl: str
property web2py_private_key: str

Get the web2py private key. Prefer to get it from the environment. This allows us to avoid introducing a secret into the codebase, and it also avoids the need to mount a volume to the container to store the key in a file.

Returns:

The web2py private key.

Return type:

str