Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
HTTP/1.1 204 No Content
Session does not exist::
HTTP/1.1 404 Not Found
.. rubric:: Example
::
curl -v -H "Httpkom-Connection: 033556ee-3e52-423f-9c9a-d85aed7688a1" \\
-X DELETE "http://localhost:5001/lyskom/sessions/abc123"
"""
try:
await g.ksession.disconnect(session_no)
# We should delete the connection if we're no longer connected
# (i.e. we disconnected the curent session).
if not g.ksession.is_connected():
_delete_komsession(g.connection_id)
return empty_response(204)
except komerror.UndefinedSession as ex:
return error_response(404, kom_error=ex)
.. rubric:: Example
::
curl -v -X POST H "Content-Type: application/json" \\
-d '{ "name": "Oskar Testperson", "passwd": "test123" }' \\
http://localhost:5001/lyskom/persons/
"""
request_json = await request.json
name = request_json['name']
passwd = request_json['passwd']
try:
kom_person = await g.ksession.create_person(name, passwd)
return jsonify(await to_dict(kom_person, g.ksession)), 201
except komerror.Error as ex:
return error_response(400, kom_error=ex)
Conference does not exist::
HTTP/1.0 404 NOT FOUND
{ TODO: error stuff }
.. rubric:: Example
::
curl -v -X GET "http://localhost:5001/lyskom/conferences/14506?micro=true"
"""
try:
micro = get_bool_arg_with_default(request.args, 'micro', True)
return jsonify(await to_dict(await g.ksession.get_conference(conf_no, micro),
g.ksession))
except komerror.UndefinedConference as ex:
return error_response(404, kom_error=ex)
def decorated(*args, **kwargs):
g.connection_id = _get_connection_id_from_request()
return f(*args, **kwargs)
return decorated
async def decorated(*args, **kwargs):
g.ksession = _get_komsession(g.connection_id)
if g.ksession is None:
return empty_response(403)
try:
return await f(*args, **kwargs)
except KomSessionNotConnected:
_delete_komsession(g.connection_id)
return empty_response(403)
except socket.error as e:
(eno, msg) = e.args
if eno in (errno.EPIPE, errno.ECONNRESET):
_delete_komsession(g.connection_id)
return empty_response(403)
else:
raise
return decorated
async def decorated(*args, **kwargs):
if await g.ksession.is_logged_in():
return await f(*args, **kwargs)
else:
return empty_response(401)
return decorated
def get_db():
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
}
.. rubric:: Example
::
curl -v -X GET -H "Content-Type: application/json" \\
"http://localhost:5001/lyskom/conferences/?name=osk%20t&want-confs=false"
"""
name = request.args['name']
want_pers = get_bool_arg_with_default(request.args, 'want-pers', True)
want_confs = get_bool_arg_with_default(request.args, 'want-confs', True)
try:
lookup = await g.ksession.lookup_name(name, want_pers, want_confs)
confs = [ dict(conf_no=t[0], conf_name=t[1]) for t in lookup ]
return jsonify(dict(conferences=confs))
except komerror.Error as ex:
return error_response(400, kom_error=ex)
def after_request(response):
request_info = g.request_info
request_info.update_response_status(response)
# TODO:handle to print out request instrumentation in non-JSON mode
self.request_logger.info("", extra={'request_info': request_info})
return response
def pull_server_id(endpoint, values):
_servers = dict()
for i, server in enumerate(current_app.config['HTTPKOM_LYSKOM_SERVERS']):
_servers[server[0]] = Server(server[0], i, server[1], server[2], server[3])
server_id = values.pop('server_id')
if server_id in _servers:
g.server = _servers[server_id]
else:
# No such server
abort(404)