aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authordesvox <ofunknowndescent@gmail.com>2018-08-05 19:13:41 -0500
committerdesvox <ofunknowndescent@gmail.com>2018-08-05 19:13:41 -0500
commitcba92412a82f0737cf2517412fabb825ed133ccb (patch)
tree114524ff407d6e77bce91c10515b909714e5604b /server.py
parent826c13db98e79e182e4e9106678a934b71d2241d (diff)
downloadbbj-cba92412a82f0737cf2517412fabb825ed133ccb.tar.gz
Allow setting server admins from server's config.json
Diffstat (limited to 'server.py')
-rw-r--r--server.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/server.py b/server.py
index c40640a..f650ecc 100644
--- a/server.py
+++ b/server.py
@@ -12,7 +12,8 @@ dbname = "data.sqlite"
# any values here may be overrided in the config.json. Any values not listed
# here will have no effect on the server.
-app_config = {
+default_config = {
+ "admins": [],
"port": 7099,
"host": "127.0.0.1",
"instance_name": "BBJ",
@@ -20,13 +21,22 @@ app_config = {
"debug": False
}
-
try:
- with open("config.json") as _conf:
- app_config.update(json.load(_conf))
+ with open("config.json", "r") as _in:
+ app_config = json.load(_in)
+ # update the file with new keys if necessary
+ for key, default_value in default_config.items():
+ # The application will never store a config value
+ # as the NoneType, so users may set an option as
+ # null in their file to reset it to default
+ if key not in app_config or app_config[key] == None:
+ app_config[key] = default_value
+# else just use the defaults
except FileNotFoundError:
- with open("config.json", "w") as _conf:
- json.dump(app_config, _conf, indent=2)
+ app_config = default_prefs
+finally:
+ with open("config.json", "w") as _out:
+ json.dump(app_config, _out, indent=2)
def api_method(function):
@@ -192,7 +202,8 @@ class API(object):
"""
return {
"allow_anon": app_config["allow_anon"],
- "instance_name": app_config["instance_name"]
+ "instance_name": app_config["instance_name"],
+ "admins": app_config["admins"]
}
@api_method
@@ -667,10 +678,11 @@ API_CONFIG = {
def run():
- # user anonymity is achieved in the laziest possible way: a literal user
- # named anonymous. may god have mercy on my soul.
_c = sqlite3.connect(dbname)
try:
+ db.set_admins(_c, app_config["admins"])
+ # user anonymity is achieved in the laziest possible way: a literal user
+ # named anonymous. may god have mercy on my soul.
db.anon = db.user_resolve(_c, "anonymous")
if not db.anon:
db.anon = db.user_register(
Un proyecto texto-plano.xyz