forked from Github-Mirrors/canaille
Configuration file
This commit is contained in:
parent
77f6600de7
commit
5957029860
5 changed files with 14 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ venv/*
|
|||
.*@neomake*
|
||||
.ash_history
|
||||
.python_history
|
||||
config.toml
|
||||
|
|
6
config.sample.toml
Normal file
6
config.sample.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
SECRET_KEY = "change me before you go in production"
|
||||
|
||||
[LDAP]
|
||||
URI = "ldaps://ldap.mydomain.tld"
|
||||
BIND_USER = "cn=admin,dc=mydomain,dc=tld"
|
||||
BIND_PW = "admin"
|
|
@ -2,3 +2,4 @@ Flask
|
|||
Flask-SQLAlchemy
|
||||
Authlib==0.14.3
|
||||
python-ldap
|
||||
toml
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import ldap
|
||||
import os
|
||||
import toml
|
||||
from flask import Flask, g
|
||||
|
||||
# from .models import db
|
||||
from .oauth2 import config_oauth
|
||||
from .routes import bp
|
||||
|
||||
|
@ -10,19 +10,10 @@ from .routes import bp
|
|||
def create_app(config=None):
|
||||
app = Flask(__name__)
|
||||
|
||||
# load default configuration
|
||||
app.config.from_object("website.settings")
|
||||
config = toml.load(os.environ.get("CONFIG", "config.toml"))
|
||||
app.config.from_mapping(config)
|
||||
|
||||
# load environment configuration
|
||||
if "WEBSITE_CONF" in os.environ:
|
||||
app.config.from_envvar("WEBSITE_CONF")
|
||||
|
||||
# load app specified configuration
|
||||
if config is not None:
|
||||
if isinstance(config, dict):
|
||||
app.config.update(config)
|
||||
elif config.endswith(".py"):
|
||||
app.config.from_pyfile(config)
|
||||
app.url_map.strict_slashes = False
|
||||
|
||||
setup_app(app)
|
||||
return app
|
||||
|
@ -31,8 +22,8 @@ def create_app(config=None):
|
|||
def setup_app(app):
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.ldap = ldap.initialize("ldap://ldap")
|
||||
g.ldap.simple_bind_s("cn=admin,dc=mydomain,dc=tld", "admin")
|
||||
g.ldap = ldap.initialize(app.config["LDAP"]["URI"])
|
||||
g.ldap.simple_bind_s(app.config["LDAP"]["BIND_USER"], app.config["LDAP"]["BIND_PW"])
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
|
@ -40,11 +31,5 @@ def setup_app(app):
|
|||
g.ldap.unbind_s()
|
||||
return response
|
||||
|
||||
# # Create tables if they do not exist already
|
||||
# @app.before_first_request
|
||||
# def create_tables():
|
||||
# db.create_all()
|
||||
#
|
||||
# db.init_app(app)
|
||||
config_oauth(app)
|
||||
app.register_blueprint(bp, url_prefix="")
|
||||
|
|
Loading…
Reference in a new issue