add debug flag and user_map endpoint
parent
7267a700f8
commit
634a868030
28
server.py
28
server.py
|
@ -9,6 +9,7 @@ import sqlite3
|
||||||
import json
|
import json
|
||||||
|
|
||||||
dbname = "data.sqlite"
|
dbname = "data.sqlite"
|
||||||
|
debug = False
|
||||||
|
|
||||||
def api_method(function):
|
def api_method(function):
|
||||||
"""
|
"""
|
||||||
|
@ -44,6 +45,9 @@ def api_method(function):
|
||||||
username = cherrypy.request.headers.get("User")
|
username = cherrypy.request.headers.get("User")
|
||||||
auth = cherrypy.request.headers.get("Auth")
|
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):
|
if (username and not auth) or (auth and not username):
|
||||||
raise BBJParameterError("User or Auth was given without the other.")
|
raise BBJParameterError("User or Auth was given without the other.")
|
||||||
|
|
||||||
|
@ -182,6 +186,24 @@ class API(object):
|
||||||
return user
|
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
|
@api_method
|
||||||
def user_get(self, args, database, user, **kwargs):
|
def user_get(self, args, database, user, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -528,6 +550,12 @@ if __name__ == "__main__":
|
||||||
except IndexError: # flag given but no value
|
except IndexError: # flag given but no value
|
||||||
exit("thats not how this works, silly! --host 127.0.0.1")
|
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({
|
cherrypy.config.update({
|
||||||
"server.socket_port": int(port),
|
"server.socket_port": int(port),
|
||||||
"server.socket_host": host
|
"server.socket_host": host
|
||||||
|
|
Loading…
Reference in New Issue