1use crate::message::{
2 CommandFinished,
3 CommandStart,
4};
5use chrono::{
6 DateTime,
7 Utc,
8};
9use serde::{
10 Deserialize,
11 Serialize,
12};
13use std::path::PathBuf;
14use uuid::Uuid;
15
16#[derive(Debug, Serialize, Deserialize, Ord, PartialOrd, PartialEq, Eq)]
17pub struct Entry {
18 pub time_finished: DateTime<Utc>,
19 pub time_start: DateTime<Utc>,
20 pub hostname: String,
21 pub command: String,
22 pub pwd: PathBuf,
23 pub result: u16,
24 pub session_id: Uuid,
25 pub user: String,
26}
27
28impl Entry {
29 pub fn from_messages(start: CommandStart, finish: &CommandFinished) -> Self {
30 let command = start.command.trim_end();
31
32 let command = command
33 .strip_suffix("\\r\\n")
34 .or_else(|| command.strip_suffix("\\n"))
35 .unwrap_or(command)
36 .to_string();
37
38 let user = start.user.trim().to_string();
39 let hostname = start.hostname.trim().to_string();
40
41 Self {
42 time_finished: finish.time_stamp,
43 time_start: start.time_stamp,
44 hostname,
45 command,
46 pwd: start.pwd,
47 result: finish.result,
48 session_id: start.session_id,
49 user,
50 }
51 }
52}