add debug flag and user_map endpoint

pull/4/head
Blake DeMarcy 2017-04-27 19:07:18 -05:00
parent 7267a700f8
commit 634a868030
1 changed files with 28 additions and 0 deletions

View File

@ -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