aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-27 19:07:18 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-27 19:07:18 -0500
commit634a868030b6fc6512d7238b330e1ae265ee1c9d (patch)
tree87a20b3097f580e64397227b167329c5b9136b03 /server.py
parent7267a700f881980c852502e8b1ce51abceebafcd (diff)
downloadbbj-634a868030b6fc6512d7238b330e1ae265ee1c9d.tar.gz
add debug flag and user_map endpoint
Diffstat (limited to 'server.py')
-rw-r--r--server.py28
1 files changed, 28 insertions, 0 deletions
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.")
@@ -183,6 +187,24 @@ class API(object):
@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):
"""
Retreive an external user object for the given `user`.
@@ -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
Un proyecto texto-plano.xyz