-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
60 lines (53 loc) · 1.7 KB
/
cli.py
File metadata and controls
60 lines (53 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import argparse
import os
from dataclasses import dataclass
from utils.logger import logger
__author__ = "Tempesta Technologies, Inc."
__copyright__ = "Copyright (C) 2023-2025 Tempesta Technologies, Inc."
__license__ = "GPL2"
__version__ = "0.1.1"
@dataclass
class CommandLineArgs:
config: str = "/etc/tempesta/webshield/app.env"
log_level: str = "INFO"
verify: bool = False
@classmethod
def parse_args(cls) -> "CommandLineArgs":
"""
Read command line arguments
:return: key-value arguments
"""
parser = argparse.ArgumentParser(
description=f"""
Tempesta WebShield {__version__} (this version is experimental and should not be used in production).
Dynamically analyzes web traffic and blocks bad bots.
""",
epilog="./app.py --config=/etc/tempesta/webshield/config.env",
formatter_class=argparse.RawDescriptionHelpFormatter,
add_help=True,
)
parser.add_argument(
"-c",
"--config",
type=str,
default="/etc/tempesta/webshield/app.env",
help="Path to the config file",
)
parser.add_argument(
"-l",
"--log-level",
type=str,
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
default="INFO",
help="Log level",
)
parser.add_argument(
"--verify",
action="store_true",
help="Verify config params",
)
args = cls(**vars(parser.parse_args()))
if not os.path.exists(args.config):
logger.error(f"Config file not found at path: {args.config}")
exit(1)
return args