Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust Collector #544

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add types
  • Loading branch information
akshay288 committed Jun 25, 2023
commit 9bd1c90e04728a14dc9d4da412c5128dc1d4f046
92 changes: 1 addition & 91 deletions collector/src/api/log_trace.rs
Original file line number Diff line number Diff line change
@@ -1,96 +1,6 @@
use axum::extract::{self, Extension};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use std::collections::{HashMap, HashSet};

use crate::types::CurrentUser;

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct KeyVal {
pub name: String,
pub value: String,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiUrl {
pub host: String,
pub path: String,
pub parameters: Vec<KeyVal>,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiRequest {
pub method: String,
pub url: ApiUrl,
pub headers: Vec<KeyVal>,
pub body: String,
pub user: Option<String>,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiResponse {
pub status: u16,
pub headers: Vec<KeyVal>,
pub body: String,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiMeta {
pub environment: String,
pub incoming: bool,
pub source: String,
pub source_port: u16,
pub destination: String,
pub destination_port: u16,
pub original_source: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessTraceRes {
pub block: bool,
pub attack_detections: Option<HashMap<String, HashSet<String>>>,
pub sensitive_data_detected: Option<HashMap<String, HashSet<String>>>,
pub data_types: Option<HashMap<String, HashSet<String>>>,
pub graphql_paths: Option<HashSet<String>>,
pub request_content_type: String,
pub response_content_type: String,
pub request_tags: Option<Vec<String>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionMeta {
pub authentication_provided: Option<bool>,
pub authentication_successful: Option<bool>,
pub auth_type: Option<String>,
pub unique_session_key: Option<String>,
pub user: Option<String>,
pub user_agent: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Encryption {
pub key: String,
pub generated_ivs: HashMap<String, Vec<u8>>,
}

#[skip_serializing_none]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessedApiTrace {
pub request: ApiRequest,
pub response: Option<ApiResponse>,
pub meta: Option<ApiMeta>,
pub processed_trace_data: Option<ProcessTraceRes>,
pub redacted: bool,
pub encryption: Option<Encryption>,
pub session_meta: Option<SessionMeta>,
pub analysis_type: String,
}
use crate::types::{CurrentUser, ProcessedApiTrace};

pub async fn log_trace_batch(
Extension(current_user): Extension<CurrentUser>,
Expand Down
91 changes: 91 additions & 0 deletions collector/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,98 @@
use std::collections::{HashMap, HashSet};

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use uuid;

#[derive(Clone, Debug)]
pub struct CurrentUser {
pub user_uuid: Option<uuid::Uuid>,
pub organization_uuid: uuid::Uuid,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct KeyVal {
pub name: String,
pub value: String,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiUrl {
pub host: String,
pub path: String,
pub parameters: Vec<KeyVal>,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiRequest {
pub method: String,
pub url: ApiUrl,
pub headers: Vec<KeyVal>,
pub body: String,
pub user: Option<String>,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct ApiResponse {
pub status: u16,
pub headers: Vec<KeyVal>,
pub body: String,
}

#[derive(Deserialize, Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiMeta {
pub environment: String,
pub incoming: bool,
pub source: String,
pub source_port: u16,
pub destination: String,
pub destination_port: u16,
pub original_source: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessTraceRes {
pub block: bool,
pub attack_detections: Option<HashMap<String, HashSet<String>>>,
pub sensitive_data_detected: Option<HashMap<String, HashSet<String>>>,
pub data_types: Option<HashMap<String, HashSet<String>>>,
pub graphql_paths: Option<HashSet<String>>,
pub request_content_type: String,
pub response_content_type: String,
pub request_tags: Option<Vec<String>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionMeta {
pub authentication_provided: Option<bool>,
pub authentication_successful: Option<bool>,
pub auth_type: Option<String>,
pub unique_session_key: Option<String>,
pub user: Option<String>,
pub user_agent: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Encryption {
pub key: String,
pub generated_ivs: HashMap<String, Vec<u8>>,
}

#[skip_serializing_none]
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProcessedApiTrace {
pub request: ApiRequest,
pub response: Option<ApiResponse>,
pub meta: Option<ApiMeta>,
pub processed_trace_data: Option<ProcessTraceRes>,
pub redacted: bool,
pub encryption: Option<Encryption>,
pub session_meta: Option<SessionMeta>,
pub analysis_type: String,
}