From b138364323b563249564e798e445809a48ef4ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Copin?= Date: Sat, 8 Jul 2023 20:50:49 +0200 Subject: [PATCH] Add external configuration --- REQUIREMENTS | 1 + bin/import.py | 11 ++++++----- bin/server.py | 6 +++++- config/settings.yaml | 8 ++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 config/settings.yaml diff --git a/REQUIREMENTS b/REQUIREMENTS index 7656de5..eca36df 100644 --- a/REQUIREMENTS +++ b/REQUIREMENTS @@ -1,2 +1,3 @@ redis falcon +dynaconf diff --git a/bin/import.py b/bin/import.py index 2165063..c1bf1f4 100644 --- a/bin/import.py +++ b/bin/import.py @@ -10,14 +10,15 @@ import shutil import xml.sax import redis import time +from dynaconf import Dynaconf # Configuration -cpe_path = '../data/official-cpe-dictionary_v2.3.xml' -cpe_source = ( - 'https://nvd.nist.gov/feeds/xml/cpe/dictionary/official-cpe-dictionary_v2.3.xml.gz' +settings = Dynaconf( + settings_files=['../config/settings.yaml'] ) -rdb = redis.Redis(host='127.0.0.1', port=6379, db=8) - +cpe_path = settings.cpe.path +cpe_source = (settings.cpe.source) +rdb = redis.Redis(host=settings.redis.host, port=settings.redis.port, db=8) class CPEHandler(xml.sax.ContentHandler): def __init__(self): diff --git a/bin/server.py b/bin/server.py index 9e7cf57..16b49f0 100644 --- a/bin/server.py +++ b/bin/server.py @@ -6,9 +6,13 @@ import sys import falcon from wsgiref.simple_server import make_server import json +from dynaconf import Dynaconf # Configuration -port = 8000 +settings = Dynaconf( + settings_files=['../config/settings.yaml'] +) +port = settings.server.port runPath = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(runPath, "..")) diff --git a/config/settings.yaml b/config/settings.yaml new file mode 100644 index 0000000..45ddd82 --- /dev/null +++ b/config/settings.yaml @@ -0,0 +1,8 @@ +server: + port: 8000 +redis: + host: 127.0.0.1 + port: 6379 +cpe: + path: '../data/official-cpe-dictionary_v2.3.xml' + source: 'https://nvd.nist.gov/feeds/xml/cpe/dictionary/official-cpe-dictionary_v2.3.xml.gz' \ No newline at end of file