Correct some codacy errors
This commit is contained in:
parent
dedc1e34a2
commit
434dcf6e4e
4 changed files with 21 additions and 15 deletions
|
@ -105,7 +105,7 @@ try:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
__CAS_FEDERATE_PROVIDERS_LIST = list(settings.CAS_FEDERATE_PROVIDERS.keys())
|
__CAS_FEDERATE_PROVIDERS_LIST = list(settings.CAS_FEDERATE_PROVIDERS.keys())
|
||||||
|
|
||||||
def __CAS_FEDERATE_PROVIDERS_LIST_sort(key):
|
def __cas_federate_providers_list_sort(key):
|
||||||
if len(settings.CAS_FEDERATE_PROVIDERS[key]) > 2:
|
if len(settings.CAS_FEDERATE_PROVIDERS[key]) > 2:
|
||||||
key = settings.CAS_FEDERATE_PROVIDERS[key][2].lower()
|
key = settings.CAS_FEDERATE_PROVIDERS[key][2].lower()
|
||||||
else:
|
else:
|
||||||
|
@ -113,11 +113,11 @@ except AttributeError:
|
||||||
if isinstance(key, six.string_types) or isinstance(key, six.text_type):
|
if isinstance(key, six.string_types) or isinstance(key, six.text_type):
|
||||||
return tuple(
|
return tuple(
|
||||||
int(num) if num else alpha
|
int(num) if num else alpha
|
||||||
for num, alpha in __CAS_FEDERATE_PROVIDERS_LIST_sort.tokenize(key)
|
for num, alpha in __cas_federate_providers_list_sort.tokenize(key)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return key
|
return key
|
||||||
__CAS_FEDERATE_PROVIDERS_LIST_sort.tokenize = re.compile(r'(\d+)|(\D+)').findall
|
__cas_federate_providers_list_sort.tokenize = re.compile(r'(\d+)|(\D+)').findall
|
||||||
__CAS_FEDERATE_PROVIDERS_LIST.sort(key=__CAS_FEDERATE_PROVIDERS_LIST_sort)
|
__CAS_FEDERATE_PROVIDERS_LIST.sort(key=__cas_federate_providers_list_sort)
|
||||||
|
|
||||||
setting_default('CAS_FEDERATE_PROVIDERS_LIST', __CAS_FEDERATE_PROVIDERS_LIST)
|
setting_default('CAS_FEDERATE_PROVIDERS_LIST', __CAS_FEDERATE_PROVIDERS_LIST)
|
||||||
|
|
|
@ -46,7 +46,7 @@ class CASFederateValidateUser(object):
|
||||||
"""test `password` agains the user"""
|
"""test `password` agains the user"""
|
||||||
if self.client is None:
|
if self.client is None:
|
||||||
return False
|
return False
|
||||||
username, attributs, pgtiou = self.client.verify_ticket(ticket)
|
username, attributs = self.client.verify_ticket(ticket)[:2]
|
||||||
if username is not None:
|
if username is not None:
|
||||||
if attributs is None:
|
if attributs is None:
|
||||||
attributs = {}
|
attributs = {}
|
||||||
|
@ -73,7 +73,8 @@ class CASFederateValidateUser(object):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def register_slo(self, username, session_key, ticket):
|
@staticmethod
|
||||||
|
def register_slo(username, session_key, ticket):
|
||||||
FederateSLO.objects.create(
|
FederateSLO.objects.create(
|
||||||
username=username,
|
username=username,
|
||||||
session_key=session_key,
|
session_key=session_key,
|
||||||
|
@ -82,10 +83,10 @@ class CASFederateValidateUser(object):
|
||||||
|
|
||||||
def clean_sessions(self, logout_request):
|
def clean_sessions(self, logout_request):
|
||||||
try:
|
try:
|
||||||
SLOs = self.client.get_saml_slos(logout_request)
|
slos = self.client.get_saml_slos(logout_request)
|
||||||
except NameError:
|
except NameError:
|
||||||
SLOs = []
|
slos = []
|
||||||
for slo in SLOs:
|
for slo in slos:
|
||||||
try:
|
try:
|
||||||
for federate_slo in FederateSLO.objects.filter(ticket=slo.text):
|
for federate_slo in FederateSLO.objects.filter(ticket=slo.text):
|
||||||
session = SessionStore(session_key=federate_slo.session_key)
|
session = SessionStore(session_key=federate_slo.session_key)
|
||||||
|
|
|
@ -73,7 +73,9 @@ def reverse_params(url_name, params=None, **kwargs):
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
def copy_params(get_or_post_params, ignore=set()):
|
def copy_params(get_or_post_params, ignore=None):
|
||||||
|
if ignore is None:
|
||||||
|
ignore = set()
|
||||||
params = {}
|
params = {}
|
||||||
for key in get_or_post_params:
|
for key in get_or_post_params:
|
||||||
if key not in ignore and get_or_post_params[key]:
|
if key not in ignore and get_or_post_params[key]:
|
||||||
|
@ -96,7 +98,9 @@ def set_cookie(response, key, value, max_age):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_current_url(request, ignore_params=set()):
|
def get_current_url(request, ignore_params=None):
|
||||||
|
if ignore_params is None:
|
||||||
|
ignore_params = set()
|
||||||
protocol = 'https' if request.is_secure() else "http"
|
protocol = 'https' if request.is_secure() else "http"
|
||||||
service_url = "%s://%s%s" % (protocol, request.get_host(), request.path)
|
service_url = "%s://%s%s" % (protocol, request.get_host(), request.path)
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
@ -184,11 +188,11 @@ def gen_saml_id():
|
||||||
return _gen_ticket('_')
|
return _gen_ticket('_')
|
||||||
|
|
||||||
|
|
||||||
def get_tuple(tuple, index, default=None):
|
def get_tuple(nuplet, index, default=None):
|
||||||
if tuple is None:
|
if nuplet is None:
|
||||||
return default
|
return default
|
||||||
try:
|
try:
|
||||||
return tuple[index]
|
return nuplet[index]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,8 @@ class FederateAuth(View):
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
return super(FederateAuth, self).dispatch(request, *args, **kwargs)
|
return super(FederateAuth, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_cas_client(self, request, provider):
|
@staticmethod
|
||||||
|
def get_cas_client(request, provider):
|
||||||
if provider in settings.CAS_FEDERATE_PROVIDERS:
|
if provider in settings.CAS_FEDERATE_PROVIDERS:
|
||||||
service_url = utils.get_current_url(request, {"ticket", "provider"})
|
service_url = utils.get_current_url(request, {"ticket", "provider"})
|
||||||
return CASFederateValidateUser(provider, service_url)
|
return CASFederateValidateUser(provider, service_url)
|
||||||
|
|
Loading…
Reference in a new issue