forked from github-starred/komodo
implement get updates list
This commit is contained in:
@@ -36,7 +36,7 @@ impl MonitorClient {
|
||||
}
|
||||
|
||||
pub async fn create_full_build(&self, build: &Build) -> anyhow::Result<Build> {
|
||||
self.post("/api/build/create_full", build)
|
||||
self.post::<&Build, _>("/api/build/create_full", build)
|
||||
.await
|
||||
.context(format!("failed at creating full build"))
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ impl MonitorClient {
|
||||
&self,
|
||||
deployment: &Deployment,
|
||||
) -> anyhow::Result<Deployment> {
|
||||
self.post("/api/deployment/create_full", deployment)
|
||||
self.post::<&Deployment, _>("/api/deployment/create_full", deployment)
|
||||
.await
|
||||
.context(format!("failed at creating full deployment"))
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ mod permissions;
|
||||
mod procedure;
|
||||
mod secret;
|
||||
mod server;
|
||||
mod update;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MonitorClient {
|
||||
|
||||
@@ -29,7 +29,7 @@ impl MonitorClient {
|
||||
}
|
||||
|
||||
pub async fn create_full_procedure(&self, procedure: &Procedure) -> anyhow::Result<Procedure> {
|
||||
self.post("/api/procedure/create_full", procedure)
|
||||
self.post::<&Procedure, _>("/api/procedure/create_full", procedure)
|
||||
.await
|
||||
.context(format!("failed at creating full procedure"))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Context;
|
||||
use monitor_types::{
|
||||
BasicContainerInfo, ImageSummary, Log, Network, Server, ServerActionState, SystemStats,
|
||||
BasicContainerInfo, ImageSummary, Log, Network, Server, ServerActionState, ServerWithStatus,
|
||||
SystemStats,
|
||||
};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@@ -10,7 +11,7 @@ impl MonitorClient {
|
||||
pub async fn list_servers(
|
||||
&self,
|
||||
query: impl Into<Option<Value>>,
|
||||
) -> anyhow::Result<Vec<Server>> {
|
||||
) -> anyhow::Result<Vec<ServerWithStatus>> {
|
||||
self.get("/api/server/list", query.into())
|
||||
.await
|
||||
.context("failed at list servers")
|
||||
@@ -44,7 +45,7 @@ impl MonitorClient {
|
||||
}
|
||||
|
||||
pub async fn create_full_server(&self, server: &Server) -> anyhow::Result<Server> {
|
||||
self.post("/api/server/create_full", server)
|
||||
self.post::<&Server, _>("/api/server/create_full", server)
|
||||
.await
|
||||
.context(format!("failed at creating full server"))
|
||||
}
|
||||
|
||||
30
lib/monitor_client/src/update.rs
Normal file
30
lib/monitor_client/src/update.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use monitor_types::{Update, UpdateTarget};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::MonitorClient;
|
||||
|
||||
impl MonitorClient {
|
||||
pub async fn list_updates(
|
||||
&self,
|
||||
target: impl Into<Option<UpdateTarget>>,
|
||||
offset: u64,
|
||||
) -> anyhow::Result<Vec<Update>> {
|
||||
let mut query = json!({ "offset": offset });
|
||||
if let Some(target) = target.into() {
|
||||
let mut value =
|
||||
serde_json::from_str::<Value>(&serde_json::to_string(&target).unwrap()).unwrap();
|
||||
let value = value.as_object_mut().unwrap();
|
||||
query
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.insert("type".to_string(), value.remove("type").unwrap());
|
||||
if let Some(target_id) = value.remove("id") {
|
||||
query
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.insert("id".to_string(), target_id);
|
||||
}
|
||||
}
|
||||
self.get("/api/update/list", query).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user