Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sse/stream_access_logs): handle invalid log #3307

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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