From b4a30b3f8092ffc507b475818eb282e9dd435b69 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 17 Aug 2023 13:57:32 +0200 Subject: [PATCH] appstore: implement a proper config mechanism --- store/.gitignore | 1 + store/app.py | 26 +++++++++++++++++++------- store/config.toml.example | 5 +++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 store/.gitignore create mode 100644 store/config.toml.example diff --git a/store/.gitignore b/store/.gitignore new file mode 100644 index 0000000..5b6c096 --- /dev/null +++ b/store/.gitignore @@ -0,0 +1 @@ +config.toml diff --git a/store/app.py b/store/app.py index d9cf32d..6837588 100644 --- a/store/app.py +++ b/store/app.py @@ -1,4 +1,4 @@ -from flask import Flask, send_from_directory, render_template, session, redirect, request +import toml import base64 import hashlib import hmac @@ -6,16 +6,28 @@ import os import random import urllib import json -from settings import DISCOURSE_SSO_SECRET, DISCOURSE_SSO_ENDPOINT, CALLBACK_URL_AFTER_LOGIN_ON_DISCOURSE +import sys +from flask import Flask, send_from_directory, render_template, session, redirect, request + app = Flask(__name__) - -app.debug = True -app.config["DEBUG"] = True -app.config['TEMPLATES_AUTO_RELOAD'] = True - catalog = json.load(open("apps.json")) catalog['categories'] = {c['id']:c for c in catalog['categories']} +try: + config = toml.loads(open("config.toml").read()) + DISCOURSE_SSO_SECRET = config["DISCOURSE_SSO_SECRET"] + DISCOURSE_SSO_ENDPOINT = config["DISCOURSE_SSO_ENDPOINT"] + CALLBACK_URL_AFTER_LOGIN_ON_DISCOURSE = config["CALLBACK_URL_AFTER_LOGIN_ON_DISCOURSE"] +except Exception as e: + print("You should create a config.toml with the appropriate key/values, cf config.toml.example") + print(e) + sys.exit(1) + +if config.get("DEBUG"): + app.debug = True + app.config["DEBUG"] = True + app.config['TEMPLATES_AUTO_RELOAD'] = True + category_color = { "synchronization": "sky", "publishing": "yellow", diff --git a/store/config.toml.example b/store/config.toml.example new file mode 100644 index 0000000..f6e5617 --- /dev/null +++ b/store/config.toml.example @@ -0,0 +1,5 @@ +# This secret is configured in Discourse +DISCOURSE_SSO_SECRET = "abcdefghijklmnopqrstuvwxyz1234567890" +DISCOURSE_SSO_ENDPOINT = "https://forum.yunohost.org/session/sso_provider" +CALLBACK_URL_AFTER_LOGIN_ON_DISCOURSE = "http://localhost:5000/sso_login_callback" +DEBUG = false