11from faker import Faker
22import click
33import sys
4- from faker_cli .templates import S3AccessLogs , S3AccessWriter , CloudTrailLogs
4+ from faker_cli .templates import CloudFrontWriter , S3AccessLogs , S3AccessWriter , CloudTrailLogs , CloudFrontLogs
55
66from faker_cli .writer import CSVWriter , JSONWriter
77from 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+
2429fake = Faker ()
2530fake .add_provider (S3AccessLogs )
2631fake .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 )
3440def 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