-
Notifications
You must be signed in to change notification settings - Fork 43
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
adapt dbus API to prepare for answers file and change use_defaults to… #669
Changes from all commits
defdcdf
3f8874d
d4cdb6f
a13759c
c58c3e3
771143b
8844c62
151bede
98c4d42
0fb9164
fab42b2
44d2316
be5e583
20a7e0a
b98242a
3827c84
d9e95c6
d3095d2
266f3d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
answers: | ||
- class: storage.luks_activation | ||
answer: "skip" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ use anyhow::Context; | |
use log; | ||
use zbus::{dbus_interface, fdo::ObjectManager, zvariant::ObjectPath, Connection}; | ||
|
||
mod answers; | ||
|
||
#[derive(Clone, Debug)] | ||
struct GenericQuestionObject(questions::GenericQuestion); | ||
|
||
|
@@ -81,7 +83,11 @@ enum QuestionType { | |
} | ||
|
||
/// Trait for objects that can provide answers to all kind of Question. | ||
/// | ||
/// If no strategy is selected or the answer is unknown, then ask to the user. | ||
trait AnswerStrategy { | ||
/// Id for quick runtime inspection of strategy type | ||
fn id(&self) -> u8; | ||
/// Provides answer for generic question | ||
/// | ||
/// I gets as argument the question to answer. Returned value is `answer` | ||
|
@@ -103,7 +109,17 @@ trait AnswerStrategy { | |
/// AnswerStrategy that provides as answer the default option. | ||
struct DefaultAnswers; | ||
|
||
impl DefaultAnswers { | ||
pub fn id() -> u8 { | ||
1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NP: I think this can be a field of the struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reason why it is also class method is to allow detection of strategy like below that instance is DefaultAnswers |
||
} | ||
} | ||
|
||
impl AnswerStrategy for DefaultAnswers { | ||
fn id(&self) -> u8 { | ||
DefaultAnswers::id() | ||
} | ||
|
||
fn answer(&self, question: &GenericQuestion) -> Option<String> { | ||
Some(question.default_option.clone()) | ||
} | ||
|
@@ -227,11 +243,43 @@ impl Questions { | |
Ok(()) | ||
} | ||
|
||
/// sets questions to be answered by default answer instead of asking user | ||
async fn use_default_answer(&mut self) -> Result<(), Error> { | ||
log::info!("Answer questions with default option"); | ||
self.answer_strategies.push(Box::new(DefaultAnswers {})); | ||
Ok(()) | ||
/// property that defines if questions is interactive or automatically answered with | ||
/// default answer | ||
#[dbus_interface(property)] | ||
fn interactive(&self) -> bool { | ||
let last = self.answer_strategies.last(); | ||
if let Some(real_strategy) = last { | ||
real_strategy.id() != DefaultAnswers::id() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if I understood the idea of having more than one strategy. Is it for priorities? First from file, if no found then default, if not found then ask to user? And the mode is only considered interactive if the last assigned strategy is not DefaultAnswers. But what happens if the last strategy is answers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for strategies is extensibility, which allows to add completely different source of answers from strategy like e.g. some remote server answering it. |
||
} else { | ||
true | ||
} | ||
} | ||
|
||
#[dbus_interface(property)] | ||
fn set_interactive(&mut self, value: bool) { | ||
if value != self.interactive() { | ||
log::info!("interactive value unchanged - {}", value); | ||
return; | ||
} | ||
|
||
log::info!("set interactive to {}", value); | ||
if value { | ||
jreidinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.answer_strategies.pop(); | ||
} else { | ||
self.answer_strategies.push(Box::new(DefaultAnswers {})); | ||
} | ||
} | ||
|
||
fn add_answer_file(&mut self, path: String) -> Result<(), Error> { | ||
log::info!("Adding answer file {}", path); | ||
let answers = answers::Answers::new_from_file(path.as_str()); | ||
match answers { | ||
Ok(answers) => { | ||
self.answer_strategies.push(Box::new(answers)); | ||
Ok(()) | ||
} | ||
Err(e) => Err(e.into()), | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: In Agama we are using both YaML and Json (jsonnet). It was already commented in some planning that we should converge to a single format if there is no reason to keep both. I would vote for using json everywhere: config file, autoinstall profile and questions answers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
luckily it is easy with abstraction library provides. It is just about different crate. So when it is unify it is fine for me to convert it.