added a Configparser

This commit is contained in:
Tim Gröger 2019-12-30 09:22:43 +01:00
parent 3a5d7d7d0f
commit 7a95fb9d32
4 changed files with 50 additions and 7 deletions

9
geruecht/config.yml Normal file
View File

@ -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

24
geruecht/configparser.py Normal file
View File

@ -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()

View File

@ -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()

View File

@ -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 = []