Added __builtins__ file and cleanup afterwards

This commit is contained in:
itdominator 2023-03-15 22:41:02 -05:00
parent e09a702896
commit 60ea5945be
7 changed files with 42 additions and 31 deletions

36
src/core/__builtins__.py Normal file
View File

@ -0,0 +1,36 @@
# Python imports
import os
import builtins
import threading
# Lib imports
# Application imports
from core.utils import Logger
from core.utils import MessageHandler # Get simple message processor
class BuiltinsException(Exception):
...
# NOTE: Threads WILL NOT die with parent's destruction.
def threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
return wrapper
# NOTE: Threads WILL die with parent's destruction.
def daemon_threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
return wrapper
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.app_name = ':::APP TITLE:::'
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
builtins.ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
builtins.logger = Logger().get_logger()
builtins.json_message = MessageHandler()

View File

@ -1,32 +1,29 @@
# Python imports # Python imports
import os import os
# Lib imports # Lib imports
from flask import Flask from flask import Flask
# OIDC Login path # OIDC Login path
from flask_oidc import OpenIDConnect from flask_oidc import OpenIDConnect
# Flask Login Path # Flask Login Path
from flask_bcrypt import Bcrypt from flask_bcrypt import Bcrypt
from flask_login import current_user from flask_login import current_user
from flask_login import login_user from flask_login import login_user
from flask_login import logout_user from flask_login import logout_user
from flask_login import LoginManager from flask_login import LoginManager
# Apoplication imports # Apoplication imports
from core.utils import Logger from .__builtins__ import *
app = Flask(__name__) app = Flask(__name__)
app.config.from_object("core.config.Config") app.config.from_object("core.config.Config")
# app.config.from_object("core.config.DevelopmentConfig")
oidc = OpenIDConnect(app) oidc = OpenIDConnect(app)
login_manager = LoginManager(app) login_manager = LoginManager(app)
bcrypt = Bcrypt(app) bcrypt = Bcrypt(app)
logger = Logger().get_logger()
def oidc_loggedin(): def oidc_loggedin():
return oidc.user_loggedin return oidc.user_loggedin
@ -38,12 +35,12 @@ def oidc_isAdmin():
return True return True
return False return False
app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
app.jinja_env.globals['TITLE'] = app.config["TITLE"] app.jinja_env.globals['TITLE'] = app.config["TITLE"]
from core.models import db from core.models import db
from core.models import User from core.models import User

View File

@ -10,8 +10,6 @@ from datetime import timedelta
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. # This path is submitted as the redirect URI in certain code flows.
# Change localhost%3A6969 to different port accordingly or change to your domain. # Change localhost%3A6969 to different port accordingly or change to your domain.
REDIRECT_LINK = "http%3A%2F%2Flocalhost%3A6969%2F" REDIRECT_LINK = "http%3A%2F%2Flocalhost%3A6969%2F"
@ -27,7 +25,7 @@ class FileGroups:
class Config(object): class Config(object):
TITLE = APP_NAME TITLE = app_name
DEBUG = False DEBUG = False
TESTING = False TESTING = False
SECRET_KEY = secrets.token_hex(32) SECRET_KEY = secrets.token_hex(32)

View File

@ -18,12 +18,8 @@ from core import db
from core import User from core import User
from core import LoginForm from core import LoginForm
from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
@app.route('/app-login', methods=['GET', 'POST']) @app.route('/app-login', methods=['GET', 'POST'])
def app_login(): def app_login():
if current_user.is_authenticated or app.config["LOGIN_DISABLED"]: if current_user.is_authenticated or app.config["LOGIN_DISABLED"]:

View File

@ -16,13 +16,9 @@ from core import current_user
from core import RegisterForm from core import RegisterForm
from core.models import User from core.models import User
from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
@app.route('/app-register', methods=['GET', 'POST']) @app.route('/app-register', methods=['GET', 'POST'])
def app_register(): def app_register():
if current_user.is_authenticated or app.config["REGISTER_DISABLED"]: if current_user.is_authenticated or app.config["REGISTER_DISABLED"]:

View File

@ -13,11 +13,6 @@ from ... import app
from ... import oidc from ... import oidc
from ... import db from ... import db
from ...utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
@app.route('/oidc-register', methods=['GET', 'POST']) @app.route('/oidc-register', methods=['GET', 'POST'])

View File

@ -8,16 +8,9 @@ from flask_login import current_user
# Application imports # Application imports
# Get from __init__ # Get from __init__
from core import app from core import app
from core import logger
from core import oidc from core import oidc
from core import db from core import db
from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def home(): def home():