Working on peach-config

This commit is contained in:
notplants 2022-07-04 13:23:55 +02:00
parent 6621a09ec9
commit f002f5cf3e
6 changed files with 58 additions and 0 deletions

1
Cargo.lock generated
View File

@ -2204,6 +2204,7 @@ version = "0.1.25"
dependencies = [
"clap",
"env_logger 0.6.2",
"golgi",
"lazy_static",
"log 0.4.17",
"peach-lib",

View File

@ -37,3 +37,4 @@ log = "0.4"
lazy_static = "1.4.0"
peach-lib = { path = "../peach-lib" }
rpassword = "5.0"
golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" }

View File

@ -50,6 +50,10 @@ enum PeachConfig {
/// Updates file permissions on PeachCloud device
#[structopt(name = "permissions")]
SetPermissions,
/// Returns sbot id if sbot is running
#[structopt(name = "whoami")]
WhoAmI,
}
#[derive(StructOpt, Debug)]
@ -155,6 +159,12 @@ fn main() {
)
}
},
PeachConfig::WhoAmI => match status::who_am_i() {
Ok(sbot_id) => {sbot_id}
Err(err) => {
error!("1")
}
},
}
}
}

View File

@ -0,0 +1,12 @@
use crate::error::PeachConfigError;
use crate::ChangePasswordOpts;
use peach_lib::password_utils::set_new_password;
use peach_lib::sbot::init_sbot;
use golgi::Sbot;
/// Utility function to check if sbot is running via the whoami method
pub fn whoami() -> Result<bool, PeachConfigError> {
let sbot = init_sbot()?;
sbot.whoami()
}

View File

@ -256,3 +256,9 @@ impl From<string::FromUtf8Error> for PeachError {
PeachError::Utf8ToString(err)
}
}
impl From<GolgiError> for PeachError {
fn from(err: GolgiError) -> PeachError {
PeachError::Golgi(err)
}
}

View File

@ -2,6 +2,11 @@
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
use golgi::{
api::friends::RelationshipQuery, blobs, messages::SsbMessageValue, sbot::Keystore, Sbot,
};
use log::debug;
use crate::config_manager;
use serde::{Deserialize, Serialize};
@ -240,3 +245,26 @@ impl SbotConfig {
Ok(())
}
}
/// Initialise an sbot client
pub async fn init_sbot() -> Result<Sbot, PeachError> {
// read sbot config from config.toml
let sbot_config = SbotConfig::read().ok();
debug!("Initialising an sbot client with configuration parameters");
// initialise sbot connection with ip:port and shscap from config file
let key_path = format!(
"{}/secret",
config_manager::get_config_value("GO_SBOT_DATADIR")?
);
let sbot_client = match sbot_config {
// TODO: panics if we pass `Some(conf.shscap)` as second arg
Some(conf) => {
let ip_port = conf.lis.clone();
Sbot::init(Keystore::CustomGoSbot(key_path), Some(ip_port), None).await?
}
None => Sbot::init(Keystore::CustomGoSbot(key_path), None, None).await?,
};
Ok(sbot_client)
}