use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{
ResourceTarget, SearchCombinator, U64,
docker::{
container::{Container, ContainerListItem},
image::{Image, ImageHistoryResponseItem, ImageListItem},
network::{Network, NetworkListItem},
volume::{Volume, VolumeListItem},
},
stack::ComposeProject,
update::Log,
};
use super::KomodoReadRequest;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/GetDockerContainersSummary",
description = "Gets a summary of data relating to all containers.",
request_body(content = GetDockerContainersSummary),
responses(
(status = 200, description = "The docker containers summary", body = GetDockerContainersSummaryResponse),
),
)]
pub fn get_docker_containers_summary() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetDockerContainersSummaryResponse)]
#[error(mogh_error::Error)]
pub struct GetDockerContainersSummary {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetDockerContainersSummaryResponse {
pub total: u32,
pub running: u32,
pub stopped: u32,
pub unhealthy: u32,
pub unknown: u32,
}
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListAllDockerContainers",
description = "List all docker containers on the target servers.",
request_body(content = ListAllDockerContainers),
responses(
(status = 200, description = "The list of containers", body = ListAllDockerContainersResponse),
),
)]
pub fn list_all_docker_containers() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListAllDockerContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListAllDockerContainers {
#[serde(default)]
pub servers: Vec<String>,
#[serde(default)]
pub containers: Vec<String>,
}
#[typeshare]
pub type ListAllDockerContainersResponse = Vec<ContainerListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListDockerContainers",
description = "List all docker containers on the target server.",
request_body(content = ListDockerContainers),
responses(
(status = 200, description = "The list of containers", body = ListDockerContainersResponse),
),
)]
pub fn list_docker_containers() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListDockerContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListDockerContainers {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListDockerContainersResponse = Vec<ContainerListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectDockerContainer",
description = "Inspect a docker container on the server.",
request_body(content = InspectDockerContainer),
responses(
(status = 200, description = "The container", body = InspectDockerContainerResponse),
),
)]
pub fn inspect_docker_container() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectDockerContainerResponse)]
#[error(mogh_error::Error)]
pub struct InspectDockerContainer {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub container: String,
}
#[typeshare]
pub type InspectDockerContainerResponse = 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 docker 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 = "/ListDockerNetworks",
description = "List the docker networks on the server.",
request_body(content = ListDockerNetworks),
responses(
(status = 200, description = "The list of networks", body = ListDockerNetworksResponse),
),
)]
pub fn list_docker_networks() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListDockerNetworksResponse)]
#[error(mogh_error::Error)]
pub struct ListDockerNetworks {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListDockerNetworksResponse = Vec<NetworkListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectDockerNetwork",
description = "Inspect a docker network on the server.",
request_body(content = InspectDockerNetwork),
responses(
(status = 200, description = "The network", body = InspectDockerNetworkResponse),
),
)]
pub fn inspect_docker_network() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectDockerNetworkResponse)]
#[error(mogh_error::Error)]
pub struct InspectDockerNetwork {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub network: String,
}
#[typeshare]
pub type InspectDockerNetworkResponse = Network;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListDockerImages",
description = "List the docker images locally cached on the target server.",
request_body(content = ListDockerImages),
responses(
(status = 200, description = "The list of images", body = ListDockerImagesResponse),
),
)]
pub fn list_docker_images() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListDockerImagesResponse)]
#[error(mogh_error::Error)]
pub struct ListDockerImages {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListDockerImagesResponse = Vec<ImageListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectDockerImage",
description = "Inspect a docker image on the server.",
request_body(content = InspectDockerImage),
responses(
(status = 200, description = "The image", body = InspectDockerImageResponse),
),
)]
pub fn inspect_docker_image() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectDockerImageResponse)]
#[error(mogh_error::Error)]
pub struct InspectDockerImage {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub image: String,
}
#[typeshare]
pub type InspectDockerImageResponse = Image;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListDockerImageHistory",
description = "Get image history from the server.",
request_body(content = ListDockerImageHistory),
responses(
(status = 200, description = "The image history", body = ListDockerImageHistoryResponse),
),
)]
pub fn list_docker_image_history() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListDockerImageHistoryResponse)]
#[error(mogh_error::Error)]
pub struct ListDockerImageHistory {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub image: String,
}
#[typeshare]
pub type ListDockerImageHistoryResponse =
Vec<ImageHistoryResponseItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/ListDockerVolumes",
description = "List all docker volumes on the target server.",
request_body(content = ListDockerVolumes),
responses(
(status = 200, description = "The list of volumes", body = ListDockerVolumesResponse),
),
)]
pub fn list_docker_volumes() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListDockerVolumesResponse)]
#[error(mogh_error::Error)]
pub struct ListDockerVolumes {
#[serde(alias = "id", alias = "name")]
pub server: String,
}
#[typeshare]
pub type ListDockerVolumesResponse = Vec<VolumeListItem>;
#[cfg(feature = "utoipa")]
#[utoipa::path(
post,
path = "/InspectDockerVolume",
description = "Inspect a docker volume on the server.",
request_body(content = InspectDockerVolume),
responses(
(status = 200, description = "The volume", body = InspectDockerVolumeResponse),
),
)]
pub fn inspect_docker_volume() {}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectDockerVolumeResponse)]
#[error(mogh_error::Error)]
pub struct InspectDockerVolume {
#[serde(alias = "id", alias = "name")]
pub server: String,
pub volume: String,
}
#[typeshare]
pub type InspectDockerVolumeResponse = Volume;