This commit is contained in:
@@ -8,6 +8,9 @@ from subprocess import run
|
|||||||
SOURCE = os.environ.get("PLUGIN_SOURCE", ".")
|
SOURCE = os.environ.get("PLUGIN_SOURCE", ".")
|
||||||
TARGET = os.environ['PLUGIN_TARGET']
|
TARGET = os.environ['PLUGIN_TARGET']
|
||||||
|
|
||||||
|
def is_target_http(target):
|
||||||
|
return target.startswith("http://") or target.startswith("https://")
|
||||||
|
|
||||||
def apply_key_permissions(keyfile):
|
def apply_key_permissions(keyfile):
|
||||||
os.chmod(keyfile, 0o600)
|
os.chmod(keyfile, 0o600)
|
||||||
if not os.name == "nt":
|
if not os.name == "nt":
|
||||||
@@ -23,15 +26,23 @@ def apply_key_permissions(keyfile):
|
|||||||
run(["Icacls", keyfile, "/c", "/t", "/Remove:g", other_user])
|
run(["Icacls", keyfile, "/c", "/t", "/Remove:g", other_user])
|
||||||
run(["Icacls", keyfile])
|
run(["Icacls", keyfile])
|
||||||
|
|
||||||
|
def make_parent_dirs(target, auth):
|
||||||
|
if is_target_http(target):
|
||||||
|
return
|
||||||
|
|
||||||
|
(host, path) = target.split(":", 2)
|
||||||
|
run(["ssh", "-i", auth, host, "mkdir", "-p", os.path.dirname(path)], check=True)
|
||||||
|
|
||||||
def deploy(source, target, auth):
|
def deploy(source, target, auth):
|
||||||
for source_file in glob.glob(source):
|
for source_file in glob.glob(source):
|
||||||
deploy_file(source_file, target, auth)
|
deploy_file(source_file, target, auth)
|
||||||
|
|
||||||
def deploy_file(source_file, target, auth):
|
def deploy_file(source_file, target, auth):
|
||||||
print(f">> {source_file} -> {target}")
|
print(f">> {source_file} -> {target}")
|
||||||
if target.startswith("http://") or target.startswith("https://"):
|
if is_target_http(target):
|
||||||
run(["curl", "--user", auth, target, "--upload-file", source_file], check=True)
|
run(["curl", "--user", auth, target, "--upload-file", source_file], check=True)
|
||||||
else:
|
else:
|
||||||
|
make_parent_dirs(target, auth)
|
||||||
run(["scp", "-i", auth, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-r", source_file, target], check=True)
|
run(["scp", "-i", auth, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-r", source_file, target], check=True)
|
||||||
|
|
||||||
temp_file_name = None
|
temp_file_name = None
|
||||||
|
|||||||
Reference in New Issue
Block a user