From 6c570f7a258a8c4d21f1f0888f3b588d5ad1c818 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Oct 2024 10:44:53 +0200 Subject: [PATCH 1/3] switch answers file from yaml to json --- rust/Cargo.lock | 20 -------------- rust/agama-cli/src/questions.rs | 2 +- rust/agama-server/Cargo.toml | 1 - rust/agama-server/src/questions.rs | 2 +- rust/agama-server/src/questions/answers.rs | 31 +++++++++++++--------- 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index b61892af8a..66549e648d 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -112,7 +112,6 @@ dependencies = [ "serde", "serde_json", "serde_with", - "serde_yaml", "subprocess", "thiserror", "tokio", @@ -3629,19 +3628,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.6.0", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha1" version = "0.10.6" @@ -4408,12 +4394,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.9.0" diff --git a/rust/agama-cli/src/questions.rs b/rust/agama-cli/src/questions.rs index 6a0a156306..a763f19999 100644 --- a/rust/agama-cli/src/questions.rs +++ b/rust/agama-cli/src/questions.rs @@ -37,7 +37,7 @@ pub enum QuestionsCommands { /// Please check Agama documentation for more details and examples: /// https://github.com/openSUSE/agama/blob/master/doc/questions.md Answers { - /// Path to a file containing the answers in YAML format. + /// Path to a file containing the answers in JSON format. path: String, }, /// Prints the list of questions that are waiting for an answer in JSON format diff --git a/rust/agama-server/Cargo.toml b/rust/agama-server/Cargo.toml index c5952683eb..07202aa937 100644 --- a/rust/agama-server/Cargo.toml +++ b/rust/agama-server/Cargo.toml @@ -15,7 +15,6 @@ zbus = { version = "3", default-features = false, features = ["tokio"] } uuid = { version = "1.10.0", features = ["v4"] } thiserror = "1.0.64" serde = { version = "1.0.210", features = ["derive"] } -serde_yaml = "0.9.34" cidr = { version = "0.2.3", features = ["serde"] } tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread"] } tokio-stream = "0.1.16" diff --git a/rust/agama-server/src/questions.rs b/rust/agama-server/src/questions.rs index 19b15f5b70..edfb8030c5 100644 --- a/rust/agama-server/src/questions.rs +++ b/rust/agama-server/src/questions.rs @@ -32,7 +32,7 @@ pub enum QuestionsError { #[error("Could not read the answers file: {0}")] IO(std::io::Error), #[error("Could not deserialize the answers file: {0}")] - Deserialize(serde_yaml::Error), + Deserialize(serde_json::Error), } #[derive(Clone, Debug)] diff --git a/rust/agama-server/src/questions/answers.rs b/rust/agama-server/src/questions/answers.rs index 1dbc4928c5..dd738a76bd 100644 --- a/rust/agama-server/src/questions/answers.rs +++ b/rust/agama-server/src/questions/answers.rs @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize}; use super::QuestionsError; -/// Data structure for single yaml answer. For variables specification see +/// Data structure for single JSON answer. For variables specification see /// corresponding [agama_lib::questions::GenericQuestion] fields. /// The *matcher* part is: `class`, `text`, `data`. /// The *answer* part is: `answer`, `password`. @@ -83,7 +83,7 @@ pub struct Answers { impl Answers { pub fn new_from_file(path: &str) -> Result { let f = std::fs::File::open(path).map_err(QuestionsError::IO)?; - let result: Self = serde_yaml::from_reader(f).map_err(QuestionsError::Deserialize)?; + let result: Self = serde_json::from_reader(f).map_err(QuestionsError::Deserialize)?; Ok(result) } @@ -298,18 +298,25 @@ mod tests { } #[test] - fn test_loading_yaml() { + fn test_loading_json() { let file = r#" - answers: - - class: "without_data" - answer: "OK" - - class: "with_data" - data: - testk: testv - testk2: testv2 - answer: "Cancel" + { + "answers": [ + { + "class": "without_data", + "answer": "OK" + }, + { + "class": "with_data", + "data": { + "testk": "testv", + "testk2": "testv2" + }, + "answer": "Cancel" + }] + } "#; - let result: Answers = serde_yaml::from_str(file).expect("failed to load yaml string"); + let result: Answers = serde_json::from_str(file).expect("failed to load JSON string"); assert_eq!(result.answers.len(), 2); } } From 0c9f6adca6165441c5763cefd70fc37302b974b2 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Mon, 14 Oct 2024 13:48:18 +0200 Subject: [PATCH 2/3] convert answers file to json to use consistent formats --- doc/dbus/org.opensuse.Agama1.Questions.doc.xml | 2 +- doc/questions.md | 2 +- service/lib/agama/autoyast/report_patching.rb | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/dbus/org.opensuse.Agama1.Questions.doc.xml b/doc/dbus/org.opensuse.Agama1.Questions.doc.xml index 576b6b2713..9e47507d8a 100644 --- a/doc/dbus/org.opensuse.Agama1.Questions.doc.xml +++ b/doc/dbus/org.opensuse.Agama1.Questions.doc.xml @@ -88,7 +88,7 @@ when the question is answered and the answer is successfully read.