Restructured config setup
This commit is contained in:
parent
9537943fa5
commit
97562394ce
@ -1,6 +1,5 @@
|
||||
# Python imports
|
||||
import os, secrets
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
|
||||
# Lib imports
|
||||
@ -16,40 +15,14 @@ from flask_login import current_user, login_user, logout_user, LoginManager
|
||||
from core.utils import Logger
|
||||
|
||||
|
||||
# Configs and 'init'
|
||||
APP_NAME = ':::APP TITLE:::'
|
||||
ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
# This path is submitted as the redirect URI in certain code flows.
|
||||
# Change localhost%3A6969 to different port accordingly or change to your domain.
|
||||
REDIRECT_LINK = "http%3A%2F%2Flocalhost%3A6969%2F"
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.update({
|
||||
"TITLE": APP_NAME,
|
||||
'DEBUG': False,
|
||||
'LOGIN_PATH': "FLASK_LOGIN", # Value can be OIDC or FLASK_LOGIN
|
||||
'SECRET_KEY': secrets.token_hex(32), # For csrf and some other stuff...
|
||||
'PERMANENT_SESSION_LIFETIME': timedelta(days = 7).total_seconds(),
|
||||
'SQLALCHEMY_DATABASE_URI': "sqlite:///static/db/database.db",
|
||||
'SQLALCHEMY_TRACK_MODIFICATIONS': False,
|
||||
'APP_REDIRECT_URI': REDIRECT_LINK,
|
||||
'OIDC_CLIENT_SECRETS': ROOT_FILE_PTH + '/client_secrets.json',
|
||||
'OIDC_ID_TOKEN_COOKIE_SECURE': True, # Only set false in development setups...
|
||||
'OIDC_REQUIRE_VERIFIED_EMAIL': False,
|
||||
'OIDC_USER_INFO_ENABLED': True,
|
||||
'OIDC_VALID_ISSUERS': [
|
||||
'http://localhost:8080/auth/realms/apps',
|
||||
'https://localhost:443/auth/realms/apps'
|
||||
],
|
||||
'OIDC_TOKEN_TYPE_HINT': 'access_token'
|
||||
})
|
||||
app.config.from_object("core.config.Config")
|
||||
|
||||
oidc = OpenIDConnect(app)
|
||||
login_manager = LoginManager(app)
|
||||
bcrypt = Bcrypt(app)
|
||||
logger = Logger().get_logger()
|
||||
|
||||
|
||||
def oidc_loggedin():
|
||||
return oidc.user_loggedin
|
||||
|
||||
@ -60,10 +33,9 @@ def oidc_isAdmin():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
|
||||
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
|
||||
app.jinja_env.globals['TITLE'] = APP_NAME
|
||||
app.jinja_env.globals['TITLE'] = app.config["TITLE"]
|
||||
|
||||
|
||||
from core.models import db, User
|
||||
|
74
src/core/config.py
Normal file
74
src/core/config.py
Normal file
@ -0,0 +1,74 @@
|
||||
# System import
|
||||
import os, secrets, json
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
# Lib imports
|
||||
|
||||
|
||||
# Apoplication imports
|
||||
|
||||
|
||||
APP_NAME = ':::APP TITLE:::'
|
||||
ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
# This path is submitted as the redirect URI in certain code flows.
|
||||
# Change localhost%3A6969 to different port accordingly or change to your domain.
|
||||
REDIRECT_LINK = "http%3A%2F%2Flocalhost%3A6969%2F"
|
||||
|
||||
|
||||
class FileGroups:
|
||||
videos = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
|
||||
office = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
|
||||
images = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga')
|
||||
text = ('.txt', '.text', '.sh', '.cfg', '.conf')
|
||||
music = ('.psf', '.mp3', '.ogg', '.flac', '.m4a')
|
||||
pdf = ('.pdf')
|
||||
|
||||
|
||||
class Config(object):
|
||||
TITLE = APP_NAME
|
||||
DEBUG = False
|
||||
TESTING = False
|
||||
SECRET_KEY = secrets.token_hex(32)
|
||||
|
||||
PERMANENT_SESSION_LIFETIME = timedelta(days = 7).total_seconds()
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///static/db/database.db"
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
LOGIN_PATH = "FLASK_LOGIN" # Value can be OIDC or FLASK_LOGIN
|
||||
OIDC_TOKEN_TYPE_HINT = 'access_token'
|
||||
APP_REDIRECT_URI = REDIRECT_LINK
|
||||
OIDC_CLIENT_SECRETS = ROOT_FILE_PTH + '/client_secrets.json'
|
||||
OIDC_ID_TOKEN_COOKIE_SECURE = True
|
||||
OIDC_REQUIRE_VERIFIED_EMAIL = True
|
||||
OIDC_USER_INFO_ENABLED = True
|
||||
OIDC_VALID_ISSUERS = [
|
||||
'http://localhost:8080/auth/realms/apps',
|
||||
'https://localhost:443/auth/realms/apps'
|
||||
]
|
||||
|
||||
STATIC_FPTH = ROOT_FILE_PTH + "/static"
|
||||
FILEGROUPS = FileGroups
|
||||
VEXTENSION = FileGroups.videos
|
||||
OEXTENSION = FileGroups.office
|
||||
IEXTENSION = FileGroups.images
|
||||
TEXTENSION = FileGroups.text
|
||||
MEXTENSION = FileGroups.music
|
||||
PEXTENSION = FileGroups.pdf
|
||||
|
||||
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
DEBUG = True
|
||||
OIDC_ID_TOKEN_COOKIE_SECURE = False
|
||||
OIDC_REQUIRE_VERIFIED_EMAIL = False
|
||||
|
||||
|
||||
class TestingConfig(Config):
|
||||
TESTING = True
|
@ -6,7 +6,7 @@ from flask_login import current_user
|
||||
|
||||
|
||||
# App imports
|
||||
from core import app, oidc, db # Get from __init__
|
||||
from core import app, logger, oidc, db # Get from __init__
|
||||
from core.utils import MessageHandler # Get simple message processor
|
||||
|
||||
|
||||
|
@ -5,13 +5,13 @@ import os, logging
|
||||
|
||||
|
||||
class Logger:
|
||||
def __init__(self):
|
||||
self.logger = self.create_logger("flask_app")
|
||||
def __init__(self, name = "NO_LOGGER_NAME_PASSED_ON_INIT"):
|
||||
self.logger = self.create_logger(name)
|
||||
|
||||
def get_logger(self):
|
||||
return self.logger
|
||||
|
||||
def create_logger(self, loggerName = "NO_LOGGER_NAME_PASSED", createFile = True):
|
||||
def create_logger(self, loggerName, createFile = True):
|
||||
"""
|
||||
Create a new logging object and return it.
|
||||
:note:
|
||||
|
Loading…
Reference in New Issue
Block a user