diff --git a/.gitignore b/.gitignore index b7c6bfa..018b26e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ __pycache__/ *.py[cod] *$py.class +# Ignore dynaconf secret files +**/.secrets.* + # C extensions *.so diff --git a/mobilizon_bots/__init__.py b/mobilizon_bots/__init__.py index df552ad..3dc1f76 100644 --- a/mobilizon_bots/__init__.py +++ b/mobilizon_bots/__init__.py @@ -1,4 +1 @@ -__version__ = '0.1.0' - - -from . import publishers +__version__ = "0.1.0" diff --git a/mobilizon_bots/config.py b/mobilizon_bots/config.py new file mode 100644 index 0000000..f07b2ee --- /dev/null +++ b/mobilizon_bots/config.py @@ -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() diff --git a/mobilizon_bots/settings.toml b/mobilizon_bots/settings.toml new file mode 100644 index 0000000..de2535d --- /dev/null +++ b/mobilizon_bots/settings.toml @@ -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:" \ No newline at end of file