diff --git a/.gitignore b/.gitignore index 93a7d74..7961b79 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .idea *.egg-info __pycache__ +/dist +*.env 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/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 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() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..87aec4d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "filepass" +version = "0.2.0" +authors = [ + { name="Orlund Norstrom", email="onorstrom@kamloops.ca" }, + { name="Marco Lussetti", email="mlussetti@kamloops.ca" }, + { name="Parul Parul", email="pparul@kamloops.ca" }, +] +description = "Wrapper around fs libraries to synchronized files between different system types including SMB, SFTP, FSTP." +readme = "README.md" +license = { file="LICENSE" } +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] + +[project.urls] +"Homepage" = "https://github.com/cityofkamloops/filepass" +"Bug Tracker" = "https://github.com/cityofkamloops/filepass/issues" diff --git a/requirements.txt b/requirements.txt index 0f3e418..c052adf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,16 @@ appdirs==1.4.4 -bcrypt==3.2.0 -black==21.11b1 -cffi==1.14.5 -click==8.0.3 -colorama==0.4.4 -cryptography==3.4.7 -fs==2.4.13 -fs.smbfs==1.0.2 -fs.sshfs==1.0.0 -ftpfs==0.2 -fusepy==3.0.1 +bcrypt==4.1.2 +cffi==1.16.0 +cryptography==42.0.2 +fs==2.4.16 +fs.smbfs==1.0.7 +fs.sshfs==1.0.2 graypy==2.1.0 -mypy-extensions==0.4.3 -paramiko==2.7.2 -pathspec==0.9.0 -platformdirs==2.4.0 +paramiko==3.4.0 property-cached==1.6.4 -pyasn1==0.4.8 -pycparser==2.20 -PyNaCl==1.4.0 -pysmb==1.2.7 -pytz==2021.1 -regex==2021.11.10 -scp==0.13.5 +pyasn1==0.5.1 +pycparser==2.21 +PyNaCl==1.5.0 +pysmb==1.2.9.1 six==1.16.0 -tomli==1.2.2 -typing-extensions==4.0.1 +tqdm==4.66.2 diff --git a/src/filepass/__init__.py b/src/filepass/__init__.py index d89a17e..d169ea3 100644 --- a/src/filepass/__init__.py +++ b/src/filepass/__init__.py @@ -1 +1 @@ -from .filepass import file_pass, ftps_connection, smb_connection, ssh_connection +from .filepass import file_pass, smb_connection, ssh_connection diff --git a/src/filepass/filepass.py b/src/filepass/filepass.py index 72db5ad..27a6f37 100644 --- a/src/filepass/filepass.py +++ b/src/filepass/filepass.py @@ -1,11 +1,6 @@ -import logging -import os -import sys - import fs import fs.ftpfs import fs.smbfs -import graypy from fs.walk import Walker @@ -29,17 +24,6 @@ def smb_connection(logger, user, pw, svr, port, smbshare, dir): return fs_conn -def ftps_connection(logger, user, pw, svr, port, tls, dir): - logger.debug( - "ftps host: {} user: {} password: {} port: {} tls: {} dir: {}".format( - svr, user, "passwordhere", port, tls, dir - ) - ) - # fs_conn = fs.ftpfs.FTPFS(host=svr, user=user, passwd=pw, port=port, tls=tls) - fs_conn = fs.open_fs("ftps://{}:{}@{}/{}".format(user, pw, svr, dir)) - return fs_conn - - def transfer_file(from_fs, to_fs, filename): to_fs.writefile(filename, from_fs.open(filename, "rb")) @@ -77,12 +61,6 @@ def file_pass( logger, from_user, from_pw, from_svr, from_port, from_share, from_dir ) - if from_method == "ftps": - logger.debug("Create from FTPS connection") - from_fs = ftps_connection( - logger, from_user, from_pw, from_svr, from_port, True, from_dir - ) - # To File System if to_method == "ssh": logger.debug("Create to SSH connection") @@ -92,9 +70,6 @@ def file_pass( to_fs = smb_connection( logger, to_user, to_pw, to_svr, to_port, to_share, to_dir ) - if to_method == "ftps": - logger.debug("Create to FTPS connection") - to_fs = ftps_connection(logger, to_user, to_pw, to_svr, to_port, True, to_dir) # Do the move walker = Walker(filter=[from_filter], ignore_errors=True, max_depth=1) @@ -132,89 +107,3 @@ def file_pass( from_fs.close() to_fs.close() - - -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("GREYLOG_SERVER"), int(os.environ.get("GREYLOG_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()