Skip to content

Commit

Permalink
fix(sse/stream_access_logs): handle invalid log (#3307)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Jan 19, 2024
1 parent 90ee8c7 commit 0ef4764
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion api/sse/sse_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import logging
from functools import wraps
from io import StringIO
from typing import Generator
Expand All @@ -10,6 +11,8 @@
from sse import tasks
from sse.dataclasses import SSEAccessLogs

logger = logging.getLogger(__name__)

GNUPG_HOME = "/app/.gnupg"


Expand Down Expand Up @@ -64,6 +67,11 @@ def stream_access_logs() -> Generator[SSEAccessLogs, None, None]:
reader = csv.reader(StringIO(decrypted_body.data.decode()))

for row in reader:
yield SSEAccessLogs(*row)
try:
log = SSEAccessLogs(*row)
except TypeError:
logger.warning("Invalid row in SSE access log file: %s", row)
continue
yield log

log_file.delete()
3 changes: 2 additions & 1 deletion api/tests/unit/sse/test_sse_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_stream_access_logs(mocker: MockerFixture, aws_credentials: None) -> Non
first_encrypted_object_data = b"first_bucket_encrypted_data"
first_decrypted_object_data = (
f"{first_log.generated_at},{first_log.api_key}\n"
f"{second_log.generated_at},{second_log.api_key}".encode()
f"{second_log.generated_at},{second_log.api_key}\n"
"some,invalid,log,entry,111,222".encode()
)
second_encrypted_object_data = b"second_bucket_encrypted_data"
second_decrypted_object_data = (
Expand Down

3 comments on commit 0ef4764

@vercel
Copy link

@vercel vercel bot commented on 0ef4764 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-flagsmith.vercel.app
docs-git-main-flagsmith.vercel.app
docs.bullet-train.io
docs.flagsmith.com

@vercel
Copy link

@vercel vercel bot commented on 0ef4764 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0ef4764 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.