commit
a182deffe2
36 changed files with 344 additions and 229 deletions
@ -1,3 +1,4 @@ |
|||||||
ADMIN_AUTH_TOKEN=464af63dbd241969baa1e94b2461d94d |
DB_HOST=u_db |
||||||
POSTGRES_PASSWORD=12348756 |
DB_NAME=u_db |
||||||
DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@u_db/u_db |
DB_USER=postgres |
||||||
|
RUST_BACKTRACE=1 |
@ -0,0 +1,4 @@ |
|||||||
|
# remove '.sample' to activate |
||||||
|
ADMIN_AUTH_TOKEN= |
||||||
|
DB_PASSWORD= |
||||||
|
POSTGRES_PASSWORD=${DB_PASSWORD} |
@ -0,0 +1,8 @@ |
|||||||
|
use std::path::PathBuf; |
||||||
|
|
||||||
|
fn main() { |
||||||
|
let server_cert = PathBuf::from("../../certs/ca.crt"); |
||||||
|
if !server_cert.exists() { |
||||||
|
panic!("CA certificate doesn't exist. Create it first with certs/gen_certs.sh"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
set -ex |
||||||
|
DIR=. |
||||||
|
V3_CFG=v3.ext |
||||||
|
|
||||||
|
cat > $DIR/$V3_CFG << EOF |
||||||
|
authorityKeyIdentifier=keyid,issuer |
||||||
|
basicConstraints=CA:FALSE |
||||||
|
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign |
||||||
|
EOF |
||||||
|
|
||||||
|
|
||||||
|
openssl req -x509 -newkey rsa:4096 -keyout $DIR/ca.key -out $DIR/ca.crt -nodes -days 365 -subj "/CN=root" |
||||||
|
openssl req -newkey rsa:4096 -keyout $DIR/alice.key -out $DIR/alice.csr -nodes -days 365 -subj "/CN=alice" |
||||||
|
openssl req -newkey rsa:4096 -keyout $DIR/server.key -out $DIR/server.csr -nodes -days 365 -subj "/CN=u_server" |
||||||
|
openssl x509 -req -in $DIR/alice.csr -CA $DIR/ca.crt -CAkey $DIR/ca.key -out $DIR/alice.crt -set_serial 01 -days 365 -extfile $DIR/$V3_CFG |
||||||
|
openssl x509 -req -in $DIR/server.csr -CA $DIR/ca.crt -CAkey $DIR/ca.key -out $DIR/server.crt -set_serial 01 -days 365 -extfile $DIR/$V3_CFG |
||||||
|
openssl pkcs12 -export -out $DIR/alice.p12 -inkey $DIR/alice.key -in $DIR/alice.crt -passin pass: -passout pass: |
@ -1,5 +1,3 @@ |
|||||||
pub mod client; |
|
||||||
pub mod panel; |
pub mod panel; |
||||||
|
|
||||||
pub use client::AgentClient; |
|
||||||
pub use panel::Panel; |
pub use panel::Panel; |
||||||
|
@ -1,80 +1,67 @@ |
|||||||
mod helpers; |
mod helpers; |
||||||
|
|
||||||
use helpers::{AgentClient, Panel}; |
use helpers::Panel; |
||||||
|
|
||||||
use serde_json::json; |
use std::error::Error; |
||||||
use std::thread::sleep; |
use std::thread::sleep; |
||||||
use std::time::Duration; |
use std::time::Duration; |
||||||
|
use u_lib::{api::ClientHandler, models::*}; |
||||||
use uuid::Uuid; |
use uuid::Uuid; |
||||||
|
|
||||||
type TestResult<R = ()> = Result<R, Box<dyn std::error::Error>>; |
type TestResult<R = ()> = Result<R, Box<dyn Error>>; |
||||||
|
|
||||||
async fn register_agent() -> Uuid { |
async fn register_agent() -> Uuid { |
||||||
let cli = AgentClient::new(); |
let cli = ClientHandler::new(None); |
||||||
let agent_uid = Uuid::new_v4(); |
let agent_uid = Uuid::new_v4(); |
||||||
let resp = cli.get(format!("get_agent_jobs/{}", agent_uid)).await; |
let resp = cli |
||||||
let job_id = &resp["job_id"]; |
.get_personal_jobs(Some(agent_uid)) |
||||||
let resp = cli.get(format!("get_jobs/{}", job_id)).await; |
.await |
||||||
assert_eq!(&resp["alias"], "agent_hello"); |
.unwrap() |
||||||
let agent_data = json! { |
.pop() |
||||||
{"id": &agent_uid,"inner":[ |
.unwrap(); |
||||||
{"Agent": |
let job_id = resp.job_id; |
||||||
{"alias":null, |
let resp = cli.get_jobs(Some(job_id)).await.unwrap().pop().unwrap(); |
||||||
"hostname":"3b1030fa6324", |
assert_eq!(resp.alias, Some("agent_hello".to_string())); |
||||||
"id":&agent_uid, |
let agent_data = Agent { |
||||||
"is_root":false, |
id: agent_uid, |
||||||
"is_root_allowed":false, |
..Default::default() |
||||||
"last_active":{"secs_since_epoch":1625271265,"nanos_since_epoch":92814921}, |
|
||||||
"platform":"x86_64-unknown-linux-gnu", |
|
||||||
"regtime":{"secs_since_epoch":1625271265,"nanos_since_epoch":92814945}, |
|
||||||
"state":"New", |
|
||||||
"token":null, |
|
||||||
"username":"root"} |
|
||||||
} |
|
||||||
]} |
|
||||||
}; |
}; |
||||||
cli.post("report", &agent_data).await; |
cli.report(&vec![ExecResult::Agent(agent_data)]) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
agent_uid |
agent_uid |
||||||
} |
} |
||||||
|
|
||||||
#[tokio::test] |
#[tokio::test] |
||||||
async fn test_registration() -> TestResult { |
async fn test_registration() -> TestResult { |
||||||
let agent_uid = register_agent().await; |
let agent_uid = register_agent().await; |
||||||
let agents = Panel::check_output("agents list"); |
let agents: Vec<Agent> = Panel::check_output("agents list"); |
||||||
let found = agents |
let found = agents.iter().find(|v| v.id == agent_uid); |
||||||
.iter() |
|
||||||
.find(|v| v["id"].as_str().unwrap() == agent_uid.to_string()); |
|
||||||
assert!(found.is_some()); |
assert!(found.is_some()); |
||||||
|
//teardown
|
||||||
|
Panel::check_status::<i32>(&format!("agents delete {}", agent_uid)); |
||||||
Ok(()) |
Ok(()) |
||||||
} |
} |
||||||
|
|
||||||
#[tokio::test] |
#[tokio::test] |
||||||
async fn test_setup_tasks() -> TestResult { |
async fn test_setup_tasks() -> TestResult { |
||||||
let agent_uid = Panel::check_output("agents list")[0]["id"].clone(); |
//some independent agents should present
|
||||||
dbg!(&agent_uid); |
let agents: Vec<Agent> = Panel::check_output("agents list"); |
||||||
|
let agent_uid = agents[0].id; |
||||||
let job_alias = "passwd_contents"; |
let job_alias = "passwd_contents"; |
||||||
let cmd = format!("jobs add --alias {} 'cat /etc/passwd'", job_alias); |
let cmd = format!("jobs add --alias {} 'cat /etc/passwd'", job_alias); |
||||||
Panel::check_status(cmd); |
Panel::check_status::<Empty>(&cmd); |
||||||
let cmd = format!("jobmap add {} {}", agent_uid, job_alias); |
let cmd = format!("jobmap add {} {}", agent_uid, job_alias); |
||||||
let assigned_uids = Panel::check_output(cmd); |
let assigned_uids: Vec<Uuid> = Panel::check_output(cmd); |
||||||
dbg!(&assigned_uids); |
for _ in 0..3 { |
||||||
loop { |
let result: Vec<AssignedJob> = |
||||||
let result = Panel::check_output(format!("jobmap list {}", assigned_uids[0])); |
Panel::check_output(format!("jobmap list {}", assigned_uids[0])); |
||||||
dbg!(&result); |
if result[0].state == JobState::Finished { |
||||||
match result.get(0) { |
return Ok(()); |
||||||
Some(entry) if entry["state"] == "Finished" => { |
} else { |
||||||
println!("{}", result[0]); |
sleep(Duration::from_secs(5)); |
||||||
break; |
eprintln!("waiting for task"); |
||||||
} |
|
||||||
None => { |
|
||||||
eprintln!("jobmap list is empty (bad bad bad)"); |
|
||||||
continue; |
|
||||||
} |
|
||||||
_ => { |
|
||||||
sleep(Duration::from_secs(1)); |
|
||||||
eprintln!("waiting for task"); |
|
||||||
} |
|
||||||
} |
} |
||||||
} |
} |
||||||
Ok(()) |
panic!() |
||||||
} |
} |
||||||
|
@ -0,0 +1,10 @@ |
|||||||
|
use crate::UError; |
||||||
|
use serde::{Deserialize, Serialize}; |
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)] |
||||||
|
#[serde(rename_all = "lowercase")] |
||||||
|
#[serde(tag = "status", content = "data")] |
||||||
|
pub enum DataResult<M> { |
||||||
|
Ok(M), |
||||||
|
Err(UError), |
||||||
|
} |
@ -1,8 +1,9 @@ |
|||||||
use crate::models::{Agent, AssignedJob}; |
use crate::models::{Agent, AssignedJob}; |
||||||
use serde::{Deserialize, Serialize}; |
use serde::{Deserialize, Serialize}; |
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)] |
#[derive(Serialize, Deserialize, Clone, PartialEq)] |
||||||
pub enum ExecResult { |
pub enum ExecResult { |
||||||
Assigned(AssignedJob), |
Assigned(AssignedJob), |
||||||
Agent(Agent), |
Agent(Agent), |
||||||
|
Dummy, |
||||||
} |
} |
||||||
|
@ -1,12 +1,12 @@ |
|||||||
#!/bin/bash |
#!/bin/bash |
||||||
set -e |
set -ex |
||||||
source $(dirname $0)/rootdir.sh #set ROOTDIR |
source $(dirname $0)/rootdir.sh #set ROOTDIR |
||||||
umask 002 |
ARGS=$@ |
||||||
docker run \ |
docker run \ |
||||||
|
--env-file $ROOTDIR/.env \ |
||||||
-v $ROOTDIR:/volume \ |
-v $ROOTDIR:/volume \ |
||||||
-v cargo-cache:/root/.cargo/registry \ |
-v cargo-cache:/root/.cargo/registry \ |
||||||
-w /volume \ |
-w /volume \ |
||||||
-it \ |
-it \ |
||||||
unki/musllibs \ |
unki/musllibs \ |
||||||
cargo $@ |
bash -c "umask 0000; cargo $ARGS" |
||||||
|
|
||||||
|
Loading…
Reference in new issue