You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@warble.apache.org by hu...@apache.org on 2018/06/26 15:21:09 UTC
[incubator-warble-server] 02/07: switch clients (agents/nodes) to
their own sub-class
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git
commit 55b0234f7d10ca95375d8b0fb02a6b9329b1b29a
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 09:49:12 2018 -0500
switch clients (agents/nodes) to their own sub-class
this way we can just check:
if session.client: dostuff()
or
if session.user: dohumanstuff()
---
api/plugins/session.py | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/api/plugins/session.py b/api/plugins/session.py
index bb3a406..d302b45 100644
--- a/api/plugins/session.py
+++ b/api/plugins/session.py
@@ -29,6 +29,7 @@ import traceback
import http.cookies
import uuid
import time
+import plugins.registry
class WarbleSession(object):
@@ -67,6 +68,7 @@ class WarbleSession(object):
"""
self.config = config
self.user = None
+ self.client = None
self.DB = DB
self.headers = [('Content-Type', 'application/json')]
self.cookie = None
@@ -141,15 +143,10 @@ class WarbleSession(object):
elif 'HTTP_APIKEY' in environ:
cookie = environ['HTTP_APIKEY']
if re.match(r"^[-a-f0-9]+$", cookie): # Validate cookie, must follow UUID4 specs
- registry_conn = self.DB.sqlite.open('nodes.db')
- rc = registry_conn.cursor()
- rc.execute("SELECT * FROM `registry` WHERE `apikey` = ? LIMIT 1", (cookie,))
- ndoc = rc.fetchone()
- if ndoc:
- self.user = {k:ndoc[k] for k in ndoc.keys()}
- self.user['human'] = False
- self.user['userid'] = 'node:%s' % ndoc['id']
- self.user['userlevel'] = 'robbit'
+ try:
+ self.client = plugins.registry.node(self, cookie)
+ except:
+ pass
if not cookie:
cookie = self.newCookie()
self.cookie = cookie
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org