From a9b23a6a1dc1d319d77cbdfe03ba1710b4201711 Mon Sep 17 00:00:00 2001 From: Parul Date: Tue, 13 Feb 2024 08:08:44 -0800 Subject: [PATCH] wrapper class for Docker --- .gitignore | 1 - Dockerfile | 2 +- cli.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 cli.py diff --git a/.gitignore b/.gitignore index 0da3226..7961b79 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ __pycache__ /dist *.env -test.py diff --git a/Dockerfile b/Dockerfile index d2cbc58..c629769 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ WORKDIR /app COPY requirements.txt . RUN pip3 install -r requirements.txt COPY . . -ENTRYPOINT ["python3", "filepass.py"] +ENTRYPOINT ["python3", "cli.py"] diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..680f11e --- /dev/null +++ b/cli.py @@ -0,0 +1,93 @@ +import logging +import os +import sys + +import graypy + +from src.filepass import file_pass + + +def main(): + # Load Environmental Variables + + # GREYLOG_SERVER + # GREYLOG_PORT + # INTEGRATION_NAME + + from_user = os.environ.get("FROMUSER") + from_pw = os.environ.get("FROMPW") + from_svr = os.environ.get("FROMSVR") + from_port = os.environ.get("FROMPORT") + from_dir = os.environ.get("FROMDIR") + from_share = os.environ.get("FROMSMBSHARE") + from_method = os.environ.get("FROMMETHOD") + from_delete = os.environ.get("FROMDELETE") + from_filter = os.environ.get("FROMFILEFILTER") + + to_user = os.environ.get("TOUSER") + to_pw = os.environ.get("TOPW") + to_svr = os.environ.get("TOSVR") + to_port = os.environ.get("TOPORT") + to_dir = os.environ.get("TODIR") + to_share = os.environ.get("TOSMBSHARE") + to_method = os.environ.get("TOMETHOD") + to_delete = os.environ.get("TODELETE") + + filepass_logger = logging.getLogger("filepass_logger") + filepass_logger.setLevel(logging.DEBUG) + + handler = graypy.GELFTCPHandler( + os.environ.get("GRAYLOG_SERVER"), int(os.environ.get("GRAYLOG_PORT")) + ) + filepass_logger.addHandler(handler) + + handler_std = logging.StreamHandler(sys.stdout) + filepass_logger.addHandler(handler_std) + + logger = logging.LoggerAdapter( + filepass_logger, + { + "from_method": from_method, + "from_user": from_user, + "from_svr": from_svr, + "from_port": from_port, + "from_share": from_share, + "from_dir": from_dir, + "from_filter": from_filter, + "to_method": to_method, + "to_user": to_user, + "to_svr": to_svr, + "to_port": to_port, + "to_share": to_share, + "to_dir": to_dir, + "integration": "filepass", + "filepass_name": os.environ.get("INTEGRATION_NAME"), + }, + ) + try: + file_pass( + logger, + from_user, + from_pw, + from_svr, + from_port, + from_dir, + from_share, + from_method, + from_delete, + from_filter, + to_user, + to_pw, + to_svr, + to_port, + to_dir, + to_share, + to_method, + to_delete, + ) + except: + logger.exception("Critical error found", stack_info=True) + + +if __name__ == "__main__": + main()