Moved custom conf files to their own directory

main
Ben Busby 2020-06-02 14:38:29 -06:00
parent b6fb4723f9
commit 64af72abb5
3 changed files with 8 additions and 2 deletions

2
.gitignore vendored
View File

@ -3,10 +3,12 @@ venv/
__pycache__/
*.pyc
*.pem
*.conf
config.json
test/static
flask_session/
app/static/config
app/static/custom_config
# pip stuff
build/

View File

@ -12,12 +12,16 @@ app.config['VERSION_NUMBER'] = '0.2.0'
app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__)))
app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config['APP_ROOT'], 'static'))
app.config['CONFIG_PATH'] = os.getenv('CONFIG_VOLUME', app.config['STATIC_FOLDER'] + '/config')
app.config['USER_CONFIG'] = os.path.join(app.config['STATIC_FOLDER'], 'custom_config')
app.config['SESSION_FILE_DIR'] = app.config['CONFIG_PATH']
app.config['SESSION_COOKIE_SECURE'] = True
if not os.path.exists(app.config['CONFIG_PATH']):
os.makedirs(app.config['CONFIG_PATH'])
if not os.path.exists(app.config['USER_CONFIG']):
os.makedirs(app.config['USER_CONFIG'])
sess = Session()
sess.init_app(app)

View File

@ -157,7 +157,7 @@ def config():
return json.dumps(g.user_config.__dict__)
elif request.method == 'PUT':
if 'name' in request.args:
config_pkl = os.path.join(app.config['CONFIG_PATH'], request.args.get('name'))
config_pkl = os.path.join(app.config['USER_CONFIG'], request.args.get('name'))
session['config'] = pickle.load(open(config_pkl, 'rb')) if os.path.exists(config_pkl) else session['config']
return json.dumps(session['config'])
else:
@ -168,7 +168,7 @@ def config():
config_data['url'] = g.user_config.url
if 'name' in request.args:
pickle.dump(config_data, open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'wb'))
pickle.dump(config_data, open(os.path.join(app.config['USER_CONFIG'], request.args.get('name')), 'wb'))
session['config'] = config_data
return redirect(config_data['url'])