mirror of
https://github.com/moghtech/komodo.git
synced 2026-10-28 16:00:38 +00:00
add 'init' param to make 'execute_terminal' in single call possible
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use anyhow::Context;
|
||||
use axum::{Extension, Router, middleware, routing::post};
|
||||
use komodo_client::{
|
||||
api::terminal::*,
|
||||
api::{terminal::*, write::TerminalRecreateMode},
|
||||
entities::{
|
||||
deployment::Deployment, permission::PermissionLevel,
|
||||
server::Server, stack::Stack, user::User,
|
||||
@@ -43,6 +43,7 @@ async fn execute_terminal(
|
||||
server,
|
||||
terminal,
|
||||
command,
|
||||
init,
|
||||
}): Json<ExecuteTerminalBody>,
|
||||
) -> serror::Result<axum::body::Body> {
|
||||
info!("/terminal/execute request | user: {}", user.username);
|
||||
@@ -54,8 +55,14 @@ async fn execute_terminal(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let stream = periphery_client(&server)
|
||||
.await?
|
||||
let periphery = periphery_client(&server).await?;
|
||||
|
||||
// Maybe init terminal.
|
||||
if let Some(request) = init {
|
||||
periphery.request(request).await?;
|
||||
}
|
||||
|
||||
let stream = periphery
|
||||
.execute_terminal(terminal, command)
|
||||
.await
|
||||
.context("Failed to execute command on periphery")?;
|
||||
@@ -100,7 +107,12 @@ async fn execute_container_exec(
|
||||
let periphery = periphery_client(&server).await?;
|
||||
|
||||
let stream = periphery
|
||||
.execute_container_exec(container, shell, command, recreate)
|
||||
.execute_container_exec(
|
||||
container,
|
||||
shell,
|
||||
command,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
.context(
|
||||
"Failed to execute container exec command on periphery",
|
||||
@@ -146,7 +158,12 @@ async fn execute_deployment_exec(
|
||||
let periphery = periphery_client(&server).await?;
|
||||
|
||||
let stream = periphery
|
||||
.execute_container_exec(deployment.name, shell, command, recreate)
|
||||
.execute_container_exec(
|
||||
deployment.name,
|
||||
shell,
|
||||
command,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
.context(
|
||||
"Failed to execute container exec command on periphery",
|
||||
@@ -209,7 +226,12 @@ async fn execute_stack_exec(
|
||||
let periphery = periphery_client(&server).await?;
|
||||
|
||||
let stream = periphery
|
||||
.execute_container_exec(container, shell, command, recreate)
|
||||
.execute_container_exec(
|
||||
container,
|
||||
shell,
|
||||
command,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
.context(
|
||||
"Failed to execute container exec command on periphery",
|
||||
|
||||
@@ -4,8 +4,11 @@ use axum::{
|
||||
};
|
||||
use futures_util::SinkExt;
|
||||
use komodo_client::{
|
||||
api::terminal::{
|
||||
ConnectContainerAttachQuery, ConnectContainerExecQuery,
|
||||
api::{
|
||||
terminal::{
|
||||
ConnectContainerAttachQuery, ConnectContainerExecQuery,
|
||||
},
|
||||
write::TerminalRecreateMode,
|
||||
},
|
||||
entities::{permission::PermissionLevel, server::Server},
|
||||
};
|
||||
@@ -52,7 +55,7 @@ pub async fn exec(
|
||||
&server,
|
||||
container,
|
||||
shell,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
@@ -96,7 +99,7 @@ pub async fn attach(
|
||||
client_socket,
|
||||
&server,
|
||||
container,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
|
||||
@@ -4,8 +4,11 @@ use axum::{
|
||||
};
|
||||
use futures_util::SinkExt;
|
||||
use komodo_client::{
|
||||
api::terminal::{
|
||||
ConnectDeploymentAttachQuery, ConnectDeploymentExecQuery,
|
||||
api::{
|
||||
terminal::{
|
||||
ConnectDeploymentAttachQuery, ConnectDeploymentExecQuery,
|
||||
},
|
||||
write::TerminalRecreateMode,
|
||||
},
|
||||
entities::{
|
||||
deployment::Deployment, permission::PermissionLevel,
|
||||
@@ -67,7 +70,7 @@ pub async fn exec(
|
||||
&server,
|
||||
deployment.name,
|
||||
shell,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
@@ -123,7 +126,7 @@ pub async fn attach(
|
||||
client_socket,
|
||||
&server,
|
||||
deployment.name,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
|
||||
@@ -4,7 +4,10 @@ use axum::{
|
||||
};
|
||||
use futures_util::SinkExt;
|
||||
use komodo_client::{
|
||||
api::terminal::{ConnectStackAttachQuery, ConnectStackExecQuery},
|
||||
api::{
|
||||
terminal::{ConnectStackAttachQuery, ConnectStackExecQuery},
|
||||
write::TerminalRecreateMode,
|
||||
},
|
||||
entities::{
|
||||
permission::PermissionLevel, server::Server, stack::Stack,
|
||||
},
|
||||
@@ -37,7 +40,7 @@ pub async fn exec(
|
||||
&server,
|
||||
container,
|
||||
shell,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
@@ -63,7 +66,7 @@ pub async fn attach(
|
||||
client_socket,
|
||||
&server,
|
||||
container,
|
||||
recreate,
|
||||
recreate.unwrap_or(TerminalRecreateMode::DifferentCommand),
|
||||
)
|
||||
.await
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use crate::api::write::TerminalRecreateMode;
|
||||
use crate::api::write::{CreateTerminal, TerminalRecreateMode};
|
||||
|
||||
/// Query to connect to a terminal (interactive shell over websocket) on the given server.
|
||||
#[typeshare]
|
||||
@@ -26,6 +26,9 @@ pub struct ExecuteTerminalBody {
|
||||
pub terminal: String,
|
||||
/// The command to execute.
|
||||
pub command: String,
|
||||
/// Pass to init the terminal session
|
||||
/// for when the terminal doesn't already exist.
|
||||
pub init: Option<CreateTerminal>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container exec session (interactive shell over websocket) on the given server.
|
||||
@@ -40,8 +43,7 @@ pub struct ConnectContainerExecQuery {
|
||||
pub shell: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container attach session (interactive shell over websocket) on the given server.
|
||||
@@ -54,8 +56,7 @@ pub struct ConnectContainerAttachQuery {
|
||||
pub container: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Execute a command in the given containers shell.
|
||||
@@ -72,8 +73,7 @@ pub struct ExecuteContainerExecBody {
|
||||
pub command: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container exec session (interactive shell over websocket) on the given Deployment.
|
||||
@@ -87,8 +87,7 @@ pub struct ConnectDeploymentExecQuery {
|
||||
pub shell: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container attach session (interactive shell over websocket) on the given Deployment.
|
||||
@@ -100,8 +99,7 @@ pub struct ConnectDeploymentAttachQuery {
|
||||
pub deployment: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Execute a command in the given containers shell.
|
||||
@@ -116,8 +114,7 @@ pub struct ExecuteDeploymentExecBody {
|
||||
pub command: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container exec session (interactive shell over websocket) on the given Stack / service.
|
||||
@@ -133,8 +130,7 @@ pub struct ConnectStackExecQuery {
|
||||
pub shell: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Query to connect to a container attach session (interactive shell over websocket) on the given Stack / service.
|
||||
@@ -148,8 +144,7 @@ pub struct ConnectStackAttachQuery {
|
||||
pub service: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
/// Execute a command in the given containers shell.
|
||||
@@ -166,10 +161,5 @@ pub struct ExecuteStackExecBody {
|
||||
pub command: String,
|
||||
/// Specify the recreate behavior.
|
||||
/// Default is 'DifferentCommand'
|
||||
#[serde(default = "default_container_recreate_mode")]
|
||||
pub recreate: TerminalRecreateMode,
|
||||
}
|
||||
|
||||
fn default_container_recreate_mode() -> TerminalRecreateMode {
|
||||
TerminalRecreateMode::DifferentCommand
|
||||
pub recreate: Option<TerminalRecreateMode>,
|
||||
}
|
||||
|
||||
@@ -3561,6 +3561,8 @@ export type ListAllDockerContainersResponse = ContainerListItem[];
|
||||
export interface TerminalInfoWithServer {
|
||||
/** The server id. */
|
||||
server_id: string;
|
||||
/** The server name. */
|
||||
server_name: string;
|
||||
/** The name of the terminal. */
|
||||
name: string;
|
||||
/** The root program / args of the pty */
|
||||
@@ -4672,7 +4674,7 @@ export interface ConnectContainerAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/** Query to connect to a container exec session (interactive shell over websocket) on the given server. */
|
||||
@@ -4687,7 +4689,7 @@ export interface ConnectContainerExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4701,7 +4703,7 @@ export interface ConnectDeploymentAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4717,7 +4719,7 @@ export interface ConnectDeploymentExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4733,7 +4735,7 @@ export interface ConnectStackAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4751,7 +4753,7 @@ export interface ConnectStackExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/** Query to connect to a terminal (interactive shell over websocket) on the given server. */
|
||||
@@ -5733,7 +5735,7 @@ export interface ExecuteContainerExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/** Execute a command in the given containers shell. */
|
||||
@@ -5748,7 +5750,7 @@ export interface ExecuteDeploymentExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/** Execute a command in the given containers shell. */
|
||||
@@ -5765,7 +5767,7 @@ export interface ExecuteStackExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
|
||||
/** Execute a terminal command on the given server. */
|
||||
@@ -5776,6 +5778,11 @@ export interface ExecuteTerminalBody {
|
||||
terminal: string;
|
||||
/** The command to execute. */
|
||||
command: string;
|
||||
/**
|
||||
* Pass to init the terminal session
|
||||
* for when the terminal doesn't already exist.
|
||||
*/
|
||||
init?: CreateTerminal;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+16
-9
@@ -3600,6 +3600,8 @@ export type ListAllDockerContainersResponse = ContainerListItem[];
|
||||
export interface TerminalInfoWithServer {
|
||||
/** The server id. */
|
||||
server_id: string;
|
||||
/** The server name. */
|
||||
server_name: string;
|
||||
/** The name of the terminal. */
|
||||
name: string;
|
||||
/** The root program / args of the pty */
|
||||
@@ -4559,7 +4561,7 @@ export interface ConnectContainerAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/** Query to connect to a container exec session (interactive shell over websocket) on the given server. */
|
||||
export interface ConnectContainerExecQuery {
|
||||
@@ -4573,7 +4575,7 @@ export interface ConnectContainerExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/**
|
||||
* Query to connect to a container attach session (interactive shell over websocket) on the given Deployment.
|
||||
@@ -4586,7 +4588,7 @@ export interface ConnectDeploymentAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/**
|
||||
* Query to connect to a container exec session (interactive shell over websocket) on the given Deployment.
|
||||
@@ -4601,7 +4603,7 @@ export interface ConnectDeploymentExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/**
|
||||
* Query to connect to a container attach session (interactive shell over websocket) on the given Stack / service.
|
||||
@@ -4616,7 +4618,7 @@ export interface ConnectStackAttachQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/**
|
||||
* Query to connect to a container exec session (interactive shell over websocket) on the given Stack / service.
|
||||
@@ -4633,7 +4635,7 @@ export interface ConnectStackExecQuery {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/** Query to connect to a terminal (interactive shell over websocket) on the given server. */
|
||||
export interface ConnectTerminalQuery {
|
||||
@@ -5540,7 +5542,7 @@ export interface ExecuteContainerExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/** Execute a command in the given containers shell. */
|
||||
export interface ExecuteDeploymentExecBody {
|
||||
@@ -5554,7 +5556,7 @@ export interface ExecuteDeploymentExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/** Execute a command in the given containers shell. */
|
||||
export interface ExecuteStackExecBody {
|
||||
@@ -5570,7 +5572,7 @@ export interface ExecuteStackExecBody {
|
||||
* Specify the recreate behavior.
|
||||
* Default is 'DifferentCommand'
|
||||
*/
|
||||
recreate: TerminalRecreateMode;
|
||||
recreate?: TerminalRecreateMode;
|
||||
}
|
||||
/** Execute a terminal command on the given server. */
|
||||
export interface ExecuteTerminalBody {
|
||||
@@ -5580,6 +5582,11 @@ export interface ExecuteTerminalBody {
|
||||
terminal: string;
|
||||
/** The command to execute. */
|
||||
command: string;
|
||||
/**
|
||||
* Pass to init the terminal session
|
||||
* for when the terminal doesn't already exist.
|
||||
*/
|
||||
init?: CreateTerminal;
|
||||
}
|
||||
/**
|
||||
* Get pretty formatted monrun sync toml for all resources
|
||||
|
||||
Reference in New Issue
Block a user