use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{
ResourceTarget, SearchCombinator, U64,
docker::{
container::{
Container, ContainerListItem, ContainerSortBy,
ContainerStateStatusEnum,
},
image::{Image, ImageHistoryResponseItem, ImageListItem},
network::{Network, NetworkListItem},
volume::{Volume, VolumeListItem},
},
stack::ComposeProject,
update::Log,
};
use super::KomodoReadRequest;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetContainersSummary",
description = "Gets a summary of data relating to all containers.",
request_body(content = GetContainersSummary),
responses(
(status = 200, description = "The containers summary", body = GetContainersSummaryResponse),
),
)]
pub fn get_containers_summary() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetContainersSummaryResponse)]
#[error(mogh_error::Error)]
pub struct GetContainersSummary {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetContainersSummaryResponse {
pub total: u32,
pub running: u32,
pub stopped: u32,
pub unhealthy: u32,
pub unknown: u32,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListAllContainers",
description = "List all containers on the target servers.",
request_body(content = ListAllContainers),
responses(
(status = 200, description = "The list of containers", body = ListAllContainersResponse),
),
)]
pub fn list_all_containers() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListAllContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListAllContainers {
#[serde(default)]
pub servers: Vec<String>,
#[serde(default)]
pub tags: Vec<String>,
#[serde(default)]
pub terms: Vec<String>,
#[serde(default)]
pub state: Vec<ContainerStateStatusEnum>,
#[serde(default)]
pub page: U64,
pub limit: Option<U64>,
#[serde(default)]
pub sort_by: ContainerSortBy,
#[serde(default)]
pub sort_desc: bool,
}
#[typeshare]
pub type ListAllContainersResponse = Vec<ContainerListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListContainers",
description = "List all containers on the target server.",
request_body(content = ListContainers),
responses(
(status = 200, description = "The list of containers", body = ListContainersResponse),
),
)]
pub fn list_containers() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListContainers {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListContainersResponse = Vec<ContainerListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectContainer",
description = "Inspect a container on the server.",
request_body(content = InspectContainer),
responses(
(status = 200, description = "The container", body = InspectContainerResponse),
),
)]
pub fn inspect_container() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectContainerResponse)]
#[error(mogh_error::Error)]
pub struct InspectContainer {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub container: String,
}
#[typeshare]
pub type InspectContainerResponse = Container;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetResourceMatchingContainer",
description = "Find the attached resource for a container.",
request_body(content = GetResourceMatchingContainer),
responses(
(status = 200, description = "The resource matching the container", body = GetResourceMatchingContainerResponse),
),
)]
pub fn get_resource_matching_container() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetResourceMatchingContainerResponse)]
#[error(mogh_error::Error)]
pub struct GetResourceMatchingContainer {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub container: String,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetResourceMatchingContainerResponse {
pub resource: Option<ResourceTarget>,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetContainerLog",
description = "Get the container log's tail, split by stdout/stderr.",
request_body(content = GetContainerLog),
responses(
(status = 200, description = "The container log", body = GetContainerLogResponse),
),
)]
pub fn get_container_log() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetContainerLogResponse)]
#[error(mogh_error::Error)]
pub struct GetContainerLog {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub container: String,
#[serde(default = "default_tail")]
pub tail: U64,
#[serde(default)]
pub timestamps: bool,
}
fn default_tail() -> u64 {
50
}
#[typeshare]
pub type GetContainerLogResponse = Log;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/SearchContainerLog",
description = "Search the container log's tail using `grep`.",
request_body(content = SearchContainerLog),
responses(
(status = 200, description = "The search results", body = SearchContainerLogResponse),
),
)]
pub fn search_container_log() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(SearchContainerLogResponse)]
#[error(mogh_error::Error)]
pub struct SearchContainerLog {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub container: String,
pub terms: Vec<String>,
#[serde(default)]
pub combinator: SearchCombinator,
#[serde(default)]
pub invert: bool,
#[serde(default)]
pub timestamps: bool,
}
#[typeshare]
pub type SearchContainerLogResponse = Log;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListComposeProjects",
description = "List all compose projects on the target server.",
request_body(content = ListComposeProjects),
responses(
(status = 200, description = "The list of compose projects", body = ListComposeProjectsResponse),
),
)]
pub fn list_compose_projects() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListComposeProjectsResponse)]
#[error(mogh_error::Error)]
pub struct ListComposeProjects {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListComposeProjectsResponse = Vec<ComposeProject>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListNetworks",
description = "List the container networks on the server.",
request_body(content = ListNetworks),
responses(
(status = 200, description = "The list of networks", body = ListNetworksResponse),
),
)]
pub fn list_networks() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListNetworksResponse)]
#[error(mogh_error::Error)]
pub struct ListNetworks {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListNetworksResponse = Vec<NetworkListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectNetwork",
description = "Inspect a container network on the server.",
request_body(content = InspectNetwork),
responses(
(status = 200, description = "The network", body = InspectNetworkResponse),
),
)]
pub fn inspect_network() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectNetworkResponse)]
#[error(mogh_error::Error)]
pub struct InspectNetwork {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub network: String,
}
#[typeshare]
pub type InspectNetworkResponse = Network;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListImages",
description = "List the container images locally cached on the target server.",
request_body(content = ListImages),
responses(
(status = 200, description = "The list of images", body = ListImagesResponse),
),
)]
pub fn list_images() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListImagesResponse)]
#[error(mogh_error::Error)]
pub struct ListImages {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListImagesResponse = Vec<ImageListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectImage",
description = "Inspect a container image on the server.",
request_body(content = InspectImage),
responses(
(status = 200, description = "The image", body = InspectImageResponse),
),
)]
pub fn inspect_image() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectImageResponse)]
#[error(mogh_error::Error)]
pub struct InspectImage {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub image: String,
}
#[typeshare]
pub type InspectImageResponse = Image;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListImageHistory",
description = "Get image history from the server.",
request_body(content = ListImageHistory),
responses(
(status = 200, description = "The image history", body = ListImageHistoryResponse),
),
)]
pub fn list_image_history() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListImageHistoryResponse)]
#[error(mogh_error::Error)]
pub struct ListImageHistory {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub image: String,
}
#[typeshare]
pub type ListImageHistoryResponse = Vec<ImageHistoryResponseItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListVolumes",
description = "List all container volumes on the target server.",
request_body(content = ListVolumes),
responses(
(status = 200, description = "The list of volumes", body = ListVolumesResponse),
),
)]
pub fn list_volumes() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListVolumesResponse)]
#[error(mogh_error::Error)]
pub struct ListVolumes {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListVolumesResponse = Vec<VolumeListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectVolume",
description = "Inspect a container volume on the server.",
request_body(content = InspectVolume),
responses(
(status = 200, description = "The volume", body = InspectVolumeResponse),
),
)]
pub fn inspect_volume() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectVolumeResponse)]
#[error(mogh_error::Error)]
pub struct InspectVolume {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub volume: String,
}
#[typeshare]
pub type InspectVolumeResponse = Volume;