Compare commits

..

No commits in common. "master" and "v1.1.1" have entirely different histories.

2 changed files with 12 additions and 44 deletions

49
app.py
View File

@ -6,8 +6,6 @@ import scp
import sys
import math
import re
import tempfile
import os
envs = environ
@ -44,34 +42,19 @@ def strip_and_parse_envs(p):
return None
for c in strips:
p = p.strip(c)
return path.expandvars(p) if p != "." else f"{path.realpath(p)}/*"
return path.expandvars(p)
def connect(callback=None):
tmp = tempfile.NamedTemporaryFile(delete=False)
try:
ssh = paramiko.SSHClient()
p_key = None
if INPUT_KEY:
tmp.write(INPUT_KEY.encode())
tmp.close()
p_key = paramiko.RSAKey.from_private_key_file(filename=tmp.name)
with paramiko.SSHClient() as ssh:
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(INPUT_HOST, port=INPUT_PORT, username=INPUT_USER,
pkey=p_key, password=INPUT_PASS,
timeout=convert_to_seconds(INPUT_CONNECT_TIMEOUT))
except Exception as err:
print(f"Connect error\n{err}")
sys.exit(1)
else:
if callback:
callback(ssh)
finally:
os.unlink(tmp.name)
tmp.close()
# Define progress callback that prints the current percentage completed for the file
def progress(filename, size, sent):
@ -96,8 +79,6 @@ def ssh_process(ssh, input_ssh):
stdin, stdout, stderr = ssh.exec_command(command_str)
ssh_exit_status = stdout.channel.recv_exit_status()
out = "".join(stdout.readlines())
out = out.strip() if out is not None else None
if out:
@ -106,11 +87,10 @@ def ssh_process(ssh, input_ssh):
err = "".join(stderr.readlines())
err = err.strip() if err is not None else None
if err:
print(f"Error: \n{err}")
if ssh_exit_status != 0:
print(f"ssh exit status: {ssh_exit_status}")
sys.exit(1)
if out is None:
raise Exception(err)
else:
print(f"Error: \n{err}")
pass
@ -137,19 +117,10 @@ def scp_process(ssh, input_scp):
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
for l2r in copy_list:
remote = l2r.get('r')
try:
ssh.exec_command(f"mkdir -p {remote}")
except Exception as err:
print(f"Remote mkdir error. Can't create {remote}\n{err}")
sys.exit(1)
ssh.exec_command(f"mkdir -p {remote} || true")
for f in [f for f in glob(l2r.get('l'))]:
try:
conn.put(f, remote_path=remote, recursive=True)
print(f"{f} -> {remote}")
except Exception as err:
print(f"Scp error. Can't copy {f} on {remote}\n{err}")
sys.exit(1)
conn.put(f, remote_path=remote, recursive=True)
print(f"{f} -> {remote}")
pass

View File

@ -3,8 +3,5 @@
echo "+++++++++++++++++++STARTING PIPELINES+++++++++++++++++++"
python3 /opt/tools/app.py
RET=$?
echo "+++++++++++++++++++END PIPELINES+++++++++++++++++++"
exit $RET