diff --git a/tracing-surreal/src/stop.rs b/tracing-surreal/src/stop.rs index e73ab87..fa3d084 100644 --- a/tracing-surreal/src/stop.rs +++ b/tracing-surreal/src/stop.rs @@ -1,4 +1,4 @@ -use crate::tracing_msg::{current_exe_name, ClientHandshake, MsgFormat, Role}; +use crate::tracing_msg::{current_exe_name, ClientHandshake, ClientRole, MsgFormat}; use chrono::{DateTime, Local}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -28,6 +28,25 @@ struct RID { id: RecordId, } +#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[serde(rename_all = "lowercase")] +enum Role { + Host, + Pusher, + Observer, + Director, +} + +impl From for Role { + fn from(value: ClientRole) -> Self { + match value { + ClientRole::Pusher => Self::Pusher, + ClientRole::Observer => Self::Observer, + ClientRole::Director => Self::Director, + } + } +} + impl Stop { pub async fn init(db: Surreal, app: &str) -> Result { db.use_db(format!("app-tracing-{}", app)).await?; @@ -94,7 +113,7 @@ impl Stop { pub async fn client_handshake( &self, client_info: ClientHandshake, - client_role: Role, + client_role: ClientRole, client_addr: SocketAddr, query_map: Option>, ) -> surrealdb::Result { @@ -103,7 +122,7 @@ impl Stop { &self.session_id, &self.formatted_timestamp, &client_info.client_name, - client_role, + client_role.into(), &client_info.proc_name, client_info.proc_id, Some(client_info.msg_format), diff --git a/tracing-surreal/src/tmp/server.rs b/tracing-surreal/src/tmp/server.rs index 50b0db2..f9f98c3 100644 --- a/tracing-surreal/src/tmp/server.rs +++ b/tracing-surreal/src/tmp/server.rs @@ -1,4 +1,4 @@ -use crate::{stop::Stop, tracing_msg::Role}; +use crate::{stop::Stop, tracing_msg::ClientRole}; use est::task::CloseAndWait; use std::{ collections::HashMap, @@ -270,7 +270,7 @@ impl ServerBuilder { query, auth_args.pusher_token, role_send, - Role::Pusher, + ClientRole::Pusher, resp ); } @@ -280,7 +280,7 @@ impl ServerBuilder { query, auth_args.observer_token, role_send, - Role::Observer, + ClientRole::Observer, resp ); } @@ -290,7 +290,7 @@ impl ServerBuilder { query, auth_args.director_token, role_send, - Role::Director, + ClientRole::Director, resp ); } @@ -313,7 +313,7 @@ impl ServerBuilder { }; println!("inner_stream: {:?}", stream); - println!("inner_role: {:?}", role); + println!("client_role: {:?}", role); println!("query_map: {:?}", query_map); }); } @@ -358,8 +358,8 @@ impl BuildServerDefault for Stop { fn token_auth( query: Option, serde_qs::Error>>, token_need: Option, - role_send: oneshot::Sender, - role: Role, + role_send: oneshot::Sender, + role: ClientRole, resp: Response, ) -> Result { if let Some(token_need) = token_need { diff --git a/tracing-surreal/src/tracing_msg.rs b/tracing-surreal/src/tracing_msg.rs index 0134858..116f22e 100644 --- a/tracing-surreal/src/tracing_msg.rs +++ b/tracing-surreal/src/tracing_msg.rs @@ -1,14 +1,15 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum Role { - Host, +#[serde(rename_all = "lowercase")] +pub enum ClientRole { Pusher, Observer, Director, } #[derive(Serialize, Deserialize, Default, Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[serde(rename_all = "lowercase")] pub enum MsgFormat { Json, #[default]