mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge branch 'stretch-unstable' into autopep8
This commit is contained in:
commit
1ce8ea9ffc
3 changed files with 5 additions and 31 deletions
|
@ -75,7 +75,7 @@ class Authenticator(BaseAuthenticator):
|
||||||
|
|
||||||
def authenticate(self, password):
|
def authenticate(self, password):
|
||||||
try:
|
try:
|
||||||
con = ldap.initialize(self.uri)
|
con = ldap.ldapobject.ReconnectLDAPObject(self.uri, retry_max=10, retry_delay=0.5)
|
||||||
if self.userdn:
|
if self.userdn:
|
||||||
con.simple_bind_s(self.userdn, password)
|
con.simple_bind_s(self.userdn, password)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -418,8 +418,8 @@ class MoulinetteError(Exception):
|
||||||
|
|
||||||
"""Moulinette base exception"""
|
"""Moulinette base exception"""
|
||||||
|
|
||||||
def __init__(self, key, __raw_msg__=False, *args, **kwargs):
|
def __init__(self, key, raw_msg=False, *args, **kwargs):
|
||||||
if __raw_msg__:
|
if raw_msg:
|
||||||
msg = key
|
msg = key
|
||||||
else:
|
else:
|
||||||
msg = moulinette.m18n.g(key, *args, **kwargs)
|
msg = moulinette.m18n.g(key, *args, **kwargs)
|
||||||
|
|
|
@ -351,7 +351,7 @@ class _ActionsMapPlugin(object):
|
||||||
self.logout(profile)
|
self.logout(profile)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
raise error_to_response(e)
|
raise HTTPUnauthorizedResponse(e.strerror)
|
||||||
else:
|
else:
|
||||||
# Update dicts with new values
|
# Update dicts with new values
|
||||||
s_hashes[profile] = s_hash
|
s_hashes[profile] = s_hash
|
||||||
|
@ -438,7 +438,7 @@ class _ActionsMapPlugin(object):
|
||||||
try:
|
try:
|
||||||
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
ret = self.actionsmap.process(arguments, timeout=30, route=_route)
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
raise error_to_response(e)
|
raise HTTPBadRequestResponse(e.strerror)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, HTTPResponse):
|
if isinstance(e, HTTPResponse):
|
||||||
raise e
|
raise e
|
||||||
|
@ -522,38 +522,12 @@ class HTTPUnauthorizedResponse(HTTPResponse):
|
||||||
super(HTTPUnauthorizedResponse, self).__init__(output, 401)
|
super(HTTPUnauthorizedResponse, self).__init__(output, 401)
|
||||||
|
|
||||||
|
|
||||||
class HTTPForbiddenResponse(HTTPResponse):
|
|
||||||
|
|
||||||
def __init__(self, output=''):
|
|
||||||
super(HTTPForbiddenResponse, self).__init__(output, 403)
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPErrorResponse(HTTPResponse):
|
class HTTPErrorResponse(HTTPResponse):
|
||||||
|
|
||||||
def __init__(self, output=''):
|
def __init__(self, output=''):
|
||||||
super(HTTPErrorResponse, self).__init__(output, 500)
|
super(HTTPErrorResponse, self).__init__(output, 500)
|
||||||
|
|
||||||
|
|
||||||
def error_to_response(error):
|
|
||||||
"""Convert a MoulinetteError to relevant HTTP response."""
|
|
||||||
if error.errno == errno.EPERM:
|
|
||||||
return HTTPForbiddenResponse(error.strerror)
|
|
||||||
elif error.errno == errno.EACCES:
|
|
||||||
return HTTPUnauthorizedResponse(error.strerror)
|
|
||||||
# Client-side error
|
|
||||||
elif error.errno in [errno.ENOENT, errno.ESRCH, errno.ENXIO, errno.EEXIST,
|
|
||||||
errno.ENODEV, errno.EINVAL, errno.ENOPKG, errno.EDESTADDRREQ]:
|
|
||||||
return HTTPBadRequestResponse(error.strerror)
|
|
||||||
# Server-side error
|
|
||||||
elif error.errno in [errno.EIO, errno.EBUSY, errno.ENODATA, errno.EINTR,
|
|
||||||
errno.ENETUNREACH]:
|
|
||||||
return HTTPErrorResponse(error.strerror)
|
|
||||||
else:
|
|
||||||
logger.debug('unknown relevant response for error [%s] %s',
|
|
||||||
error.errno, error.strerror)
|
|
||||||
return HTTPErrorResponse(error.strerror)
|
|
||||||
|
|
||||||
|
|
||||||
def format_for_response(content):
|
def format_for_response(content):
|
||||||
"""Format the resulted content of a request for the HTTP response."""
|
"""Format the resulted content of a request for the HTTP response."""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|
Loading…
Add table
Reference in a new issue