diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2018-03-09 16:35:22 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2018-03-09 18:06:09 +0800 |
commit | 1a95c1e6b33d9b3efcfd92e1de64feee7e9b5c68 (patch) | |
tree | 61488ece232657c6693425eabc07ad6ca4b3af8e /testapi/testapi-client/testapiclient/utils/identity.py | |
parent | cc29ae1cd41d1f403511730d5ba44dded967fb12 (diff) |
restructure testapiclient project
Change-Id: I13d24ce7b436f203a66fe14f4930e58b3ab1193c
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/testapi-client/testapiclient/utils/identity.py')
-rw-r--r-- | testapi/testapi-client/testapiclient/utils/identity.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/utils/identity.py b/testapi/testapi-client/testapiclient/utils/identity.py new file mode 100644 index 0000000..2aeb87a --- /dev/null +++ b/testapi/testapi-client/testapiclient/utils/identity.py @@ -0,0 +1,38 @@ +import functools +import os +import urllib + +import requests + +from testapiclient.utils import user + + +def _authenticate(username, password): + session = requests.Session() + hostname = '{}{}{}'.format(os.environ.get('testapi_cas_auth_url'), + urllib.quote(os.environ.get('testapi_url')), + os.environ.get('testapi_cas_signin_return')) + data = { + 'name': username, + 'pass': password, + 'form_id': 'user_login' + } + response = session.post(hostname, data) + if "login" not in response.text: + user.User.session = session + return response + + +def authenticate(xstep): + @functools.wraps(xstep) + def wrapper(self, parsed_args): + if(user.User.session is None): + username = parsed_args.u + password = parsed_args.p + if(username and password): + response = _authenticate(username, password) + if "login" in response.text: + print "Authentication has failed." + return + xstep(self, parsed_args) + return wrapper |