doc more api

This commit is contained in:
mbecker20
2024-04-27 02:20:09 -07:00
parent b5ea6d43f3
commit 9509b23dc1
9 changed files with 103 additions and 12 deletions

View File

@@ -3,13 +3,18 @@ use resolver_api::derive::Request;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::update::Update;
use crate::entities::{update::Update, NoData};
use super::MonitorExecuteRequest;
//
/// Executes the target build. Response: [Update]
/// Executes the target build. Response: [Update].
///
/// 1. Get a handle to the builder. If using AWS builder, this means starting a builder ec2 instance.
/// 2. Clone the repo on the builder. If an `on_clone` commmand is given, it will be executed.
/// 3. Execute `docker build {...params}`, where params are determined using the builds configuration.
/// 4. If a dockerhub account is attached, the build will be pushed to that account.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -38,5 +43,4 @@ pub struct CancelBuild {
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CancelBuildResponse {}
pub type CancelBuildResponse = NoData;

View File

@@ -9,8 +9,13 @@ use crate::entities::{
use super::MonitorExecuteRequest;
//
/// Deploys the container for the target deployment. Response: [Update].
///
/// 1. Pulls the image onto the target server.
/// 2. If the container is already running,
/// it will be stopped and removed using `docker container rm ${container_name}`.
/// 3. The container will be run using `docker run {...params}`,
/// where params are determined by the deployment's configuration.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -20,12 +25,17 @@ use super::MonitorExecuteRequest;
pub struct Deploy {
/// Name or id
pub deployment: String,
/// Override the default termination signal specified in the deployment.
pub stop_signal: Option<TerminationSignal>,
/// Override the default termination max time.
pub stop_time: Option<i32>,
}
//
/// Starts the container for the target deployment. Response: [Update]
///
/// 1. Runs `docker start ${container_name}`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -39,6 +49,9 @@ pub struct StartContainer {
//
/// Stops the container for the target deployment. Response: [Update]
///
/// 1. Runs `docker stop ${container_name}`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -48,10 +61,15 @@ pub struct StartContainer {
pub struct StopContainer {
/// Name or id
pub deployment: String,
/// Override the default termination signal specified in the deployment.
pub signal: Option<TerminationSignal>,
/// Override the default termination max time.
pub time: Option<i32>,
}
/// Stops all deployments on the target server. Response: [Update]
///
/// 1. Runs [StopContainer] on all deployments on the server concurrently.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -65,6 +83,10 @@ pub struct StopAllContainers {
//
/// Stops and removes the container for the target deployment.
/// Reponse: [Update].
///
/// 1. The container is stopped and removed using `docker container rm ${container_name}`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -72,8 +94,10 @@ pub struct StopAllContainers {
#[empty_traits(MonitorExecuteRequest)]
#[response(Update)]
pub struct RemoveContainer {
/// Name or id
/// Name or id.
pub deployment: String,
/// Override the default termination signal specified in the deployment.
pub signal: Option<TerminationSignal>,
/// Override the default termination max time.
pub time: Option<i32>,
}

View File

@@ -15,15 +15,18 @@ pub use procedure::*;
pub use repo::*;
pub use server::*;
use crate::entities::NoData;
pub trait MonitorExecuteRequest: HasResponse {}
/// A wrapper for all monitor exections.
#[typeshare]
#[derive(Debug, Clone, Serialize, Deserialize, EnumVariants)]
#[variant_derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(tag = "type", content = "params")]
pub enum Execution {
/// For new executions upon instantiation
None(None),
None(NoData),
// PROCEDURE
RunProcedure(RunProcedure),
@@ -47,7 +50,3 @@ pub enum Execution {
PruneDockerImages(PruneDockerImages),
PruneDockerContainers(PruneDockerContainers),
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct None {}

View File

@@ -7,6 +7,7 @@ use crate::entities::update::Update;
use super::MonitorExecuteRequest;
/// Runs the target procedure. Response: [Update]
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,

View File

@@ -9,6 +9,13 @@ use super::MonitorExecuteRequest;
//
/// Clones the target repo. Response: [Update].
///
/// 1. Clones the repo on the target server using `git clone https://{$token?}@github.com/${repo} -b ${branch}`.
/// The token will only be used if a github account is specified,
/// and must be declared in the periphery configuration on the target server.
/// 2. If `on_clone` and `on_pull` are specified, they will be executed.
/// `on_clone` will be executed before `on_pull`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -22,6 +29,10 @@ pub struct CloneRepo {
//
/// Pulls the target repo. Response: [Update].
///
/// 1. Pulls the repo on the target server using `git pull`.
/// 2. If `on_pull` is specified, it will be executed after the pull is complete.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,

View File

@@ -9,6 +9,9 @@ use super::MonitorExecuteRequest;
//
/// Prunes the docker networks on the target server. Response: [Update].
///
/// 1. Runs `docker network prune -f`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -22,6 +25,9 @@ pub struct PruneDockerNetworks {
//
/// Prunes the docker images on the target server. Response: [Update].
///
/// 1. Runs `docker image prune -a -f`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -35,6 +41,9 @@ pub struct PruneDockerImages {
//
/// Prunes the docker containers on the target server. Response: [Update].
///
/// 1. Runs `docker container prune -f`.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,

View File

@@ -7,6 +7,8 @@ use crate::entities::{alert::Alert, MongoDocument, I64, U64};
use super::MonitorReadRequest;
/// Get a paginated list of alerts sorted by timestamp descending.
/// Response: [ListAlertsResponse].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits,
@@ -14,20 +16,50 @@ use super::MonitorReadRequest;
#[empty_traits(MonitorReadRequest)]
#[response(ListAlertsResponse)]
pub struct ListAlerts {
/// Pass a custom mongo query to filter the alerts.
///
/// ## Example JSON
/// ```
/// {
/// "resolved": "false",
/// "level": "CRITICAL",
/// "$or": [
/// {
/// "target": {
/// "type": "Server",
/// "id": "6608bf89cb2a12b257ab6c09"
/// }
/// },
/// {
/// "target": {
/// "type": "Server",
/// "id": "660a5f60b74f90d5dae45fa3"
/// }
/// }
/// ]
/// }
/// ```
/// This will filter to only include open alerts that have CRITICAL level on those two servers.
pub query: Option<MongoDocument>,
/// Retrieve older results by incrementing the page.
/// `page: 0` is default, and returns the most recent results.
#[serde(default)]
pub page: U64,
}
/// Response for [ListAlerts].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListAlertsResponse {
pub alerts: Vec<Alert>,
/// If more alerts exist, the next page will be given here.
/// Otherwise it will be `null`
pub next_page: Option<I64>,
}
//
/// Get an alert: Response: [Alert].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,

View File

@@ -11,6 +11,7 @@ use super::MonitorReadRequest;
//
/// Get a specific alerter. Response: [Alerter].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -28,6 +29,7 @@ pub type GetAlerterResponse = Alerter;
//
/// List alerters matching optional query. Response: [ListAlertersResponse].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits,
@@ -35,6 +37,7 @@ pub type GetAlerterResponse = Alerter;
#[empty_traits(MonitorReadRequest)]
#[response(ListAlertersResponse)]
pub struct ListAlerters {
/// Structured query to filter alerters.
#[serde(default)]
pub query: AlerterQuery,
}
@@ -44,6 +47,8 @@ pub type ListAlertersResponse = Vec<AlerterListItem>;
//
/// Gets a summary of data relating to all alerters.
/// Response: [GetAlertersSummaryResponse].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
@@ -52,6 +57,7 @@ pub type ListAlertersResponse = Vec<AlerterListItem>;
#[response(GetAlertersSummaryResponse)]
pub struct GetAlertersSummary {}
/// Response for [GetAlertersSummary].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetAlertersSummaryResponse {

View File

@@ -33,6 +33,11 @@ pub type MongoId = String;
#[typeshare(serialized_as = "__Serror")]
pub type _Serror = Serror;
/// Represents an empty json object: `{}`
#[typeshare]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NoData {}
pub fn all_logs_success(logs: &[update::Log]) -> bool {
for log in logs {
if !log.success {