From 7a95fb9d32c9d313ab0d1692e41da164c1a002d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 30 Dec 2019 09:22:43 +0100 Subject: [PATCH] added a Configparser --- geruecht/config.yml | 9 ++++++++ geruecht/configparser.py | 24 +++++++++++++++++++++ geruecht/controller/__init__.py | 20 ++++++++++++----- geruecht/controller/accesTokenController.py | 4 ++-- 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 geruecht/config.yml create mode 100644 geruecht/configparser.py diff --git a/geruecht/config.yml b/geruecht/config.yml new file mode 100644 index 0000000..2b3e45b --- /dev/null +++ b/geruecht/config.yml @@ -0,0 +1,9 @@ +AccessTokenLifeTime: 1800 +Database: + URL: 192.168.5.108 + user: wu5 + passwd: E1n$tein + database: geruecht +LDAP: + URL: ldap://192.168.5.108 + dn: dc=ldap,dc=example,dc=local \ No newline at end of file diff --git a/geruecht/configparser.py b/geruecht/configparser.py new file mode 100644 index 0000000..ee945e0 --- /dev/null +++ b/geruecht/configparser.py @@ -0,0 +1,24 @@ +import yaml + +class ConifgParser(): + def __init__(self, file='config.yml'): + self.file = file + with open(file, 'r') as f: + self.config = yaml.load(f) + + print(self.config) + self.db = self.config['Database'] + self.ldap = self.config['LDAP'] + self.accessTokenLifeTime = self.config['AccessTokenLifeTime'] + + def getLDAP(self): + return self.ldap + + def getDatabase(self): + return self.db + + def getAccessToken(self): + return self.accessTokenLifeTime + +if __name__ == '__main__': + ConifgParser() \ No newline at end of file diff --git a/geruecht/controller/__init__.py b/geruecht/controller/__init__.py index fa32eb5..efcc892 100644 --- a/geruecht/controller/__init__.py +++ b/geruecht/controller/__init__.py @@ -1,4 +1,10 @@ from geruecht.logger import getLogger +from geruecht.configparser import ConifgParser +import os + +print(os.getcwd()) + +config = ConifgParser('geruecht/config.yml') LOGGER = getLogger(__name__) @@ -14,17 +20,21 @@ def getDatabesController(): if db is not None: return db else: - return DatabaseController() + return DatabaseController(dbConfig['URL'], dbConfig['user'], dbConfig['passwd'], dbConfig['database']) from .ldapController import LDAPController def getLDAPController(): if ldapController is not None: return ldapController else: - return LDAPController() + return LDAPController(ldapConfig['URL'], ldapConfig['dn']) from .accesTokenController import AccesTokenController -db = DatabaseController() -ldapController = LDAPController() -accesTokenController = AccesTokenController("GERUECHT") +dbConfig = config.getDatabase() +ldapConfig = config.getLDAP() +accConfig = config.getAccessToken() + +db = DatabaseController(dbConfig['URL'], dbConfig['user'], dbConfig['passwd'], dbConfig['database']) +ldapController = LDAPController(ldapConfig['URL'], ldapConfig['dn']) +accesTokenController = AccesTokenController(accConfig) from . userController import UserController userController = UserController() \ No newline at end of file diff --git a/geruecht/controller/accesTokenController.py b/geruecht/controller/accesTokenController.py index 1c6e9ec..281ad37 100644 --- a/geruecht/controller/accesTokenController.py +++ b/geruecht/controller/accesTokenController.py @@ -15,14 +15,14 @@ class AccesTokenController(metaclass=Singleton): """ instance = None tokenList = None - lifetime = 1800 - def __init__(self, arg): + def __init__(self, lifetime=1800): """ Initialize AccessTokenController Initialize Thread and set tokenList empty. """ LOGGER.info("Initialize AccessTokenController") + self.lifetime = lifetime self.tokenList = []