-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
48 lines (31 loc) · 1.11 KB
/
lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import cherrypy
from cherrypy import log
import json
import requests
from xml.etree import ElementTree
# get list of parameters from Web Service invocation
def get_parameters(params, pname):
parameters = params[pname]
if type(parameters) == str:
parameters = [parameters]
return parameters
def handle_error(code, message, ctx="HTTP"):
if code == 500:
traceback = True
else:
traceback = False
log.error(msg=message, context=ctx, traceback=traceback)
cherrypy.response.status = code
ctype = "application/json;charset=utf-8"
cherrypy.response.headers["Content-Type"] = ctype
return json.dumps({"code": code, "message": message}).encode('utf8')
def singlequote(value):
return "'" + value + "'"
def validate(headers, cas_server, serviceID):
# FIXME
return True
token = headers["X-Auth-Token"]
url = (cas_server + "/p3/serviceValidate?service=" + serviceID + "&ticket=" + token)
r = requests.get(url, verify="/etc/ssl/certs/ca.pem")
root = list(ElementTree.fromstring(r.content))
return root[0].tag.endswith("authenticationSuccess")