diff --git a/aws_log_parser/aws/s3.py b/aws_log_parser/aws/s3.py index 962a158..969163a 100644 --- a/aws_log_parser/aws/s3.py +++ b/aws_log_parser/aws/s3.py @@ -43,7 +43,7 @@ def read_keys(self, bucket, prefix, endswith=None, regex_filter=None): if endswith and not file["Key"].endswith(endswith): continue - if reo and not reo.match(file): + if reo and not reo.match(file["Key"]): continue yield from self.read_key(bucket, file["Key"]) diff --git a/test/test_interface.py b/test/test_interface.py index 1c397cc..6daa81c 100644 --- a/test/test_interface.py +++ b/test/test_interface.py @@ -28,7 +28,14 @@ def paginate(self, **_): "ETag": '"37c13f9a66a79c2b474356adaf5da1d0"', "Size": 2844, "StorageClass": "STANDARD", - } + }, + { + "Key": f"csv-file.csv{suffix}", + "LastModified": datetime.datetime(2021, 11, 28, 3, 31, 56, tzinfo=tzutc()), + "ETag": '"37c13f9a66a79c2b474356adaf555555"', + "Size": 2844, + "StorageClass": "STANDARD", + }, ], } @@ -63,6 +70,16 @@ def cloudfront_parser(): ) +def test_regex_filter(monkeypatch): + monkeypatch.setattr(S3Service, "client", MockS3Client()) + aws_log_parser = AwsLogParser( + log_type=LogType.CloudFront, + regex_filter="cloudfront", + ) + entries = aws_log_parser.read_url("s3://aws-logs-test-data/") + assert len(list(entries)) == 6 + + def test_parse_file(cloudfront_parser): entries = cloudfront_parser.read_file("test/data/cloudfront-multiple.log") assert len(list(entries)) == 6