Init configuration

This commit is contained in:
Giacomo Leidi 2021-05-02 16:44:03 +02:00
parent 6273e56311
commit 0d02f2dd52
4 changed files with 59 additions and 4 deletions

3
.gitignore vendored
View File

@ -9,6 +9,9 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# Ignore dynaconf secret files
**/.secrets.*
# C extensions # C extensions
*.so *.so

View File

@ -1,4 +1 @@
__version__ = '0.1.0' __version__ = "0.1.0"
from . import publishers

34
mobilizon_bots/config.py Normal file
View File

@ -0,0 +1,34 @@
from dynaconf import Dynaconf, Validator
settings = Dynaconf(
envvar_prefix="MOBOTS",
settings_files=[
"settings.toml",
".secrets.toml",
"/etc/mobots.toml",
"/etc/mobots_secrets.toml",
],
validators=[
# Ensure some parameters exists (are required)
Validator("LOCAL_STATE_DIR", "LOG_DIR", "DB_PATH", must_exist=True),
# Ensure some parameter mets a condition
# conditions: (eq, ne, lt, gt, lte, gte, identity, is_type_of, is_in, is_not_in)
Validator("LOCAL_STATE_DIR", "LOG_DIR", "DB_PATH", is_type_of=str),
# check file or directory
# validate a value is eq in specific env
# Validator('PROJECT', eq='hello_world', env='production'),
#
# # Ensure some parameter (string) meets a condition
# # conditions: (len_eq, len_ne, len_min, len_max, cont)
# # Determines the minimum and maximum length for the value
# Validator("NAME", len_min=3, len_max=125),
#
# # Signifies the presence of the value in a set, text or word
# Validator("DEV_SERVERS", cont='localhost'),
#
# # Checks whether the length is the same as defined.
# Validator("PORT", len_eq=4),
],
)
settings.validators.validate()

View File

@ -0,0 +1,21 @@
[default]
DEBUG = false
DEVELOPMENT = false
LOCAL_STATE_DIR = "/var/mobots"
LOG_DIR = "/var/log/mobots"
DB_NAME = "events.db"
DB_PATH ="@jinja /{{ this.LOCAL_STATE_DIR }}/{{ this.DB_NAME | abspath }}"
[development]
DEVELOPMENT = true
DEBUG = true
LOCAL_STATE_DIR = "/tmp/mobots"
LOG_DIR = "/tmp/mobots"
DB_NAME = "development.db"
DB_PATH="@jinja /{{ this.LOCAL_STATE_DIR }}/{{ this.DB_NAME | abspath }}"
[testing]
DEBUG = true
LOCAL_STATE_DIR = "/tmp/mobots"
LOG_DIR = "/tmp/mobots"
DB_PATH=":memory:"