Skip to content
Snippets Groups Projects
Commit 4c74b7df authored by Bert Palm's avatar Bert Palm :bug:
Browse files

Merge branch 'FIX_sftp_sync' into 'main'

fixed wrong logging usage, and unpack error

See merge request !226
parents 727fe6a0 06b346a6
No related branches found
No related tags found
1 merge request!226fixed wrong logging usage, and unpack error
Pipeline #467786 passed
......@@ -159,8 +159,7 @@ class FtpFS(RemoteFS):
if uri_parts.scheme != "sftp":
logger.warning(
f"Expected URI to start with sftp://... , "
f"not with {uri_parts.scheme}://... '",
uri_parts,
f"not with {uri_parts.scheme}://... '"
)
ssh = SSHClient()
if missing_host_key_policy is not None:
......
......@@ -12,32 +12,33 @@ from paramiko import WarningPolicy
def get_minio_credentials(conn, thing_id) -> tuple[str, str, str, str]:
"""Returns (uri, access_key, secret_key, bucket_name)"""
with conn.cursor() as cur:
a, s, b = cur.execute(
res = cur.execute(
"SELECT r.access_key, r.secret_key, r.bucket "
"FROM tsm_thing t JOIN tsm_rawdatastorage r ON t.id = r.thing_id "
"WHERE t.thing_id = %s",
[thing_id],
).fetchone()
if not a:
if res is None or not res[0]:
raise RuntimeError(
"No object storage credentials found in frontend database"
)
a, s, b = res
return os.environ["MINIO_URL"], a, s, b
def get_external_ftp_credentials(conn, thing_id) -> tuple[str, str, str, str]:
"""Returns (uri, username, password, path)"""
with conn.cursor() as cur:
ur, us, pw, pa = cur.execute(
res = cur.execute(
"SELECT ext_sftp_uri, ext_sftp_username, ext_sftp_password, ext_sftp_path "
"FROM tsm_thing WHERE thing_id = %s",
[thing_id],
).fetchone()
if "" in [ur, us] or None in [ur, us]:
if res is None or res[0] in ["", None] or res[1] in ["", None]:
raise RuntimeError(
"No object external sftp credentials found in frontend database"
"No external sftp credentials present in frontend database"
)
return ur, us, pw, pa
return res
USAGE = """
......@@ -77,6 +78,8 @@ if __name__ == "__main__":
False if os.environ["MINIO_SECURE"].lower() in ["false", "0"] else True
)
logging.getLogger("sftp_sync").info("Thing UUID: %s", thing_id)
with psycopg.connect(dsn) as conn:
ftp_ext = get_external_ftp_credentials(conn, thing_id)
storage = get_minio_credentials(conn, thing_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment