Whoami
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
notplants 2022-07-04 14:35:17 +02:00
parent f002f5cf3e
commit 7e94135839
7 changed files with 46 additions and 12 deletions

1
Cargo.lock generated
View File

@ -2202,6 +2202,7 @@ dependencies = [
name = "peach-config"
version = "0.1.25"
dependencies = [
"async-std",
"clap",
"env_logger 0.6.2",
"golgi",

View File

@ -38,3 +38,4 @@ lazy_static = "1.4.0"
peach-lib = { path = "../peach-lib" }
rpassword = "5.0"
golgi = { git = "https://git.coopcloud.tech/golgi-ssb/golgi.git" }
async-std = "1.10.0"

View File

@ -1,4 +1,5 @@
#![allow(clippy::nonstandard_macro_braces)]
use golgi::error::GolgiError;
use peach_lib::error::PeachError;
pub use snafu::ResultExt;
use snafu::Snafu;
@ -35,6 +36,10 @@ pub enum PeachConfigError {
ChangePasswordError { source: PeachError },
#[snafu(display("Entered passwords did not match. Please try again."))]
InvalidPassword,
#[snafu(display("Error in peach lib: {}", source))]
PeachLibError { source: PeachError },
#[snafu(display("Error in golgi: {}", source))]
Golgi { source: GolgiError },
}
impl From<std::io::Error> for PeachConfigError {
@ -51,3 +56,15 @@ impl From<serde_json::Error> for PeachConfigError {
PeachConfigError::SerdeError { source: err }
}
}
impl From<PeachError> for PeachConfigError {
fn from(err: PeachError) -> PeachConfigError {
PeachConfigError::PeachLibError { source: err }
}
}
impl From<GolgiError> for PeachConfigError {
fn from(err: GolgiError) -> PeachConfigError {
PeachConfigError::Golgi { source: err }
}
}

View File

@ -6,6 +6,7 @@ mod set_permissions;
mod setup_networking;
mod setup_peach;
mod setup_peach_deb;
mod status;
mod update;
mod utils;
@ -106,7 +107,7 @@ arg_enum! {
}
}
fn main() {
async fn run() {
// initialize the logger
env_logger::init();
@ -159,12 +160,23 @@ fn main() {
)
}
},
PeachConfig::WhoAmI => match status::who_am_i() {
Ok(sbot_id) => {sbot_id}
PeachConfig::WhoAmI => match status::whoami().await {
Ok(sbot_id) => {
println!("{:?}", sbot_id);
{}
}
Err(err) => {
error!("1")
error!("sbot whoami encountered an error: {}", err)
}
},
}
}
}
// Enable an async main function and execute the `run()` function,
// catching any errors and printing them to `stderr` before exiting the
// process.
#[async_std::main]
async fn main() {
run().await;
}

View File

@ -1,12 +1,9 @@
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()
pub async fn whoami() -> Result<String, PeachConfigError> {
let mut sbot = init_sbot().await?;
let sbot_id = sbot.whoami().await?;
Ok(sbot_id)
}

View File

@ -3,6 +3,7 @@
//! Error handling for various aspects of the PeachCloud system, including the network, OLED, stats and dyndns JSON-RPC clients, as well as the configuration manager, sbot client and password utilities.
use std::{io, str, string};
use golgi::GolgiError;
/// This type represents all possible errors that can occur when interacting with the PeachCloud library.
#[derive(Debug)]
@ -102,6 +103,9 @@ pub enum PeachError {
/// The file path for the write attempt.
path: String,
},
/// Represents a Golgi error
Golgi(GolgiError),
}
impl std::error::Error for PeachError {
@ -130,6 +134,7 @@ impl std::error::Error for PeachError {
PeachError::Utf8ToStr(_) => None,
PeachError::Utf8ToString(_) => None,
PeachError::Write { ref source, .. } => Some(source),
PeachError::Golgi(_) => None,
}
}
}
@ -187,6 +192,7 @@ impl std::fmt::Display for PeachError {
PeachError::Write { ref path, .. } => {
write!(f, "Write error: {}", path)
}
PeachError::Golgi(ref err) => err.fmt(f),
}
}
}

View File

@ -3,7 +3,7 @@
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
use golgi::{
api::friends::RelationshipQuery, blobs, messages::SsbMessageValue, sbot::Keystore, Sbot,
sbot::Keystore, Sbot,
};
use log::debug;