Skip to content

Commit

Permalink
feat: implement protocol
Browse files Browse the repository at this point in the history
* chore: begin of the new paylaod (need rework)
* feat(agent): request and response payload added
* test(agent): update request json conversion

Signed-off-by: GridexX <[email protected]>
  • Loading branch information
GridexX authored and WoodenMaiden committed Apr 17, 2023
1 parent f296001 commit eee63df
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 218 deletions.
1 change: 1 addition & 0 deletions agent/lib/src/external_api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod model;
pub mod comms;
pub mod service;
128 changes: 127 additions & 1 deletion agent/lib/src/external_api/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug)]
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
pub struct FileModel {
pub filename: String,
pub content: String,
Expand All @@ -11,3 +11,129 @@ pub struct CodeEntry {
pub files: Vec<FileModel>,
pub script: Vec<String>, // All commands to execute at startup
}

#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
pub enum Type {
Status,
Request,
Response,
}

#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
pub enum Code {
Run,
Ok,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct StatusMessage {
pub r#type: Type,
pub code: Code,
}

impl StatusMessage {
pub fn new() -> StatusMessage {
StatusMessage {
r#type: Type::Status,
code: Code::Ok,
}
}
}

impl Default for StatusMessage {
fn default() -> Self {
Self::new()
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct ResponseStep {
pub command: String,
pub result: i32,
pub stdout: String,
pub stderr: String,
pub enable_output: bool,
}

impl ResponseStep {
pub fn new(
command: String,
result: i32,
stdout: String,
stderr: String,
enable_output: bool,
) -> ResponseStep {
ResponseStep {
command,
result,
stdout,
stderr,
enable_output,
}
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct ResponseData {
pub id: String,
pub steps: Vec<ResponseStep>,
}

impl ResponseData {
pub fn new(id: String, steps: Vec<ResponseStep>) -> ResponseData {
ResponseData { id, steps }
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct ResponseMessage {
pub r#type: Type,
pub code: Code,
pub data: ResponseData,
}

impl ResponseMessage {
pub fn new(data: ResponseData) -> ResponseMessage {
ResponseMessage {
r#type: Type::Response,
code: Code::Run,
data,
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct RequestStep {
pub command: String,
pub enable_output: bool,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct RequestData {
pub id: String,
pub files: Vec<FileModel>,
pub steps: Vec<RequestStep>,
}

impl RequestData {
pub fn new(id: String, files: Vec<FileModel>, steps: Vec<RequestStep>) -> RequestData {
RequestData { id, files, steps }
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct RequestMessage {
pub r#type: Type,
pub code: Code,
pub data: RequestData,
}

impl RequestMessage {
pub fn new(data: RequestData) -> RequestMessage {
RequestMessage {
r#type: Type::Request,
code: Code::Run,
data,
}
}
}
Loading

0 comments on commit eee63df

Please sign in to comment.