Skip to content

Commit

Permalink
core: commander: add endpoint for running code on the docker itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Sep 4, 2023
1 parent 4de3827 commit 7625cbe
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion core/services/commander/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def check_what_i_am_doing(i_know_what_i_am_doing: bool = False) -> None:
@version(1, 0)
async def command_host(command: str, i_know_what_i_am_doing: bool = False) -> Any:
check_what_i_am_doing(i_know_what_i_am_doing)
logger.debug(f"Running command: {command}")
logger.debug(f"Running command on host OS: {command}")
output = run_command(command, False)
logger.debug(f"Output: {output}")
message = {
Expand All @@ -66,6 +66,27 @@ async def command_host(command: str, i_know_what_i_am_doing: bool = False) -> An
return message


@app.post("/command", status_code=status.HTTP_200_OK)
@version(1, 0)
async def command_docker(command: str, i_know_what_i_am_doing: bool = False) -> Any:
check_what_i_am_doing(i_know_what_i_am_doing)
logger.debug(f"Running command: {command}")
output = subprocess.run(
shlex.split(command),
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
logger.debug(f"Output: {output}")
message = {
"stdout": f"{output.stdout}",
"stderr": f"{output.stderr}",
"return_code": output.returncode,
}
return message


@app.post("/set_time", status_code=status.HTTP_200_OK)
@version(1, 0)
async def set_time(unix_time_seconds: int, i_know_what_i_am_doing: bool = False) -> Any:
Expand Down

0 comments on commit 7625cbe

Please sign in to comment.