feat: Add functionality to read path from stdin and rund tasks

This commit is contained in:
0xalivecow 2024-10-20 18:34:52 +02:00
parent 43bea77392
commit 52dca1bcaf
No known key found for this signature in database
5 changed files with 29 additions and 17 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.90"
base64 = "0.22.1" base64 = "0.22.1"
serde = { version = "1.0.210", features = ["derive"] } serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"

View file

@ -1,2 +1,2 @@
mod tasks; pub mod tasks;
mod utils; pub mod utils;

View file

@ -1,3 +1,19 @@
fn main() { use std::{
println!("Hello, world!"); env::{self, args},
fs,
};
use anyhow::Result;
fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
let path_to_workload = &args[1];
let json = fs::read_to_string(path_to_workload).unwrap();
let workload = kauma::utils::parse::parse_json(json)?;
let response = kauma::tasks::task_distrubute(&workload);
println!("{}", serde_json::to_string(&response)?);
Ok(())
} }

View file

@ -23,16 +23,7 @@ pub fn task_deploy(testcase: &Testcase) -> Result<Value, String> {
match testcase.action.as_str() { match testcase.action.as_str() {
"poly2block" => { "poly2block" => {
let coefficients: Vec<u8> = args["coefficients"] let result = poly2block(args);
.as_array()
.unwrap()
.into_iter()
.map(|x| x.as_u64().unwrap() as u8)
.collect();
//eprintln!("{:?}", &args["coefficients"]);
//eprintln!("{:?}", testcase);
//eprintln!("{:?}", coefficients);
let result = poly2block(coefficients);
let json = json!({"block" : result}); let json = json!({"block" : result});
Ok(json) Ok(json)
} }
@ -43,7 +34,6 @@ pub fn task_deploy(testcase: &Testcase) -> Result<Value, String> {
} }
} }
// TODO: Is this obsolete? Might delete later.
pub fn task_distrubute(testcases: &Testcases) -> Responses { pub fn task_distrubute(testcases: &Testcases) -> Responses {
let mut responses: HashMap<String, Value> = HashMap::new(); let mut responses: HashMap<String, Value> = HashMap::new();

View file

@ -2,7 +2,12 @@ use crate::utils::poly::{self, coefficient_to_binary};
use base64::prelude::*; use base64::prelude::*;
use serde_json::Value; use serde_json::Value;
pub fn poly2block(coefficients: Vec<u8>) -> String { pub fn poly2block(args: &Value) -> String {
let coefficients: Vec<u8> = args["coefficients"]
.as_array()
.unwrap()
.into_iter()
.map(|x| x.as_u64().unwrap() as u8)
.collect();
BASE64_STANDARD.encode(poly::coefficient_to_binary(coefficients).to_ne_bytes()) BASE64_STANDARD.encode(poly::coefficient_to_binary(coefficients).to_ne_bytes())
} }