forked from navos/sheepd
🎉 init
This commit is contained in:
commit
812c4adb15
16 changed files with 4631 additions and 0 deletions
src/sheepd_core
37
src/sheepd_core/cmd.rs
Normal file
37
src/sheepd_core/cmd.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use crate::{api, sheepd_core::config::AgentConfig};
|
||||
|
||||
use super::args::JoinCommand;
|
||||
|
||||
pub fn join(conf: JoinCommand) {
|
||||
// TODO : check for root
|
||||
// TODO : check if joined somewhere already
|
||||
|
||||
log::info!("Joining to {}", conf.home);
|
||||
|
||||
let url = format!("http://{}/join", conf.home);
|
||||
println!("{url}");
|
||||
let mut res = ureq::post(url)
|
||||
.send_json(&api::JoinParams {
|
||||
join_token: None,
|
||||
machine_id: std::fs::read_to_string("/etc/machine-id").unwrap(),
|
||||
hostname: std::fs::read_to_string("/etc/hostname").unwrap(),
|
||||
})
|
||||
.unwrap();
|
||||
let res: serde_json::Value = res.body_mut().read_json().unwrap();
|
||||
|
||||
let token = res
|
||||
.as_object()
|
||||
.unwrap()
|
||||
.get("ok")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.unwrap();
|
||||
|
||||
log::info!("Joined {} successfully", conf.home);
|
||||
|
||||
std::fs::write(
|
||||
"/etc/sheepd.toml",
|
||||
toml::to_string(&AgentConfig::new(&conf.home, token)).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue