Lines 70-75
def clean_license_output(out):
|
Link Here
|
---|
|
70 |
|
70 |
|
71 |
|
71 |
|
72 |
def application(environ, start_response): |
72 |
def application(environ, start_response): |
|
|
73 |
|
74 |
class LdapLicenceFetchError(Exception): |
75 |
pass |
76 |
|
73 |
def _error(message, trace=None): |
77 |
def _error(message, trace=None): |
74 |
return { |
78 |
return { |
75 |
'status': 500, |
79 |
'status': 500, |
Lines 92-104
def application(environ, start_response):
|
Link Here
|
---|
|
92 |
|
96 |
|
93 |
# output the license upon GET request |
97 |
# output the license upon GET request |
94 |
if environ.get('REQUEST_METHOD') == 'GET': |
98 |
if environ.get('REQUEST_METHOD') == 'GET': |
|
|
99 |
cmd = ['usr/bin/sudo', '/usr/bin/univention-ldapsearch', '-LLL', 'objectClass=univentionLicense'] |
100 |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
95 |
try: |
101 |
try: |
96 |
out = subprocess.check_output(['/usr/bin/sudo', '/usr/bin/univention-ldapsearch', '-LLL', 'objectClass=univentionLicense']) |
102 |
out, err = proc.communicate() |
|
|
103 |
if proc.returncode: |
104 |
raise LdapLicenceFetchError('cmd: {}\nreturn code: {}\nstdout: {}\nstderr: {}'.format(cmd, proc.returncode, out, err)) |
97 |
out = clean_license_output(out) |
105 |
out = clean_license_output(out) |
98 |
return _finish(data=out) |
106 |
return _finish(data=out) |
99 |
except subprocess.CalledProcessError as exc: |
107 |
except LdapLicenceFetchError as exc: |
100 |
_log('Failed to read license data from LDAP:\n%s' % exc) |
108 |
return _finish('500 Internal Server Error', data=_error('Could not fetch licence from ldap', traceback.format_exc())) |
101 |
return _finish('500 Internal Server Error', _error('Failed to read license data from LDAP:\n%s' % exc)) |
|
|
102 |
except Exception as exc: |
109 |
except Exception as exc: |
103 |
return _finish('500 Internal Server Error', data=_error(str(exc), traceback.format_exc())) |
110 |
return _finish('500 Internal Server Error', data=_error(str(exc), traceback.format_exc())) |
104 |
|
111 |
|