From 634a868030b6fc6512d7238b330e1ae265ee1c9d Mon Sep 17 00:00:00 2001 From: Blake DeMarcy Date: Thu, 27 Apr 2017 19:07:18 -0500 Subject: [PATCH] add debug flag and user_map endpoint --- server.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server.py b/server.py index ff6af9d..842a9b3 100644 --- a/server.py +++ b/server.py @@ -9,6 +9,7 @@ import sqlite3 import json dbname = "data.sqlite" +debug = False def api_method(function): """ @@ -44,6 +45,9 @@ def api_method(function): username = cherrypy.request.headers.get("User") auth = cherrypy.request.headers.get("Auth") + if debug: + print("Body: {}\n\n-----------\n{}".format(body, (username, auth))) + if (username and not auth) or (auth and not username): raise BBJParameterError("User or Auth was given without the other.") @@ -182,6 +186,24 @@ class API(object): return user + @api_method + def user_map(self, args, database, user, **kwargs): + """ + Returns an array with all registered user_ids, with the usermap + object populated by their full objects. + """ + users = {user[0] for user in database.execute("SELECT user_id FROM users")} + cherrypy.thread_data.usermap = { + user: db.user_resolve( + database, + user, + externalize=True, + return_false=False) + for user in users + } + return list(users) + + @api_method def user_get(self, args, database, user, **kwargs): """ @@ -528,6 +550,12 @@ if __name__ == "__main__": except IndexError: # flag given but no value exit("thats not how this works, silly! --host 127.0.0.1") + try: + host_spec = argv.index("--debug") + debug = True + except ValueError: + pass + cherrypy.config.update({ "server.socket_port": int(port), "server.socket_host": host