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:
18
run
18
run
@@ -23,13 +23,21 @@ 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 deploy(source, target, keyfile):
|
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)
|
||||||
|
|
||||||
|
def deploy_file(source_file, target, auth):
|
||||||
print(f">> {source_file} -> {target}")
|
print(f">> {source_file} -> {target}")
|
||||||
run(["scp", "-i", keyfile, "-o", "StrictHostKeyChecking=no", "-o", "PasswordAuthentication=no", "-r", source_file, target], check=True)
|
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
|
temp_file_name = None
|
||||||
|
auth = None
|
||||||
try:
|
try:
|
||||||
|
if 'PLUGIN_KEY' in os.environ:
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
with tempfile.NamedTemporaryFile(delete=False) as deploy_key:
|
||||||
temp_file_name = deploy_key.name
|
temp_file_name = deploy_key.name
|
||||||
deploy_key.write(os.environ['PLUGIN_KEY'].encode())
|
deploy_key.write(os.environ['PLUGIN_KEY'].encode())
|
||||||
@@ -37,7 +45,11 @@ try:
|
|||||||
deploy_key.close()
|
deploy_key.close()
|
||||||
|
|
||||||
apply_key_permissions(deploy_key.name)
|
apply_key_permissions(deploy_key.name)
|
||||||
deploy(SOURCE, TARGET, deploy_key.name)
|
auth = deploy_key.name
|
||||||
|
else:
|
||||||
|
auth = os.environ['PLUGIN_AUTHENTICATION']
|
||||||
|
|
||||||
|
deploy(SOURCE, TARGET, auth)
|
||||||
finally:
|
finally:
|
||||||
if temp_file_name is not None:
|
if temp_file_name is not None:
|
||||||
os.remove(temp_file_name)
|
os.remove(temp_file_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user