Allow goat-deploy-plugin to work with http(s) targets.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
32
run
32
run
@@ -23,21 +23,33 @@ def apply_key_permissions(keyfile):
|
||||
run(["Icacls", keyfile, "/c", "/t", "/Remove:g", other_user])
|
||||
run(["Icacls", keyfile])
|
||||
|
||||
def deploy(source, target, keyfile):
|
||||
def deploy(source, target, auth):
|
||||
for source_file in glob.glob(source):
|
||||
print(f">> {source_file} -> {target}")
|
||||
run(["scp", "-i", keyfile, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-r", source_file, target], check=True)
|
||||
deploy_file(source_file, target, auth)
|
||||
|
||||
def deploy_file(source_file, target, auth):
|
||||
print(f">> {source_file} -> {target}")
|
||||
if target.startswith("http://") or target.startswith("https://"):
|
||||
run(["curl", "--user", auth, target, "--upload-file", source_file], check=True)
|
||||
else:
|
||||
run(["scp", "-i", auth, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-r", source_file, target], check=True)
|
||||
|
||||
temp_file_name = None
|
||||
auth = None
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
||||
temp_file_name = deploy_key.name
|
||||
deploy_key.write(os.environ['PLUGIN_KEY'].encode())
|
||||
deploy_key.write(b"\n")
|
||||
deploy_key.close()
|
||||
if 'PLUGIN_KEY' in os.environ:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
||||
temp_file_name = deploy_key.name
|
||||
deploy_key.write(os.environ['PLUGIN_KEY'].encode())
|
||||
deploy_key.write(b"\n")
|
||||
deploy_key.close()
|
||||
|
||||
apply_key_permissions(deploy_key.name)
|
||||
deploy(SOURCE, TARGET, deploy_key.name)
|
||||
apply_key_permissions(deploy_key.name)
|
||||
auth = deploy_key.name
|
||||
else:
|
||||
auth = os.environ['PLUGIN_AUTHENTICATION']
|
||||
|
||||
deploy(SOURCE, TARGET, auth)
|
||||
finally:
|
||||
if temp_file_name is not None:
|
||||
os.remove(temp_file_name)
|
||||
|
||||
Reference in New Issue
Block a user