summaryrefslogtreecommitdiff
path: root/src/wsgi.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/wsgi.py')
-rwxr-xr-xsrc/wsgi.py71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/wsgi.py b/src/wsgi.py
index 8ab178a..0aff8f4 100755
--- a/src/wsgi.py
+++ b/src/wsgi.py
@@ -10,6 +10,7 @@ import falcon
from db import DictDB
from base64 import b64decode
from wsgiref.simple_server import make_server
+from middleware import middleware_jwt
try:
database = os.environ['COUCHDB_NAME']
@@ -52,41 +53,51 @@ class EPGet(CollectorResource):
out = list()
selectors = dict()
- limit = 25
- skip = 0
- orgs = self.user_auth(req.auth, self._users.read_perms)
+<< << << < HEAD
+ resp.status = falcon.HTTP_200
+ resp.content_type = falcon.MEDIA_JSON
- if not orgs:
- resp.status = falcon.HTTP_401
- resp.text = json.dumps({
- 'status': 'error',
- 'message': 'Invalid username or password\n'
- })
- return
+ print(req.context)
+ if 'domains' in req.context['user']:
+ orgs = req.context['user']['domains']
+== == == =
+ limit = 25
+ skip = 0
- if key:
- out = self._db.get(key)
- resp.text = json.dumps({'status': 'success', 'data': out})
- return
+ orgs = self.user_auth(req.auth, self._users.read_perms)
+>>>>>> > main
- for param in req.params:
- if param == 'limit':
- limit = req.params['limit']
- elif param == 'skip':
- skip = req.params['skip']
- for i in index.indexes:
- for j in i['index']['fields']:
- if j == param:
- selectors[param] = req.params[param]
-
- for org in orgs:
- selectors['domain'] = org
- data = self._db.search(**selectors, limit=limit, skip=skip)
- if data:
- out += data
+ if not orgs:
+ resp.status = falcon.HTTP_401
+ resp.text = json.dumps({
+ 'status': 'error',
+ 'message': 'Invalid username or password\n'
+ })
+ return
+ if key:
+ out = self._db.get(key)
resp.text = json.dumps({'status': 'success', 'data': out})
+ return
+
+ for param in req.params:
+ if param == 'limit':
+ limit = req.params['limit']
+ elif param == 'skip':
+ skip = req.params['skip']
+ for i in index.indexes:
+ for j in i['index']['fields']:
+ if j == param:
+ selectors[param] = req.params[param]
+
+ for org in orgs:
+ selectors['domain'] = org
+ data = self._db.search(**selectors, limit=limit, skip=skip)
+ if data:
+ out += data
+
+ resp.text = json.dumps({'status': 'success', 'data': out})
class EPAdd(CollectorResource):
@@ -145,7 +156,7 @@ def main(port=8000, wsgi_helper=False):
db = DictDB(database, hostname, username, password)
users = authn.UserDB('wsgi_demo_users.yaml')
- app = falcon.App(cors_enable=True)
+ app = falcon.App(cors_enable=True, middleware=middleware_jwt)
app.add_route('/sc/v0/add', EPAdd(db, users))
app.add_route('/sc/v0/get', EPGet(db, users))
app.add_route('/sc/v0/get/{key}', EPGet(db, users))