mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
handle non-string users
This commit is contained in:
parent
7e166af604
commit
de82dcf793
3 changed files with 43 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ use crate::logfile::LogIndex;
|
||||||
use ahash::AHasher;
|
use ahash::AHasher;
|
||||||
use derive_more::{Display, From};
|
use derive_more::{Display, From};
|
||||||
use logsmash_data::LogLevel;
|
use logsmash_data::LogLevel;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Deserializer};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
@ -30,7 +30,7 @@ pub struct LogLine<'a> {
|
||||||
pub index: LogIndex,
|
pub index: LogIndex,
|
||||||
#[serde(rename = "reqId")]
|
#[serde(rename = "reqId")]
|
||||||
pub request_id: TinyAsciiStr<32>,
|
pub request_id: TinyAsciiStr<32>,
|
||||||
pub user: TinyAsciiStr<64>,
|
pub user: LogUser,
|
||||||
pub method: TinyAsciiStr<12>,
|
pub method: TinyAsciiStr<12>,
|
||||||
pub url: Cow<'a, str>,
|
pub url: Cow<'a, str>,
|
||||||
#[serde(rename = "remoteAddr")]
|
#[serde(rename = "remoteAddr")]
|
||||||
|
|
@ -44,6 +44,39 @@ pub struct LogLine<'a> {
|
||||||
pub time: OffsetDateTime,
|
pub time: OffsetDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum LogUser {
|
||||||
|
None,
|
||||||
|
User(TinyAsciiStr<64>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LogUser {
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
LogUser::None => "",
|
||||||
|
LogUser::User(user) => user.as_str(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TinyAsciiStr<64>> for LogUser {
|
||||||
|
fn from(user: TinyAsciiStr<64>) -> Self {
|
||||||
|
LogUser::User(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for LogUser {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
match TinyAsciiStr::deserialize(deserializer) {
|
||||||
|
Ok(user) => Ok(LogUser::User(user)),
|
||||||
|
Err(_) => Ok(LogUser::None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mod date {
|
mod date {
|
||||||
use crate::logfile::logline::CUSTOM_TIME_FORMAT;
|
use crate::logfile::logline::CUSTOM_TIME_FORMAT;
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
|
|
@ -160,7 +193,7 @@ impl<'a> LogLine<'a> {
|
||||||
|| filter_part.is_match(&self.url)
|
|| filter_part.is_match(&self.url)
|
||||||
|| filter_part.is_match(&self.method)
|
|| filter_part.is_match(&self.method)
|
||||||
|| filter_part.is_match(&self.remote)
|
|| filter_part.is_match(&self.remote)
|
||||||
|| filter_part.is_match(&self.user)
|
|| filter_part.is_match(self.user.as_str())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ fn test_matcher() {
|
||||||
index: LogIndex::from(0),
|
index: LogIndex::from(0),
|
||||||
method: TinyAsciiStr::from_str("GET").unwrap(),
|
method: TinyAsciiStr::from_str("GET").unwrap(),
|
||||||
remote: TinyAsciiStr::from_str("1.2.3.4").unwrap(),
|
remote: TinyAsciiStr::from_str("1.2.3.4").unwrap(),
|
||||||
user: TinyAsciiStr::from_str("user").unwrap(),
|
user: TinyAsciiStr::from_str("user").unwrap().into(),
|
||||||
url: "/url".into(),
|
url: "/url".into(),
|
||||||
request_id: TinyAsciiStr::from_str("123456").unwrap(),
|
request_id: TinyAsciiStr::from_str("123456").unwrap(),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,12 @@ impl StatefulWidget for GroupedLogs<'_> {
|
||||||
.wrap(Wrap::default()),
|
.wrap(Wrap::default()),
|
||||||
GroupedLogGrouping::Request => Paragraph::new(format!(
|
GroupedLogGrouping::Request => Paragraph::new(format!(
|
||||||
"{} {}\n\n {} from {} by {} - Nextcloud {}",
|
"{} {}\n\n {} from {} by {} - Nextcloud {}",
|
||||||
line.method, line.url, line.request_id, line.remote, line.user, line.version,
|
line.method,
|
||||||
|
line.url,
|
||||||
|
line.request_id,
|
||||||
|
line.remote,
|
||||||
|
line.user.as_str(),
|
||||||
|
line.version,
|
||||||
))
|
))
|
||||||
.wrap(Wrap::default()),
|
.wrap(Wrap::default()),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue