Skip to content

Commit

Permalink
Merge pull request #2753 from freelawproject/tweak-ip-in-api-logs
Browse files Browse the repository at this point in the history
Get client IP for API logs from CloudFront
  • Loading branch information
mlissner authored May 12, 2023
2 parents 8dccfba + 0e70549 commit 6f0d926
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
6 changes: 4 additions & 2 deletions cl/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.utils.timezone import now
from django.views.decorators.cache import cache_page
from django.views.decorators.vary import vary_on_headers
from ipware import get_client_ip
from django_ratelimit.core import get_header
from requests import Response
from rest_framework import serializers
from rest_framework.metadata import SimpleMetadata
Expand Down Expand Up @@ -244,7 +244,9 @@ def _get_response_ms(self) -> int:
def _log_request(self, request):
d = date.today().isoformat()
user = request.user
client_ip, is_routable = get_client_ip(request)
client_ip = get_header(request, "CloudFront-Viewer-Address").split(
":"
)[0]
endpoint = resolve(request.path_info).url_name
response_ms = self._get_response_ms()

Expand Down
14 changes: 1 addition & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ django-ses = {extras = ["events"], version = "^3.3.0"}
django-environ = "^0.8.1"
judge-pics = "^2.0.1"
django-admin-cursor-paginator = "^0.1.2"
django-ipware = "^4.0.2"
sentry-sdk = "^1.14.0"
selenium = "4.0.0.a7"
ipython = "^8.10.0"
Expand Down

0 comments on commit 6f0d926

Please sign in to comment.