forked from github-starred/komodo
0.2.4: add description and update description
This commit is contained in:
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -734,7 +734,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async_timing_util",
|
||||
@@ -753,7 +753,7 @@ dependencies = [
|
||||
"hmac",
|
||||
"jwt",
|
||||
"monitor_helpers",
|
||||
"monitor_types 0.2.2",
|
||||
"monitor_types 0.2.4",
|
||||
"mungos",
|
||||
"periphery_client",
|
||||
"serde",
|
||||
@@ -987,10 +987,10 @@ checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
|
||||
|
||||
[[package]]
|
||||
name = "db_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"monitor_types 0.2.2",
|
||||
"monitor_types 0.2.4",
|
||||
"mungos",
|
||||
]
|
||||
|
||||
@@ -1853,12 +1853,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "monitor_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"envy",
|
||||
"futures-util",
|
||||
"monitor_types 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"monitor_types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
@@ -1870,11 +1870,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "monitor_helpers"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
"monitor_types 0.2.2",
|
||||
"monitor_types 0.2.4",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1883,7 +1883,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "monitor_periphery"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async_timing_util",
|
||||
@@ -1895,7 +1895,7 @@ dependencies = [
|
||||
"envy",
|
||||
"futures",
|
||||
"monitor_helpers",
|
||||
"monitor_types 0.2.2",
|
||||
"monitor_types 0.2.4",
|
||||
"run_command",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
@@ -1908,7 +1908,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "monitor_types"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bollard",
|
||||
@@ -1925,9 +1925,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "monitor_types"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72e8b62148932ce7c499f16a7f0053dd9bf61ae97f66b62c0a3161203d8ca508"
|
||||
checksum = "891189d5f49168915fd4c81f4e59d8fdd937008a59431831f28de3d5f8cf2af2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bollard",
|
||||
@@ -2183,11 +2183,11 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "periphery_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"futures-util",
|
||||
"monitor_types 0.2.2",
|
||||
"monitor_types 0.2.4",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "core"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Context};
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::Path,
|
||||
http::{Request, StatusCode},
|
||||
middleware,
|
||||
routing::get,
|
||||
routing::{get, post},
|
||||
Extension, Json, Router,
|
||||
};
|
||||
use futures_util::Future;
|
||||
use helpers::handle_anyhow_error;
|
||||
use mungos::Deserialize;
|
||||
use types::User;
|
||||
use mungos::{doc, Deserialize};
|
||||
use types::{PermissionLevel, UpdateTarget, User};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use crate::{
|
||||
auth::{auth_request, JwtExtension, RequestUserExtension},
|
||||
state::StateExtension,
|
||||
auth::{auth_request, JwtExtension, RequestUser, RequestUserExtension},
|
||||
state::{State, StateExtension},
|
||||
};
|
||||
|
||||
pub mod build;
|
||||
@@ -27,6 +28,13 @@ pub mod secret;
|
||||
pub mod server;
|
||||
pub mod update;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Deserialize)]
|
||||
struct UpdateDescriptionBody {
|
||||
target: UpdateTarget,
|
||||
description: String,
|
||||
}
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route(
|
||||
@@ -56,6 +64,19 @@ pub fn router() -> Router {
|
||||
.to_string()
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/update_description",
|
||||
post(
|
||||
|state: StateExtension,
|
||||
user: RequestUserExtension,
|
||||
body: Json<UpdateDescriptionBody>| async move {
|
||||
state
|
||||
.update_description(&body.target, &body.description, &user)
|
||||
.await
|
||||
.map_err(handle_anyhow_error)
|
||||
},
|
||||
),
|
||||
)
|
||||
.route("/users", get(get_users))
|
||||
.nest("/build", build::router())
|
||||
.nest("/deployment", deployment::router())
|
||||
@@ -128,3 +149,57 @@ where
|
||||
.map_err(handle_anyhow_error)?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub async fn update_description(
|
||||
&self,
|
||||
target: &UpdateTarget,
|
||||
description: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<()> {
|
||||
match target {
|
||||
UpdateTarget::Build(id) => {
|
||||
self.get_build_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.db
|
||||
.builds
|
||||
.update_one::<()>(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
}
|
||||
UpdateTarget::Deployment(id) => {
|
||||
self.get_deployment_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.db
|
||||
.builds
|
||||
.update_one::<()>(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
}
|
||||
UpdateTarget::Server(id) => {
|
||||
self.get_server_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.db
|
||||
.builds
|
||||
.update_one::<()>(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
}
|
||||
UpdateTarget::Group(id) => {
|
||||
self.get_group_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.db
|
||||
.builds
|
||||
.update_one::<()>(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
}
|
||||
UpdateTarget::Procedure(id) => {
|
||||
self.get_procedure_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.db
|
||||
.builds
|
||||
.update_one::<()>(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
}
|
||||
_ => return Err(anyhow!("invalid target: {target:?}")),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ impl State {
|
||||
}
|
||||
let futures = servers.unwrap().into_iter().map(|server| async move {
|
||||
let _ = self.periphery.image_prune(&server).await;
|
||||
let _ = self.periphery.container_prune(&server).await;
|
||||
});
|
||||
join_all(futures).await;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export type PermissionsMap = Record<string, PermissionLevel>;
|
||||
export interface Action {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
path: string;
|
||||
command: string;
|
||||
server_ids?: string[];
|
||||
@@ -22,6 +23,7 @@ export interface Action {
|
||||
export interface Build {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
permissions?: PermissionsMap;
|
||||
server_id?: string;
|
||||
aws_config?: AwsBuilderBuildConfig;
|
||||
@@ -94,6 +96,7 @@ export interface AmiAccounts {
|
||||
export interface Deployment {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
server_id: string;
|
||||
permissions?: PermissionsMap;
|
||||
docker_run_args: DockerRunArgs;
|
||||
@@ -164,6 +167,7 @@ export interface DockerContainerStats {
|
||||
export interface Group {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
permissions?: PermissionsMap;
|
||||
builds: string[];
|
||||
deployments: string[];
|
||||
@@ -192,6 +196,7 @@ export interface UserCredentials {
|
||||
export interface Procedure {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
stages?: ProcedureStage[];
|
||||
webhook_branches?: string[];
|
||||
permissions?: PermissionsMap;
|
||||
@@ -207,6 +212,7 @@ export interface ProcedureStage {
|
||||
export interface Server {
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
address: string;
|
||||
permissions?: PermissionsMap;
|
||||
enabled: boolean;
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
ModifyUserCreateServerBody,
|
||||
ModifyUserEnabledBody,
|
||||
PermissionsUpdateBody,
|
||||
UpdateDescriptionBody,
|
||||
} from "./client_types";
|
||||
import { generateQuery, QueryObject } from "./helpers";
|
||||
|
||||
@@ -111,7 +112,7 @@ export class Client {
|
||||
}
|
||||
}
|
||||
|
||||
get_username(user_id: string): Promise<string> {
|
||||
get_username(user_id: string): Promise<string> {
|
||||
return this.get(`/api/username/${user_id}`);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,11 @@ export class Client {
|
||||
}
|
||||
|
||||
get_github_webhook_base_url(): Promise<string> {
|
||||
return this.get("/api/github_webhook_base_url")
|
||||
return this.get("/api/github_webhook_base_url");
|
||||
}
|
||||
|
||||
update_description(body: UpdateDescriptionBody): Promise<undefined> {
|
||||
return this.post("/api/update_description", body);
|
||||
}
|
||||
|
||||
// deployment
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Generated by typeshare 1.0.0
|
||||
*/
|
||||
|
||||
import { PermissionLevel, PermissionsTarget } from "../types";
|
||||
import { PermissionLevel, PermissionsTarget, UpdateTarget } from "../types";
|
||||
|
||||
export interface CreateBuildBody {
|
||||
name: string;
|
||||
@@ -37,6 +37,11 @@ export interface CreateGroupBody {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UpdateDescriptionBody {
|
||||
target: UpdateTarget;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface PermissionsUpdateBody {
|
||||
user_id: string;
|
||||
permission: PermissionLevel;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "db_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "monitor_helpers"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
authors = ["MoghTech"]
|
||||
description = "helpers used as dependency for mogh tech monitor"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "monitor_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
authors = ["MoghTech"]
|
||||
description = "a client to interact with the monitor system"
|
||||
@@ -9,7 +9,7 @@ license = "GPL-3.0-or-later"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
monitor_types = "0.2.2"
|
||||
monitor_types = "0.2.4"
|
||||
# monitor_types = { path = "../types" }
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
tokio-tungstenite = { version = "0.18", features=["native-tls"] }
|
||||
|
||||
@@ -10,6 +10,7 @@ pub use futures_util;
|
||||
pub use tokio_tungstenite;
|
||||
|
||||
pub use monitor_types as types;
|
||||
use types::UpdateTarget;
|
||||
|
||||
mod build;
|
||||
mod deployment;
|
||||
@@ -146,6 +147,19 @@ impl MonitorClient {
|
||||
.context("failed at call to get_github_webhook_base_url")
|
||||
}
|
||||
|
||||
pub async fn update_description(
|
||||
&self,
|
||||
target: UpdateTarget,
|
||||
description: &str,
|
||||
) -> anyhow::Result<()> {
|
||||
self.post(
|
||||
"/api/update_description",
|
||||
json!({ "target": target, "description": description }),
|
||||
)
|
||||
.await
|
||||
.context("failed at call to update_description")
|
||||
}
|
||||
|
||||
async fn get<R: DeserializeOwned>(
|
||||
&self,
|
||||
endpoint: &str,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "periphery_client"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "monitor_types"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
authors = ["MoghTech"]
|
||||
description = "types for the mogh tech monitor"
|
||||
|
||||
@@ -23,6 +23,11 @@ pub struct Action {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub path: String,
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ pub struct Build {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[diff(attr(#[serde(skip_serializing)]))]
|
||||
#[builder(setter(skip))]
|
||||
|
||||
@@ -24,6 +24,11 @@ pub struct Deployment {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String, // must be formatted to be compat with docker
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub server_id: String,
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ pub struct Group {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[diff(attr(#[serde(skip_serializing)]))]
|
||||
#[builder(setter(skip))]
|
||||
|
||||
@@ -23,6 +23,11 @@ pub struct Procedure {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "vec_diff_no_change")]))]
|
||||
|
||||
@@ -26,6 +26,11 @@ pub struct Server {
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub address: String,
|
||||
|
||||
@@ -94,7 +99,7 @@ impl Default for Server {
|
||||
address: Default::default(),
|
||||
permissions: Default::default(),
|
||||
enabled: true,
|
||||
auto_prune: false,
|
||||
auto_prune: true,
|
||||
to_notify: Default::default(),
|
||||
cpu_alert: default_cpu_alert(),
|
||||
mem_alert: default_mem_alert(),
|
||||
@@ -102,6 +107,7 @@ impl Default for Server {
|
||||
stats_interval: Default::default(),
|
||||
region: Default::default(),
|
||||
instance_id: Default::default(),
|
||||
description: Default::default(),
|
||||
created_at: Default::default(),
|
||||
updated_at: Default::default(),
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "monitor_periphery"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
authors = ["MoghTech"]
|
||||
description = "monitor periphery binary | run monitor periphery as system daemon"
|
||||
|
||||
Reference in New Issue
Block a user