PEP008 conformance improvements
This commit is contained in:
Родитель
d0377810f6
Коммит
c908ea5c81
|
@ -17,7 +17,7 @@ from django.conf import settings
|
|||
|
||||
def user_has_claim(func):
|
||||
def wrap(request, *args, **kwargs):
|
||||
# This check is in addition to the check done by openresty and acts as
|
||||
# This check is in addition to the check done by OpenResty and acts as
|
||||
# a redundant check for added security
|
||||
groups = request.META.get(settings.GROUPS_META_VAR, '').split('|')
|
||||
if (hasattr(request, 'user') and request.user.is_authenticated()
|
||||
|
@ -31,10 +31,10 @@ def user_has_claim(func):
|
|||
|
||||
|
||||
@user_has_claim
|
||||
def detail(request, id):
|
||||
def detail(request, id_value):
|
||||
error = None
|
||||
success = request.GET.get('success', False)
|
||||
disk = get_object_or_404(site_models.EncryptedDisk, id=id)
|
||||
disk = get_object_or_404(site_models.EncryptedDisk, id=id_value)
|
||||
if success:
|
||||
success = 'Successfully Uploaded'
|
||||
if request.method == "POST":
|
||||
|
@ -49,33 +49,35 @@ def detail(request, id):
|
|||
if f.user:
|
||||
f.email_address = f.user.username
|
||||
f.save()
|
||||
items = []
|
||||
items.append({'suser': request.user})
|
||||
items.append({'cs1Label': 'asset_tag'})
|
||||
items.append({'cs1': disk.asset_tag})
|
||||
items.append({'cs2Label': 'id'})
|
||||
items.append({'cs2': id})
|
||||
items.append({'duser': f.email_address})
|
||||
items = [
|
||||
{'suser': request.user},
|
||||
{'cs1Label': 'asset_tag'},
|
||||
{'cs1': disk.asset_tag},
|
||||
{'cs2Label': 'id'},
|
||||
{'cs2': id_value},
|
||||
{'duser': f.email_address}
|
||||
]
|
||||
log_cef("AdminUpdate", "Desktop Admin Updated info for %s - %s" % (f.email_address, f.asset_tag), items) # noqa
|
||||
success = 1
|
||||
return HttpResponseRedirect('?success=%s' % success)
|
||||
except ValueError:
|
||||
error = 'Validation Failed'
|
||||
except Exception, e:
|
||||
error = 'An unknown error has occured %s' % e
|
||||
error = 'An unknown error has occurred %s' % e
|
||||
else:
|
||||
form = forms.UploadFormDesktop(instance=disk)
|
||||
items = []
|
||||
items.append({'suser': request.user})
|
||||
items.append({'cs1Label': 'asset_tag'})
|
||||
items.append({'cs1': disk.asset_tag})
|
||||
items.append({'cs2Label': 'id'})
|
||||
items.append({'cs2': id})
|
||||
items.append({'duser': disk.email_address})
|
||||
items = [
|
||||
{'suser': request.user},
|
||||
{'cs1Label': 'asset_tag'},
|
||||
{'cs1': disk.asset_tag},
|
||||
{'cs2Label': 'id'},
|
||||
{'cs2': id_value},
|
||||
{'duser': disk.email_address}
|
||||
]
|
||||
log_cef("AdminView", "Desktop Admin viewed info for %s - %s" % (disk.email_address, disk.asset_tag), items) # noqa
|
||||
return render(request, 'detail.html', {
|
||||
'form': form,
|
||||
'id': id,
|
||||
'id': id_value,
|
||||
'success': success,
|
||||
'error': error,
|
||||
})
|
||||
|
@ -97,17 +99,17 @@ def upload(request):
|
|||
if f.user:
|
||||
f.email_address = f.user.username
|
||||
f.save()
|
||||
items = []
|
||||
items.append({'user': request.user})
|
||||
items.append({'asset_tag': f.asset_tag})
|
||||
items.append({'duser': f.email_address})
|
||||
items = [
|
||||
{'user': request.user},
|
||||
{'asset_tag': f.asset_tag},
|
||||
{'duser': f.email_address}
|
||||
]
|
||||
log_cef("AdminCreate", "Desktop Admin Created key for key for %s - %s" % (f.email_address, f.asset_tag), items) # noqa
|
||||
return HttpResponseRedirect(reverse('desktop_admin'))
|
||||
success = 1
|
||||
except ValueError:
|
||||
error = 'Validation Failed'
|
||||
except Exception, e:
|
||||
error = 'An unknown error has occured %s' % e
|
||||
error = 'An unknown error has occurred %s' % e
|
||||
else:
|
||||
form = forms.UploadFormDesktopUpload()
|
||||
return render(request, 'desktop_admin_upload.html', {
|
||||
|
@ -169,9 +171,5 @@ def download_attach(request, filename):
|
|||
response['Content-Disposition'] = 'inline; filename=%s' % filename
|
||||
if content_encoding:
|
||||
response['Content-Encoding'] = content_encoding
|
||||
items = []
|
||||
items.append({'suser': request.user})
|
||||
items.append({'cs1Label': 'filename'})
|
||||
items.append({'cs1': filename})
|
||||
log_cef("AdminDownload", "Desktop Admin downloaded file %s" % filename)
|
||||
return response
|
||||
|
|
|
@ -6,16 +6,16 @@ from apps.site import forms
|
|||
from apps.site.cef import log_cef
|
||||
|
||||
|
||||
def remote_user_login_required(function):
|
||||
def remote_user_login_required(func):
|
||||
# https://www.adelton.com/django/external-authentication-for-django-projects#idm139850931541280
|
||||
# https://code.djangoproject.com/ticket/25164
|
||||
def wrap(request, *args, **kwargs):
|
||||
if hasattr(request, 'user') and request.user.is_authenticated():
|
||||
return function(request, *args, **kwargs)
|
||||
return func(request, *args, **kwargs)
|
||||
else:
|
||||
raise PermissionDenied
|
||||
wrap.__doc__ = function.__doc__
|
||||
wrap.__name__ = function.__name__
|
||||
wrap.__doc__ = func.__doc__
|
||||
wrap.__name__ = func.__name__
|
||||
return wrap
|
||||
|
||||
|
||||
|
@ -23,8 +23,7 @@ def remote_user_login_required(function):
|
|||
def upload(request):
|
||||
error = None
|
||||
success = request.GET.get('success', False)
|
||||
items = []
|
||||
items.append({'suser': request.user})
|
||||
items = [{'suser': request.user}]
|
||||
log_cef("UserUpload", "User uploaded new key", items)
|
||||
if success:
|
||||
success = 'Successfully Uploaded'
|
||||
|
@ -36,15 +35,16 @@ def upload(request):
|
|||
f.email_address = request.user.username
|
||||
f.save()
|
||||
success = 1
|
||||
items = []
|
||||
items.append({'user': request.user})
|
||||
items.append({'asset_tag': f.asset_tag})
|
||||
items = [
|
||||
{'user': request.user},
|
||||
{'asset_tag': f.asset_tag}
|
||||
]
|
||||
log_cef("UserUpload", "User uploaded new key", items)
|
||||
return HttpResponseRedirect('?success=%s' % success)
|
||||
except ValueError:
|
||||
error = 'Validation Failed'
|
||||
except Exception, e:
|
||||
error = 'An unknown error has occured %s' % e
|
||||
error = 'An unknown error has occurred %s' % e
|
||||
else:
|
||||
form = forms.UploadFormUser()
|
||||
return render(request, 'upload.html', {
|
||||
|
|
|
@ -3,13 +3,14 @@ import syslog
|
|||
from settings import PROG_NAME
|
||||
|
||||
|
||||
def log_cef(message_name, message_description, items=[]):
|
||||
FACILITY = syslog.LOG_LOCAL4
|
||||
syslog.openlog(PROG_NAME, 0, FACILITY)
|
||||
def log_cef(message_name, message_description, items=None):
|
||||
facility = syslog.LOG_LOCAL4
|
||||
syslog.openlog(PROG_NAME, 0, facility)
|
||||
label_string = ''
|
||||
for row in items:
|
||||
for key, value in row.items():
|
||||
label_string = label_string.join("%s=%s " % (key, value))
|
||||
cefmsg = 'CEF:0|Mozilla|%s|1.0|%s|%s|5|%s dhost=%s'% (PROG_NAME, message_name, message_description, label_string, os.uname()[1]) # noqa
|
||||
if items is not None:
|
||||
for row in items:
|
||||
for key, value in row.items():
|
||||
label_string = label_string.join("%s=%s " % (key, value))
|
||||
cefmsg = 'CEF:0|Mozilla|%s|1.0|%s|%s|5|%s dhost=%s' % (PROG_NAME, message_name, message_description, label_string, os.uname()[1]) # noqa
|
||||
syslog.syslog(syslog.LOG_INFO, cefmsg)
|
||||
syslog.closelog()
|
||||
|
|
|
@ -32,11 +32,12 @@ def login_view(request):
|
|||
if user:
|
||||
login(request, user)
|
||||
if user is not None:
|
||||
items = []
|
||||
items.append({'suser': username})
|
||||
items.append({'cs1Label': 'LoginSuccess'})
|
||||
items.append({'cs1': 'True'})
|
||||
log_cef("LoginSuccess", "Login Succeeded For %s" % user.email, items) # noqa
|
||||
items = [
|
||||
{'suser': username},
|
||||
{'cs1Label': 'LoginSuccess'},
|
||||
{'cs1': 'True'}
|
||||
]
|
||||
log_cef("LoginSuccess", "Login Succeeded For %s" % user.email, items) # noqa
|
||||
if hasattr(user, 'is_desktop') and user.is_desktop:
|
||||
"""
|
||||
Per bug #822396
|
||||
|
@ -49,10 +50,11 @@ def login_view(request):
|
|||
else:
|
||||
return HttpResponseRedirect(reverse('upload'))
|
||||
else:
|
||||
items = []
|
||||
items.append({'suser': username})
|
||||
items.append({'cs1Label': 'LoginSuccess'})
|
||||
items.append({'cs1': 'False'})
|
||||
items = [
|
||||
{'suser': username},
|
||||
{'cs1Label': 'LoginSuccess'},
|
||||
{'cs1': 'False'}
|
||||
]
|
||||
log_cef("LoginFail", "Login Failed For %s" % username, items)
|
||||
error = 'Invalid Username/Password'
|
||||
else:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.contrib.auth.middleware import RemoteUserMiddleware
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class CustomRemoteUserMiddleware(RemoteUserMiddleware):
|
||||
"""
|
||||
Middleware for utilizing Web-server-provided authentication.
|
||||
|
@ -9,5 +10,5 @@ class CustomRemoteUserMiddleware(RemoteUserMiddleware):
|
|||
which is used to fetch the username from and instead uses the META variable
|
||||
defined in the REMOTE_USER_META_VAR setting
|
||||
"""
|
||||
header=getattr(
|
||||
header = getattr(
|
||||
settings, 'REMOTE_USER_META_VAR', RemoteUserMiddleware.header)
|
||||
|
|
17
oidc/auth.py
17
oidc/auth.py
|
@ -1,17 +0,0 @@
|
|||
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class CustomOIDCAuthenticationBackend(OIDCAuthenticationBackend):
|
||||
def verify_claims(self, claims):
|
||||
super(CustomOIDCAuthenticationBackend, self).verify_claims(claims)
|
||||
try:
|
||||
claim_group_path = settings.OIDC_CLAIM_GROUPS_PATH
|
||||
except AttributeError:
|
||||
claim_group_path = None
|
||||
|
||||
if claim_group_path:
|
||||
self.request.session['claim_groups'] = claims[claim_group_path]
|
||||
# claims don't need verified for access, just need to get them
|
||||
# to check for roles later
|
||||
return True
|
|
@ -2,8 +2,9 @@ from django.conf import settings
|
|||
|
||||
|
||||
def has_admin_claim_group(request):
|
||||
r_context = {}
|
||||
r_context['has_admin_claim_group'] = False
|
||||
r_context = {
|
||||
'has_admin_claim_group': False
|
||||
}
|
||||
try:
|
||||
c_group = settings.OIDC_DESKTOP_CLAIM_GROUP
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ class DatabaseStorage(Storage):
|
|||
return result
|
||||
|
||||
def size(self, name):
|
||||
"Get the size of the given filename or raise ObjectDoesNotExist."
|
||||
"""Get the size of the given filename or raise ObjectDoesNotExist."""
|
||||
query = 'SELECT %(size_column)s FROM %(table)s ' + \
|
||||
'WHERE %(name_column)s = %%s'
|
||||
query %= self.__dict__
|
||||
|
|
Загрузка…
Ссылка в новой задаче