Skip to content

Commit

Permalink
Merge pull request #4 from cityofkamloops/filepass-package
Browse files Browse the repository at this point in the history
minor version 0.2.0
  • Loading branch information
sparul93 authored Feb 13, 2024
2 parents 3df6c39 + 3620b0f commit 7d5382f
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea
*.egg-info
__pycache__
/dist
*.env
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ WORKDIR /app
COPY requirements.txt .
RUN pip3 install -r requirements.txt
COPY . .
ENTRYPOINT ["python3", "filepass.py"]
ENTRYPOINT ["python3", "cli.py"]
Empty file added LICENSE
Empty file.
Empty file added README.md
Empty file.
93 changes: 93 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "filepass"
version = "0.2.0"
authors = [
{ name="Orlund Norstrom", email="[email protected]" },
{ name="Marco Lussetti", email="[email protected]" },
{ name="Parul Parul", email="[email protected]" },
]
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"
36 changes: 12 additions & 24 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/filepass/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .filepass import file_pass, ftps_connection, smb_connection, ssh_connection
from .filepass import file_pass, smb_connection, ssh_connection
111 changes: 0 additions & 111 deletions src/filepass/filepass.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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"))

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 7d5382f

Please sign in to comment.