Skip to content

Commit

Permalink
Merge pull request #629 from openSUSE/rust_logging
Browse files Browse the repository at this point in the history
Add initial logging capability to agama-dbus-server
  • Loading branch information
jreidinger authored Jun 16, 2023
2 parents a27ded1 + f2027c7 commit 6461acc
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 88 deletions.
101 changes: 101 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/agama-cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::error::CliError;
use crate::printers::{print, Format};
use clap::Subcommand;
use convert_case::{Case, Casing};
use agama_lib::connection;
use agama_lib::install_settings::{InstallSettings, Scope};
use agama_lib::settings::{SettingObject, SettingValue, Settings};
use agama_lib::Store as SettingsStore;
use clap::Subcommand;
use convert_case::{Case, Casing};
use std::str::FromStr;
use std::{collections::HashMap, error::Error, io};

Expand Down
13 changes: 8 additions & 5 deletions rust/agama-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mod profile;
mod progress;

use crate::error::CliError;
use async_std::task::{self, block_on};
use commands::Commands;
use config::run as run_config_cmd;
use agama_lib::error::ServiceError;
use agama_lib::manager::ManagerClient;
use agama_lib::progress::build_progress_monitor;
use async_std::task::{self, block_on};
use commands::Commands;
use config::run as run_config_cmd;
use printers::Format;
use progress::InstallerProgress;
use profile::run as run_profile_cmd;
use progress::InstallerProgress;
use std::error::Error;
use std::time::Duration;

Expand Down Expand Up @@ -58,7 +58,10 @@ async fn show_progress() -> Result<(), ServiceError> {
let conn = agama_lib::connection().await?;
let mut monitor = build_progress_monitor(conn).await.unwrap();
let presenter = InstallerProgress::new();
monitor.run(presenter).await.expect("failed to monitor the progress");
monitor
.run(presenter)
.await
.expect("failed to monitor the progress");
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions rust/agama-cli/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Subcommand;
use agama_lib::error::ProfileError;
use agama_lib::profile::{download, ProfileEvaluator, ProfileValidator, ValidationResult};
use std::{path::Path};
use clap::Subcommand;
use std::path::Path;

#[derive(Subcommand, Debug)]
pub enum ProfileCommands {
Expand Down
3 changes: 3 additions & 0 deletions rust/agama-dbus-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ anyhow = "1.0"
agama-locale-data = { path="../agama-locale-data" }
agama-network = { path="../agama-network" }
agama-lib = { path="../agama-lib" }
log = "0.4"
simplelog = "0.12.1"
systemd-journal-logger = "1.0"
zbus = "3.7.0"
zbus_macros = "3.7.0"
async-std = { version = "1.12.0", features = ["attributes"]}
20 changes: 20 additions & 0 deletions rust/agama-dbus-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,36 @@ pub mod locale;
pub mod questions;

use agama_network::NetworkService;
use log::LevelFilter;
use std::future::pending;

const ADDRESS: &str = "unix:path=/run/agama/bus";

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// be smart with logging and log directly to journal if connected to it
if systemd_journal_logger::connected_to_journal() {
// unwrap here is intentional as we are sure no other logger is active yet
systemd_journal_logger::JournalLog::default()
.install()
.unwrap();
log::set_max_level(LevelFilter::Info); // log only info for journal logger
} else {
simplelog::TermLogger::init(
LevelFilter::Info, // lets use info, trace provides too much output from libraries
simplelog::Config::default(),
simplelog::TerminalMode::Stderr, // only stderr output for easier filtering
simplelog::ColorChoice::Auto,
)
.unwrap(); // unwrap here as we are sure no other logger active
}
// When adding more services here, the order might be important.
crate::questions::start_service(ADDRESS).await?;
log::info!("Started questions interface");
let _conn = crate::locale::start_service(ADDRESS).await?;
log::info!("Started locale interface");
NetworkService::start(ADDRESS).await?;
log::info!("Started network interface");

// Do other things or go to wait forever
pending::<()>().await;
Expand Down
11 changes: 6 additions & 5 deletions rust/agama-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
zbus = "3.7.0"
serde = { version = "1.0.152", features = ["derive"] }
agama-derive = { path="../agama-derive" }
anyhow = "1.0"
async-std = "1.12.0"
curl = { version = "0.4.44", features = ["protocol-ftp"] }
futures = "0.3.27"
futures-util = "0.3.27"
jsonschema = { version = "0.16.1", default-features = false }
log = "0.4"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.94"
tempfile = "3.4.0"
thiserror = "1.0.39"
anyhow = "1.0"
futures = "0.3.27"
futures-util = "0.3.27"
zbus = "3.7.0"
4 changes: 3 additions & 1 deletion rust/agama-lib/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::ProfileError;
use curl::easy::Easy;
use jsonschema::JSONSchema;
use log::info;
use serde_json;
use std::{
fs, io,
Expand All @@ -10,7 +11,7 @@ use std::{
};
use tempfile::tempdir;

/// Downloads a file a writes it to the stdout()
/// Downloads a file and writes it to the stdout()
///
/// TODO: move this code to a struct
/// TODO: add support for YaST-specific URLs
Expand Down Expand Up @@ -65,6 +66,7 @@ impl ProfileValidator {
} else {
Path::new("/usr/share/agama-cli/profile.schema.json")
};
info!("Validation with path {}", path.to_str().unwrap());
Self::new(path)
}

Expand Down
6 changes: 4 additions & 2 deletions rust/agama-lib/src/store/software.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ impl<'a> SoftwareStore<'a> {
if ids.contains(&product) {
self.software_client.select_product(product).await?;
} else {
return Err(Box::new(WrongParameter::UnknownProduct(product.clone(), ids)));
return Err(Box::new(WrongParameter::UnknownProduct(
product.clone(),
ids,
)));
}

}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/store/users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::WrongParameter;
use crate::install_settings::{FirstUserSettings, RootUserSettings, UserSettings};
use crate::users::{FirstUser, UsersClient};
use crate::error::WrongParameter;
use std::error::Error;
use zbus::Connection;

Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'a> UsersStore<'a> {
};
let (success, issues) = self.users_client.set_first_user(&first_user).await?;
if !success {
return Err(Box::new(WrongParameter::WrongUser(issues)));
return Err(Box::new(WrongParameter::WrongUser(issues)));
}
Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions rust/agama-lib/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ impl<'a> UsersClient<'a> {
value: &str,
encrypted: bool,
) -> Result<u32, ServiceError> {
Ok(self
.users_proxy
.set_root_password(value, encrypted)
.await?)
Ok(self.users_proxy.set_root_password(value, encrypted).await?)
}

/// Whether the root password is set or not
Expand Down
Loading

0 comments on commit 6461acc

Please sign in to comment.