Merge pull request 'don't run sops + editor in a pipe' (#2680) from sops-edit into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2680
This commit is contained in:
@@ -6,7 +6,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
from collections.abc import Iterable, Sequence
|
from collections.abc import Iterable, Sequence
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -194,7 +193,7 @@ def sops_run(
|
|||||||
sops_cmd.append("decrypt")
|
sops_cmd.append("decrypt")
|
||||||
else:
|
else:
|
||||||
# When sops is used to edit a file the config is only used at
|
# When sops is used to edit a file the config is only used at
|
||||||
# file creation, otherwise the keys from the exising file are
|
# file creation, otherwise the keys from the existing file are
|
||||||
# used.
|
# used.
|
||||||
sops_cmd.extend(["--config", manifest.name])
|
sops_cmd.extend(["--config", manifest.name])
|
||||||
|
|
||||||
@@ -240,6 +239,11 @@ def sops_run(
|
|||||||
if run_opts
|
if run_opts
|
||||||
else RunOpts(env=environ)
|
else RunOpts(env=environ)
|
||||||
)
|
)
|
||||||
|
if call == Operation.EDIT:
|
||||||
|
# Use direct stdout / stderr, as else it breaks editor integration.
|
||||||
|
# We never need this in our UI. TUI only.
|
||||||
|
p1 = subprocess.run(cmd, check=False, text=True)
|
||||||
|
return p1.returncode, ""
|
||||||
p = run(cmd, opts)
|
p = run(cmd, opts)
|
||||||
return p.returncode, p.stdout
|
return p.returncode, p.stdout
|
||||||
|
|
||||||
@@ -376,18 +380,12 @@ def encrypt_file(
|
|||||||
folder.mkdir(parents=True, exist_ok=True)
|
folder.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
# Use direct stdout / stderr, as else it breaks editor integration.
|
# This will spawn an editor to edit the file.
|
||||||
# We never need this in our UI. TUI only.
|
|
||||||
rc, _ = sops_run(
|
rc, _ = sops_run(
|
||||||
Operation.EDIT,
|
Operation.EDIT,
|
||||||
secret_path,
|
secret_path,
|
||||||
pubkeys,
|
pubkeys,
|
||||||
RunOpts(
|
RunOpts(),
|
||||||
stdout=sys.stdout.buffer,
|
|
||||||
stderr=sys.stderr.buffer,
|
|
||||||
check=False,
|
|
||||||
log=Log.NONE,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
status = ExitStatus.parse(rc)
|
status = ExitStatus.parse(rc)
|
||||||
if rc == 0 or status == ExitStatus.FILE_HAS_NOT_BEEN_MODIFIED:
|
if rc == 0 or status == ExitStatus.FILE_HAS_NOT_BEEN_MODIFIED:
|
||||||
|
|||||||
Reference in New Issue
Block a user