use derive_empty_traits::EmptyTraits;
use resolver_api::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{
SearchCombinator, U64,
docker::{
container::Container, service::SwarmService, stack::SwarmStack,
},
stack::{
Stack, StackActionState, StackListItem, StackQuery, StackService,
},
update::Log,
};
use super::KomodoReadRequest;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackResponse)]
#[error(serror::Error)]
pub struct GetStack {
#[serde(alias = "id", alias = "name")]
pub stack: String,
}
#[typeshare]
pub type GetStackResponse = Stack;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListStackServicesResponse)]
#[error(serror::Error)]
pub struct ListStackServices {
#[serde(alias = "id", alias = "name")]
pub stack: String,
}
#[typeshare]
pub type ListStackServicesResponse = Vec<StackService>;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackContainerResponse)]
#[error(serror::Error)]
pub struct InspectStackContainer {
#[serde(alias = "id", alias = "name")]
pub stack: String,
pub service: String,
}
#[typeshare]
pub type InspectStackContainerResponse = Container;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackSwarmServiceResponse)]
#[error(serror::Error)]
pub struct InspectStackSwarmService {
#[serde(alias = "id", alias = "name")]
pub stack: String,
pub service: String,
}
#[typeshare]
pub type InspectStackSwarmServiceResponse = SwarmService;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackSwarmInfoResponse)]
#[error(serror::Error)]
pub struct InspectStackSwarmInfo {
#[serde(alias = "id", alias = "name")]
pub stack: String,
}
#[typeshare]
pub type InspectStackSwarmInfoResponse = SwarmStack;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackLogResponse)]
#[error(serror::Error)]
pub struct GetStackLog {
#[serde(alias = "id", alias = "name")]
pub stack: String,
pub services: Vec<String>,
#[serde(default = "default_tail")]
pub tail: U64,
#[serde(default)]
pub timestamps: bool,
}
fn default_tail() -> u64 {
50
}
#[typeshare]
pub type GetStackLogResponse = Log;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(SearchStackLogResponse)]
#[error(serror::Error)]
pub struct SearchStackLog {
#[serde(alias = "id", alias = "name")]
pub stack: String,
pub services: Vec<String>,
pub terms: Vec<String>,
#[serde(default)]
pub combinator: SearchCombinator,
#[serde(default)]
pub invert: bool,
#[serde(default)]
pub timestamps: bool,
}
#[typeshare]
pub type SearchStackLogResponse = Log;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListCommonStackExtraArgsResponse)]
#[error(serror::Error)]
pub struct ListCommonStackExtraArgs {
#[serde(default)]
pub query: StackQuery,
}
#[typeshare]
pub type ListCommonStackExtraArgsResponse = Vec<String>;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListCommonStackBuildExtraArgsResponse)]
#[error(serror::Error)]
pub struct ListCommonStackBuildExtraArgs {
#[serde(default)]
pub query: StackQuery,
}
#[typeshare]
pub type ListCommonStackBuildExtraArgsResponse = Vec<String>;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Default, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListStacksResponse)]
#[error(serror::Error)]
pub struct ListStacks {
#[serde(default)]
pub query: StackQuery,
}
#[typeshare]
pub type ListStacksResponse = Vec<StackListItem>;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Default, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListFullStacksResponse)]
#[error(serror::Error)]
pub struct ListFullStacks {
#[serde(default)]
pub query: StackQuery,
}
#[typeshare]
pub type ListFullStacksResponse = Vec<Stack>;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackActionStateResponse)]
#[error(serror::Error)]
pub struct GetStackActionState {
#[serde(alias = "id", alias = "name")]
pub stack: String,
}
#[typeshare]
pub type GetStackActionStateResponse = StackActionState;
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Resolve, EmptyTraits,
)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStacksSummaryResponse)]
#[error(serror::Error)]
pub struct GetStacksSummary {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct GetStacksSummaryResponse {
pub total: u32,
pub running: u32,
pub stopped: u32,
pub down: u32,
pub unhealthy: u32,
pub unknown: u32,
}