Add logging for decorator webapi_check_local_site when return PERMISSION_DENIED
Review Request #7868 — Created Jan. 15, 2016 and submitted
Add logging for decorator webapi_check_local_site when return PERMISSION_DENIED
decorator webapi_check_local_site covers a large numbers of permission checks. When user does not have permission, we return 403 and we are expecting meaningful output in the server-side logs. Current implementation of the decorator is lack of the logging capability. This patch adds 3 logging statements when the decorator returns PERMISSION_DENIED
I manually tested that the server does log events when
- User is not allowed too access the local site
- User tries to access a local site with invalid token
- User tries to access with a valid token but with no local site name
Description | From | Last Updated |
---|---|---|
Col: 45 W291 trailing whitespace |
reviewbot | |
Col: 71 W291 trailing whitespace |
reviewbot | |
Col: 41 W291 trailing whitespace |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 37 W291 trailing whitespace |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 21 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 41 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 33 E127 continuation line over-indented for visual indent |
reviewbot | |
Python imports should be grouped into three categories, with a blank line between each: Standard library Third-party packages This module … |
david | |
How about: '%s %s by %s: User does not have access to local site %s' % (request.method, request.path_info, request.user.username, local_site_name) |
david | |
How about: '%s %s by %s: API token does not have access to local site %s' % (request.method, request.path_info, request.user.username, … |
david | |
How about: '%s %s by %s: API token is limited to a local site' % (request.method, request.path_info, request.user.username) |
david | |
Col: 37 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 33 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 29 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 37 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 33 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 29 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 45 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 67 W291 trailing whitespace |
reviewbot | |
Col: 49 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 41 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 63 W291 trailing whitespace |
reviewbot | |
Col: 45 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 55 W291 trailing whitespace |
reviewbot | |
Col: 41 E127 continuation line over-indented for visual indent |
reviewbot | |
The arguments within the (...) should be aligned (second and third rows shouldn't be indented), but actually, in the case … |
chipx86 | |
Col: 45 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 45 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 41 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 41 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot | |
Col: 37 E127 continuation line over-indented for visual indent |
reviewbot |
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py
-
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py
- Change Summary:
-
Change bug info
- Bugs:
-
https://hellosplat.com/s/beanbag/tickets/3108/
-
Can you make some changes to your review request description?
What you currently have in the "Description" field is better for "Testing Done". The "Description" field should give an overview of what was wrong, what we want it to do, and how we changed the code to get there. See https://www.reviewboard.org/docs/codebase/dev/writing-good-descriptions/ for a longer explanation and a bunch of examples.
-
Python imports should be grouped into three categories, with a blank line between each:
- Standard library
- Third-party packages
- This module
Plus we start each file with an extra one for
unicode_literals
In this case, that means you should have:
from __future__ import unicode_literals import logging from django.http import HttpRequest ...
-
How about:
'%s %s by %s: User does not have access to local site %s' % (request.method, request.path_info, request.user.username, local_site_name)
-
How about:
'%s %s by %s: API token does not have access to local site %s' % (request.method, request.path_info, request.user.username, local_site_name)
-
How about:
'%s %s by %s: API token is limited to a local site' % (request.method, request.path_info, request.user.username)
- Change Summary:
-
Update description and logging message
- Description:
-
~ Manually tested that the server does log events when
~ - User is not allowed too access the local site ~ Add logging for decorator webapi_check_local_site when return PERMISSION_DENIED
~ decorator webapi_check_local_site covers a large numbers of permission checks. When user does not have permission, we return 403 and we are expecting meaningful output in the server-side logs. Current implementation of the decorator is lack of the logging capability. This patch adds 3 logging statements when the decorator returns PERMISSION_DENIED - - User tries to access a local site with invalid token - - User tries to access with a valid token but with no local site name - Testing Done:
-
~ Manual tested
~ I manually tested that the server does log events when
+ - User is not allowed too access the local site + - User tries to access a local site with invalid token + - User tries to access with a valid token but with no local site name
-
Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py
-
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py
-
-
-
-
Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py
-
-
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: reviewboard/webapi/decorators.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/decorators.py
-
-
The arguments within the
(...)
should be aligned (second and third rows shouldn't be indented), but actually, in the case of logging statements, each of these should just be an argument to the logging call.I'd suggest a rewording of these to make it more clear that the user is being denied access, rather than just that they don't have access. How about:
logging.warning('User "%s" was denied access to Local Site "%s" (%s %s)', request.user, local_site_name, request.method, request.path_info)
Same general format with the ones below.