summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-09-11 12:37:22 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-09-12 14:23:18 +0800
commit7479f29b3d0a613d459cd26b31eab38f00a00b22 (patch)
tree2a763a2de3bd25cdddd49d5efb1eacc7036741e8 /testapi/opnfv_testapi/common
parent28d5b3d14a6354ec170ebaea7f0f6ba342375b61 (diff)
leverage LFID authentication to pod creation
only valid linux foundation user is allowed to create the new pod add owner field in pods to track the pod creator Change-Id: Icada07152069f7c826bfa6122cb86db8c4e3bf68 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/common')
-rw-r--r--testapi/opnfv_testapi/common/check.py17
-rw-r--r--testapi/opnfv_testapi/common/message.py8
2 files changed, 25 insertions, 0 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 9ded48d..e80b1c6 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -11,11 +11,28 @@ import re
from tornado import gen
+from opnfv_testapi.common import constants
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
from opnfv_testapi.db import api as dbapi
+def is_authorized(method):
+ @functools.wraps(method)
+ def wrapper(self, *args, **kwargs):
+ if self.table in ['pods']:
+ testapi_id = self.get_secure_cookie(constants.TESTAPI_ID)
+ if not testapi_id:
+ raises.Unauthorized(message.not_login())
+ user_info = yield dbapi.db_find_one('users', {'user': testapi_id})
+ if not user_info:
+ raises.Unauthorized(message.not_lfid())
+ kwargs['owner'] = testapi_id
+ ret = yield gen.coroutine(method)(self, *args, **kwargs)
+ raise gen.Return(ret)
+ return wrapper
+
+
def valid_token(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
diff --git a/testapi/opnfv_testapi/common/message.py b/testapi/opnfv_testapi/common/message.py
index 951cbaf..8b5c3fb 100644
--- a/testapi/opnfv_testapi/common/message.py
+++ b/testapi/opnfv_testapi/common/message.py
@@ -42,6 +42,14 @@ def invalid_token():
return 'Invalid Token'
+def not_login():
+ return 'TestAPI id is not provided'
+
+
+def not_lfid():
+ return 'Not a valid Linux Foundation Account'
+
+
def no_update():
return 'Nothing to update'