Implement execute_secure
Allows us to sanitize commands involving sensitive information like passwords, before throwing exceptions
This commit is contained in:
parent
2ead8cc31b
commit
8ae03f5811
1 changed files with 9 additions and 3 deletions
|
@ -101,9 +101,15 @@ class ExecutionApi:
|
||||||
raise exc
|
raise exc
|
||||||
return output
|
return output
|
||||||
|
|
||||||
# TODO: check for exception handling
|
def execute_secure(self, command: str, sanitized_command: str, dry_run=False, shell=True, check=True):
|
||||||
# TODO: can we return the output here also?
|
try:
|
||||||
# TODO: should we also print stderr?
|
output = self.execute(command, dry_run, shell, check)
|
||||||
|
return output
|
||||||
|
except CalledProcessError as exc:
|
||||||
|
sanitized_exc = exc
|
||||||
|
sanitized_exc.cmd = sanitized_command
|
||||||
|
raise sanitized_exc
|
||||||
|
|
||||||
def execute_live(self, command: str, dry_run=False, shell=True):
|
def execute_live(self, command: str, dry_run=False, shell=True):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print(command)
|
print(command)
|
||||||
|
|
Loading…
Reference in a new issue