Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first draft of questions API in http #1091

Merged
merged 13 commits into from
Mar 22, 2024
8 changes: 4 additions & 4 deletions rust/agama-cli/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{arg, Args, Subcommand};
use home;

use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE};
use std::fs;
use std::fs::File;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub async fn run(subcommand: AuthCommands) -> anyhow::Result<()> {
/// Reads stored token and returns it
fn jwt() -> anyhow::Result<String> {
if let Some(file) = jwt_file() {
if let Ok(token) = read_line_from_file(&file.as_path()) {
if let Ok(token) = read_line_from_file(file.as_path()) {
return Ok(token);
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Credentials for KnownCredentials {

impl Credentials for FileCredentials {
fn password(&self) -> io::Result<String> {
read_line_from_file(&self.path.as_path())
read_line_from_file(self.path.as_path())
}
}

Expand All @@ -119,7 +119,7 @@ fn read_line_from_file(path: &Path) -> io::Result<String> {
));
}

if let Ok(file) = File::open(&path) {
if let Ok(file) = File::open(path) {
// cares only of first line, take everything. No comments
// or something like that supported
let raw = BufReader::new(file).lines().next();
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> ManagerClient<'a> {
/// Returns the current installation phase.
pub async fn current_installation_phase(&self) -> Result<InstallationPhase, ServiceError> {
let phase = self.manager_proxy.current_installation_phase().await?;
Ok(phase.try_into()?)
phase.try_into()
}

/// Starts the probing process.
Expand Down
52 changes: 51 additions & 1 deletion rust/agama-lib/src/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ trait Questions1 {

/// New method
#[dbus_proxy(name = "New")]
fn new_quetion(
fn new_question(
&self,
class: &str,
text: &str,
Expand All @@ -122,6 +122,56 @@ trait Questions1 {
fn set_interactive(&self, value: bool) -> zbus::Result<()>;
}

#[dbus_proxy(
interface = "org.opensuse.Agama1.Questions.Generic",
default_service = "org.opensuse.Agama1",
default_path = "/org/opensuse/Agama1/Questions"
)]
trait GenericQuestion {
/// Answer property
#[dbus_proxy(property)]
fn answer(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn set_answer(&self, value: &str) -> zbus::Result<()>;

/// Class property
#[dbus_proxy(property)]
fn class(&self) -> zbus::Result<String>;

/// Data property
#[dbus_proxy(property)]
fn data(&self) -> zbus::Result<std::collections::HashMap<String, String>>;

/// DefaultOption property
#[dbus_proxy(property)]
fn default_option(&self) -> zbus::Result<String>;

/// Id property
#[dbus_proxy(property)]
fn id(&self) -> zbus::Result<u32>;

/// Options property
#[dbus_proxy(property)]
fn options(&self) -> zbus::Result<Vec<String>>;

/// Text property
#[dbus_proxy(property)]
fn text(&self) -> zbus::Result<String>;
}

#[dbus_proxy(
interface = "org.opensuse.Agama1.Questions.WithPassword",
default_service = "org.opensuse.Agama1",
default_path = "/org/opensuse/Agama1/Questions"
)]
trait QuestionWithPassword {
/// Password property
#[dbus_proxy(property)]
fn password(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn set_password(&self, value: &str) -> zbus::Result<()>;
}

#[dbus_proxy(interface = "org.opensuse.Agama1.Issues", assume_defaults = true)]
trait Issues {
/// All property
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-server/src/agama-web-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::sync::broadcast::channel;
use tracing_subscriber::prelude::*;
use utoipa::OpenApi;

const DEFAULT_WEB_UI_DIR: &'static str = "/usr/share/agama/web_ui";
const DEFAULT_WEB_UI_DIR: &str = "/usr/share/agama/web_ui";

#[derive(Subcommand, Debug)]
enum Commands {
Expand Down
6 changes: 3 additions & 3 deletions rust/agama-server/src/l10n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl Locale {
#[dbus_interface(property)]
fn set_locales(&mut self, locales: Vec<String>) -> zbus::fdo::Result<()> {
if locales.is_empty() {
return Err(zbus::fdo::Error::Failed(format!(
"The locales list cannot be empty"
)));
return Err(zbus::fdo::Error::Failed(
"The locales list cannot be empty".to_string(),
));
}
for loc in &locales {
if !self.locales_db.exists(loc.as_str()) {
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-server/src/l10n/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async fn set_config(
.output()
.map_err(LocaleError::Commit)?;
Command::new("/usr/bin/setxkbmap")
.arg(&ui_keymap)
.arg(ui_keymap)
.env("DISPLAY", ":0")
.output()
.map_err(LocaleError::Commit)?;
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-server/src/manager/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub async fn manager_stream(

/// Sets up and returns the axum service for the manager module
pub async fn manager_service(dbus: zbus::Connection) -> Result<Router, ServiceError> {
const DBUS_SERVICE: &'static str = "org.opensuse.Agama.Manager1";
const DBUS_PATH: &'static str = "/org/opensuse/Agama/Manager1";
const DBUS_SERVICE: &str = "org.opensuse.Agama.Manager1";
const DBUS_PATH: &str = "/org/opensuse/Agama/Manager1";

let status_router = service_status_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;
let progress_router = progress_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?;
Expand Down
1 change: 1 addition & 0 deletions rust/agama-server/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use log;
use zbus::{dbus_interface, fdo::ObjectManager, zvariant::ObjectPath, Connection};

mod answers;
pub mod web;

#[derive(thiserror::Error, Debug)]
pub enum QuestionsError {
Expand Down
Loading
Loading