test periphery api

This commit is contained in:
mbecker20
2023-07-03 06:09:30 +00:00
parent 312f7a9003
commit 9a1619c554
4 changed files with 10 additions and 4 deletions

View File

@@ -228,6 +228,8 @@ pub struct DockerContainerStats {
EnumString, EnumString,
MungosIndexed, MungosIndexed,
)] )]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum DockerContainerState { pub enum DockerContainerState {
#[default] #[default]
Unknown, Unknown,

View File

@@ -39,7 +39,7 @@ pub async fn guard_request_by_passkey(
format!("failed to get passkey from authorization header as str: {e:?}"), format!("failed to get passkey from authorization header as str: {e:?}"),
) )
})? })?
.to_string(); .replace("Bearer ", "");
if state.config.passkeys.contains(&req_passkey) { if state.config.passkeys.contains(&req_passkey) {
Ok(next.run(req).await) Ok(next.run(req).await)
} else { } else {

View File

@@ -1,4 +1,4 @@
use anyhow::anyhow; use anyhow::{anyhow, Context};
use bollard::{container::ListContainersOptions, Docker}; use bollard::{container::ListContainersOptions, Docker};
use monitor_types::entities::{ use monitor_types::entities::{
deployment::BasicContainerInfo, deployment::BasicContainerInfo,
@@ -38,7 +38,11 @@ impl DockerClient {
.ok_or(anyhow!("no names on container (empty vec)"))? .ok_or(anyhow!("no names on container (empty vec)"))?
.replace('/', ""), .replace('/', ""),
image: s.image.unwrap_or(String::from("unknown")), image: s.image.unwrap_or(String::from("unknown")),
state: s.state.unwrap().parse().unwrap(), state: s
.state
.context("no container state")?
.parse()
.context("failed to parse container state")?,
status: s.status, status: s.status,
}; };
Ok::<_, anyhow::Error>(info) Ok::<_, anyhow::Error>(info)

View File

@@ -43,7 +43,7 @@ async fn app() -> anyhow::Result<()> {
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}"))) .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))
}) })
.await .await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}"))); .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:#?}")));
if let Err(e) = &res { if let Err(e) = &res {
debug!("request {req_id} SPAWN ERROR: {e:?}"); debug!("request {req_id} SPAWN ERROR: {e:?}");
} }