-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into kill_process
- Loading branch information
Showing
27 changed files
with
930 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
|
||
## [Unreleased] - 19-04-2024 | ||
|
||
### Added | ||
|
||
- v0.1.1 CHANGELOG.md added | ||
- v0.1.1 versioning started | ||
- v0.1.1 gRPC added for other services to notify their status | ||
- v0.1.1 proto file(s) introduced for gRPC. its a simple for now but will be extended | ||
- v0.1.1 build.rs added to compile proto files | ||
|
||
### Changed | ||
|
||
- v0.1.1 tokio crate updated to latest version | ||
- v0.1.1 Duration::seconds() is now deprecated, changed to try_seconds() | ||
|
||
## [0.1.0] | ||
|
||
### Added | ||
|
||
- v0.1.0 initial | ||
|
||
### Fixed | ||
|
||
### Changed | ||
|
||
### Removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::{env, error::Error, path::PathBuf}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let out_dir = PathBuf::from(env::var("OUT_DIR")?); | ||
|
||
tonic_build::configure() | ||
.protoc_arg("--experimental_allow_proto3_optional") | ||
.file_descriptor_set_path(out_dir.join("remonproto_descriptor.bin")) | ||
.compile(&["./proto/notification.proto"], &["proto"])?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
syntax = "proto3"; | ||
|
||
package remonproto; | ||
|
||
service NotificationService { | ||
rpc SendNotification(NotificationRequest) returns (NotificationResponse) {} | ||
rpc Log(LogRequest) returns (LogResponse) {} | ||
} | ||
|
||
message NotificationRequest { | ||
string title = 1; | ||
string body = 2; | ||
} | ||
|
||
message NotificationResponse { | ||
bool success = 1; | ||
optional string message = 2; | ||
} | ||
|
||
message LogRequest { | ||
string level = 1; | ||
string target = 2; | ||
string message = 3; | ||
} | ||
|
||
message LogResponse { | ||
bool success = 1; | ||
optional string message = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use hyper::{Body, Request, Response}; | ||
use serde_derive::Serialize; | ||
use std::{collections::HashMap, convert::Infallible}; | ||
|
||
use crate::{ | ||
api::{authenticate, ResponseBody}, | ||
logs::{self, models::get_app_ids::GetAppIdsRequest}, | ||
}; | ||
|
||
#[derive(Serialize)] | ||
struct GepAppIdsResponse { | ||
ids: Vec<String>, | ||
} | ||
|
||
pub async fn get_app_ids(req: Request<Body>) -> Result<Response<Body>, Infallible> { | ||
match authenticate(&req) { | ||
Ok(val) => val, | ||
Err(err) => { | ||
return Ok(err); | ||
} | ||
}; | ||
|
||
let req = match req.uri().query() { | ||
None => GetAppIdsRequest { | ||
start_time: None, | ||
end_time: None, | ||
}, | ||
Some(query_str) => { | ||
let query_params: Vec<&str> = query_str.split("&").collect(); | ||
|
||
// convert query params to GetAppIdsRequest | ||
// first, split '=' from query params | ||
// and get them as key-value pair (HashMap) | ||
let spl: HashMap<String, String> = query_params | ||
.iter() | ||
.map(|x| x.split("=").collect::<Vec<&str>>()) | ||
.map(|x| (x[0].to_string(), x[1].to_string())) | ||
.collect(); | ||
|
||
// then, convert HashMap to GetAppIdsRequest | ||
let req = GetAppIdsRequest { | ||
start_time: match spl.get("start_time") { | ||
Some(val) => { | ||
let par = val.parse::<i64>(); | ||
|
||
match par { | ||
Ok(val) => Some(val), | ||
Err(_) => None, | ||
} | ||
} | ||
None => None, | ||
}, | ||
end_time: match spl.get("end_time") { | ||
Some(val) => { | ||
let par = val.parse::<i64>(); | ||
|
||
match par { | ||
Ok(val) => Some(val), | ||
Err(_) => None, | ||
} | ||
} | ||
None => None, | ||
}, | ||
}; | ||
|
||
req | ||
} | ||
}; | ||
|
||
let start_time = req.start_time; | ||
let end_time = req.end_time; | ||
|
||
let err_res_builder = |err: String| { | ||
Response::builder() | ||
.status(hyper::StatusCode::BAD_REQUEST) | ||
.header("Content-Type", "application/json") | ||
.body(Body::from( | ||
serde_json::to_string(&ResponseBody::Error(err)).unwrap(), | ||
)) | ||
.unwrap() | ||
}; | ||
|
||
let ids = match logs::persistence::get_app_ids(start_time, end_time).await { | ||
Ok(val) => val, | ||
Err(err) => { | ||
let bod = serde_json::to_string(&ResponseBody::Error(err.to_string())).unwrap(); | ||
|
||
let response = err_res_builder(bod); | ||
|
||
return Ok(response); | ||
} | ||
}; | ||
|
||
let res_model = GepAppIdsResponse { ids }; | ||
|
||
let res_json = serde_json::to_string(&res_model); | ||
|
||
let response = match res_json { | ||
Ok(res_json) => Response::builder() | ||
.status(hyper::StatusCode::OK) | ||
.header("Content-Type", "application/json") | ||
.body(Body::from(res_json)) | ||
.unwrap(), | ||
Err(err) => err_res_builder(err.to_string()), | ||
}; | ||
|
||
Ok(response) | ||
} |
Oops, something went wrong.