add decouple to config the system

This commit is contained in:
Cayo Puigdefabregas 2020-09-29 09:42:05 +02:00
parent bfb67b92dd
commit ec671312db
5 changed files with 25 additions and 1 deletions

3
.gitignore vendored
View File

@ -113,3 +113,6 @@ ENV/
.vscode/
.DS_Store
/app.py
# Environment
.env

View File

@ -37,6 +37,11 @@ Create a PostgreSQL database called *devicehub* by running
- In MacOS: ``bash examples/create-db.sh devicehub dhub``, and password
``ereuse``.
Configure project using environment file (you can use provided example as quickstart):
.. code:: bash
$ cp examples/env.example .env
Using the `dh` tool for set up with one or multiple inventories.
Create the tables in the database by executing:

View File

@ -1,6 +1,7 @@
from distutils.version import StrictVersion
from itertools import chain
from typing import Set
from decouple import config
from teal.auth import TokenAuth
from teal.config import Config
@ -29,7 +30,16 @@ class DevicehubConfig(Config):
import_resource(versions)),
)
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str
DB_USER = config('DB_USER', 'dhub')
DB_PASSWORD = config('DB_PASSWORD', 'ereuse')
DB_HOST = config('DB_HOST', 'localhost')
DB_DATABASE = config('DB_DATABASE', 'devicehub')
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{pw}@{host}/{db}'.format(
user=DB_USER,
pw=DB_PASSWORD,
host=DB_HOST,
db=DB_DATABASE,
) # type: str
MIN_WORKBENCH = StrictVersion('11.0a1') # type: StrictVersion
"""The minimum version of ereuse.org workbench that this devicehub
accepts. we recommend not changing this value.

4
examples/env.example Normal file
View File

@ -0,0 +1,4 @@
DB_USER='dhub'
DB_PASSWORD='ereuse'
DB_HOST='localhost'
DB_DATABASE='devicehub'

View File

@ -34,3 +34,5 @@ weasyprint==44
psycopg2-binary==2.8.3
sortedcontainers==2.1.0
tqdm==4.32.2
python-decouple==3.3
python-dotenv==0.14.0