forked from github-starred/komodo
get docker compose testing setup working
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use anyhow::Context;
|
||||
use monitor_types::{Build, SystemStats, Update};
|
||||
use serde_json::json;
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::MonitorClient;
|
||||
|
||||
impl MonitorClient {
|
||||
pub async fn list_builds(&self) -> anyhow::Result<Vec<Build>> {
|
||||
self.get("/api/build/list")
|
||||
pub async fn list_builds(&self, query: impl Into<Option<Value>>) -> anyhow::Result<Vec<Build>> {
|
||||
self.get("/api/build/list", query.into())
|
||||
.await
|
||||
.context("failed at list builds")
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use anyhow::Context;
|
||||
use monitor_types::{Deployment, SystemStats, Update};
|
||||
use serde_json::json;
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::MonitorClient;
|
||||
|
||||
impl MonitorClient {
|
||||
pub async fn list_deployments(&self) -> anyhow::Result<Vec<Deployment>> {
|
||||
self.get("/api/deployment/list")
|
||||
pub async fn list_deployments(
|
||||
&self,
|
||||
query: impl Into<Option<Value>>,
|
||||
) -> anyhow::Result<Vec<Deployment>> {
|
||||
self.get("/api/deployment/list", query.into())
|
||||
.await
|
||||
.context("failed at list deployments")
|
||||
}
|
||||
|
||||
@@ -63,11 +63,28 @@ impl MonitorClient {
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
async fn get<R: DeserializeOwned>(&self, endpoint: &str) -> anyhow::Result<R> {
|
||||
async fn create_user(
|
||||
&self,
|
||||
username: impl Into<String>,
|
||||
password: impl Into<String>,
|
||||
) -> anyhow::Result<String> {
|
||||
self.post_string(
|
||||
"/auth/local/create_user",
|
||||
json!({ "username": username.into(), "password": password.into() }),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get<R: DeserializeOwned>(
|
||||
&self,
|
||||
endpoint: &str,
|
||||
query: impl Serialize,
|
||||
) -> anyhow::Result<R> {
|
||||
let res = self
|
||||
.http_client
|
||||
.get(format!("{}{endpoint}", self.url))
|
||||
.header("Authorization", format!("Bearer {}", self.token))
|
||||
.query(&query)
|
||||
.send()
|
||||
.await
|
||||
.context("failed to reach monitor api")?;
|
||||
@@ -85,11 +102,12 @@ impl MonitorClient {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_string(&self, endpoint: &str) -> anyhow::Result<String> {
|
||||
async fn get_string(&self, endpoint: &str, query: impl Serialize) -> anyhow::Result<String> {
|
||||
let res = self
|
||||
.http_client
|
||||
.get(format!("{}{endpoint}", self.url))
|
||||
.header("Authorization", format!("Bearer {}", self.token))
|
||||
.query(&query)
|
||||
.send()
|
||||
.await
|
||||
.context("failed to reach monitor api")?;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use anyhow::Context;
|
||||
use monitor_types::{Server, SystemStats};
|
||||
use serde_json::json;
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::MonitorClient;
|
||||
|
||||
impl MonitorClient {
|
||||
pub async fn list_servers(&self) -> anyhow::Result<Vec<Server>> {
|
||||
self.get("/api/server/list")
|
||||
pub async fn list_servers(
|
||||
&self,
|
||||
query: impl Into<Option<Value>>,
|
||||
) -> anyhow::Result<Vec<Server>> {
|
||||
self.get("/api/server/list", query.into())
|
||||
.await
|
||||
.context("failed at list servers")
|
||||
}
|
||||
@@ -35,7 +39,7 @@ impl MonitorClient {
|
||||
}
|
||||
|
||||
pub async fn get_server_stats(&self, id: &str) -> anyhow::Result<SystemStats> {
|
||||
self.get(&format!("/api/server/stats/{id}"))
|
||||
self.get(&format!("/api/server/stats/{id}"), Option::<()>::None)
|
||||
.await
|
||||
.context(format!("failed to get server stats at id {id}"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user