Skip to content

Commit 715308e

Browse files
committed
Add CloudFront support
1 parent f62f640 commit 715308e

3 files changed

Lines changed: 382 additions & 35 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
3+
dist/

faker_cli/cli.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from faker import Faker
22
import click
33
import sys
4-
from faker_cli.templates import S3AccessLogs, S3AccessWriter, CloudTrailLogs
4+
from faker_cli.templates import CloudFrontWriter, S3AccessLogs, S3AccessWriter, CloudTrailLogs, CloudFrontLogs
55

66
from faker_cli.writer import CSVWriter, JSONWriter
77
from typing import List
@@ -21,21 +21,28 @@ def infer_column_names(col_names, col_types: str) -> List[str]:
2121
"json": JSONWriter
2222
}
2323

24+
TEMPLATE_MAPPER = {
25+
"s3access": [S3AccessWriter, "s3_access_log"],
26+
"cloudfront": [CloudFrontWriter, "cloudfront_log"],
27+
}
28+
2429
fake = Faker()
2530
fake.add_provider(S3AccessLogs)
2631
fake.add_provider(CloudTrailLogs)
32+
fake.add_provider(CloudFrontLogs)
2733

2834
@click.command()
2935
@click.option("--num-rows", "-n", default=1, help="Number of rows")
3036
@click.option("--format", "-f", type=click.Choice(["csv", "json"]), default="csv", help="Format of the output")
3137
@click.option("--columns", "-c", help="Column names", default=None, required=False)
32-
@click.option("--template", "-t", help="Template to use", type=click.Choice(["s3access"]), default=None)
38+
@click.option("--template", "-t", help="Template to use", type=click.Choice(["s3access", "cloudfront"]), default=None)
3339
@click.argument("column_types", required=False)
3440
def main(num_rows, format, columns, template, column_types):
3541
if template:
36-
writer = S3AccessWriter(sys.stdout, None)
42+
writer = TEMPLATE_MAPPER[template][0](sys.stdout, None)
43+
log_entry = TEMPLATE_MAPPER[template][1]
3744
for i in range(num_rows):
38-
row = fake.format("s3_access_log")
45+
row = fake.format(log_entry)
3946
writer.write(row)
4047
return
4148

0 commit comments

Comments
 (0)