use crate::entities::update::Update;
use anyhow::Context;
use clap::ArgAction::SetTrue;
use clap::Parser;
use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use typeshare::typeshare;
use super::{BatchExecutionResponse, KomodoExecuteRequest};
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/DeployStack",
description = "Deploys the target stack.",
request_body(content = DeployStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn deploy_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct DeployStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
pub stop_time: Option<i32>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/BatchDeployStack",
description = "Deploys multiple Stacks in parallel that match pattern.",
request_body(content = BatchDeployStack),
responses(
(status = 200, description = "The batch execution response", body = BatchExecutionResponse),
),
)]
pub fn batch_deploy_stack() {}
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(mogh_error::Error)]
pub struct BatchDeployStack {
pub pattern: String,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/DeployStackIfChanged",
description = "Checks deployed contents vs latest contents and deploys if changed.",
request_body(content = DeployStackIfChanged),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn deploy_stack_if_changed() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct DeployStackIfChanged {
pub stack: String,
pub stop_time: Option<i32>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/BatchDeployStackIfChanged",
description = "Deploys multiple Stacks if changed in parallel that match pattern.",
request_body(content = BatchDeployStackIfChanged),
responses(
(status = 200, description = "The batch execution response", body = BatchExecutionResponse),
),
)]
pub fn batch_deploy_stack_if_changed() {}
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(mogh_error::Error)]
pub struct BatchDeployStackIfChanged {
pub pattern: String,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/PullStack",
description = "Pulls images for the target stack.",
request_body(content = PullStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn pull_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct PullStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/BatchPullStack",
description = "Pulls multiple Stacks in parallel that match pattern.",
request_body(content = BatchPullStack),
responses(
(status = 200, description = "The batch execution response", body = BatchExecutionResponse),
),
)]
pub fn batch_pull_stack() {}
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(mogh_error::Error)]
pub struct BatchPullStack {
pub pattern: String,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/StartStack",
description = "Starts the target stack.",
request_body(content = StartStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn start_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct StartStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/RestartStack",
description = "Restarts the target stack.",
request_body(content = RestartStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn restart_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RestartStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/PauseStack",
description = "Pauses the target stack.",
request_body(content = PauseStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn pause_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct PauseStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/UnpauseStack",
description = "Unpauses the target stack.",
request_body(content = UnpauseStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn unpause_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct UnpauseStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/StopStack",
description = "Stops the target stack.",
request_body(content = StopStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn stop_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct StopStack {
pub stack: String,
pub stop_time: Option<i32>,
#[serde(default)]
pub services: Vec<String>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/DestroyStack",
description = "Destroys the target stack.",
request_body(content = DestroyStack),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn destroy_stack() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct DestroyStack {
pub stack: String,
#[serde(default)]
pub services: Vec<String>,
#[serde(default)]
pub remove_orphans: bool,
pub stop_time: Option<i32>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/RunStackService",
description = "Runs a one-time command against a service using docker compose run.",
request_body(content = RunStackService),
responses(
(status = 200, description = "The update", body = Update),
),
)]
pub fn run_stack_service() {}
#[typeshare]
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RunStackService {
pub stack: String,
pub service: String,
#[arg(trailing_var_arg = true, num_args = 1.., allow_hyphen_values = true)]
pub command: Option<Vec<String>>,
#[arg(long = "no-tty", action = SetTrue)]
pub no_tty: Option<bool>,
#[arg(long = "no-deps", action = SetTrue)]
pub no_deps: Option<bool>,
#[arg(long = "detach", action = SetTrue)]
pub detach: Option<bool>,
#[arg(long = "service-ports", action = SetTrue)]
pub service_ports: Option<bool>,
#[arg(long = "env", short = 'e', value_parser = env_parser)]
pub env: Option<HashMap<String, String>>,
#[arg(long = "workdir")]
pub workdir: Option<String>,
#[arg(long = "user")]
pub user: Option<String>,
#[arg(long = "entrypoint")]
pub entrypoint: Option<String>,
#[arg(long = "pull", action = SetTrue)]
pub pull: Option<bool>,
}
fn env_parser(args: &str) -> anyhow::Result<HashMap<String, String>> {
serde_qs::from_str(args).context("Failed to parse env")
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/BatchDestroyStack",
description = "Destroys multiple Stacks in parallel that match pattern.",
request_body(content = BatchDestroyStack),
responses(
(status = 200, description = "The batch execution response", body = BatchExecutionResponse),
),
)]
pub fn batch_destroy_stack() {}
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(BatchExecutionResponse)]
#[error(mogh_error::Error)]
pub struct BatchDestroyStack {
pub pattern: String,
}