Skip to content

Commit

Permalink
Fixes #23781: Use quick_xml for xml edition (#5193)
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset authored Nov 23, 2023
1 parent 02565fe commit 520accb
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 218 deletions.
26 changes: 10 additions & 16 deletions relay/sources/rudder-package/Cargo.lock

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

2 changes: 1 addition & 1 deletion relay/sources/rudder-package/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env_logger = "0.10.0"
log = "0.4.20"
lzma-rs = "0.3.0"
pretty_assertions = "1.4.0"
quick-xml = "0.31.0"
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "native-tls"] }
regex = "1.10.2"
rstest = "0.18.2"
Expand All @@ -30,7 +31,6 @@ serde_toml = "0.0.1"
sha2 = "0.10.8"
tar = "0.4.40"
tempfile = "3.8.0"
xmltree = "0.10.3"
which = "5.0.0"

[profile.dev]
Expand Down
11 changes: 4 additions & 7 deletions relay/sources/rudder-package/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
database::{Database, InstalledPlugin},
plugin::Metadata,
versions::RudderVersion,
webapp_xml::WebappXml,
PACKAGES_DATABASE_PATH, PACKAGES_FOLDER, RUDDER_VERSION_PATH, WEBAPP_XML_PATH,
webapp::Webapp,
PACKAGES_DATABASE_PATH, PACKAGES_FOLDER, RUDDER_VERSION_PATH,
};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy)]
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Rpkg {
Ok(current_database.is_installed(self.to_owned()))
}

pub fn install(&self, force: bool) -> Result<()> {
pub fn install(&self, force: bool, webapp: &mut Webapp) -> Result<()> {
debug!("Installing rpkg '{}'...", self.path);
// Verify webapp compatibility
let webapp_version = RudderVersion::from_path(RUDDER_VERSION_PATH)?;
Expand Down Expand Up @@ -238,10 +238,7 @@ impl Rpkg {
match self.metadata.jar_files.clone() {
None => (),
Some(jars) => {
let w = WebappXml::new(String::from(WEBAPP_XML_PATH));
for jar_path in jars.into_iter() {
w.enable_jar(jar_path)?;
}
webapp.enable_jars(&jars)?;
}
}
// Restarting webapp
Expand Down
16 changes: 7 additions & 9 deletions relay/sources/rudder-package/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::archive::Rpkg;
use crate::{
archive::{PackageScript, PackageScriptArg},
plugin,
webapp_xml::WebappXml,
webapp::Webapp,
PACKAGES_DATABASE_PATH, PACKAGES_FOLDER,
};
use log::debug;
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Database {
}
}

pub fn uninstall(&mut self, plugin_name: &str) -> Result<()> {
pub fn uninstall(&mut self, plugin_name: &str, webapp: &mut Webapp) -> Result<()> {
// Force to use plugin long qualified name
if !plugin_name.starts_with("rudder-plugin-") {
plugin_name.to_owned().insert_str(0, "rudder-plugin-{}")
Expand All @@ -65,7 +65,7 @@ impl Database {
"Could not extract data for plugin {} in the database",
plugin_name
))?;
installed_plugin.disable()?;
installed_plugin.disable(webapp)?;
installed_plugin
.metadata
.run_package_script(PackageScript::Prerm, PackageScriptArg::None)?;
Expand Down Expand Up @@ -96,26 +96,24 @@ pub struct InstalledPlugin {
}

impl InstalledPlugin {
pub fn disable(&self) -> Result<()> {
pub fn disable(&self, webapp: &mut Webapp) -> Result<()> {
debug!("Disabling plugin {}", self.metadata.name);
let x = WebappXml::new(PACKAGES_DATABASE_PATH.to_owned());
match &self.metadata.jar_files {
None => {
println!("Plugin {} does not support the enable/disable feature, it will always be enabled if installed.", self.metadata.name);
Ok(())
}
Some(jars) => jars.iter().try_for_each(|j| x.disable_jar(j.to_string())),
Some(jars) => webapp.disable_jars(jars),
}
}
pub fn enable(&self) -> Result<()> {
pub fn enable(&self, webapp: &mut Webapp) -> Result<()> {
debug!("Enabling plugin {}", self.metadata.name);
let x = WebappXml::new(PACKAGES_DATABASE_PATH.to_owned());
match &self.metadata.jar_files {
None => {
println!("Plugin {} does not support the enable/disable feature, it will always be enabled if installed.", self.metadata.name);
Ok(())
}
Some(jars) => jars.iter().try_for_each(|j| x.enable_jar(j.to_string())),
Some(jars) => webapp.enable_jars(jars),
}
}

Expand Down
26 changes: 16 additions & 10 deletions relay/sources/rudder-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ mod repo_index;
mod repository;
mod signature;
mod versions;
mod webapp_xml;
mod webapp;

use std::{
path::{Path, PathBuf},
process,
};

use crate::{cli::Command, signature::SignatureVerifier};
use crate::{cli::Command, signature::SignatureVerifier, webapp::Webapp};
use anyhow::{Context, Result};
use clap::Parser;
use log::{debug, error, LevelFilter};
Expand Down Expand Up @@ -73,14 +73,15 @@ pub fn run() -> Result<()> {
.with_context(|| format!("Reading configuration from '{}'", &args.config))?;
let verifier = SignatureVerifier::new(PathBuf::from(SIGNATURE_KEYRING_PATH));
let repo = Repository::new(&cfg, verifier)?;
let mut webapp = Webapp::new(PathBuf::from(WEBAPP_XML_PATH));
debug!("Parsed configuration: {cfg:?}");

match args.command {
Command::Install { force, package } => {
return action::install(force, package, repo);
return action::install(force, package, repo, &mut webapp);
}
Command::Uninstall { package } => {
return action::uninstall(package);
return action::uninstall(package, &mut webapp);
}
_ => {
error!("This command is not implemented");
Expand All @@ -98,18 +99,23 @@ pub mod action {
use crate::repo_index::RepoIndex;
use crate::repository::Repository;
use crate::versions::RudderVersion;
use crate::webapp_xml::restart_webapp;
use crate::webapp::Webapp;
use crate::{
PACKAGES_DATABASE_PATH, REPOSITORY_INDEX_PATH, RUDDER_VERSION_PATH, TMP_PLUGINS_FOLDER,
};
use std::path::Path;

pub fn uninstall(packages: Vec<String>) -> Result<()> {
pub fn uninstall(packages: Vec<String>, webapp: &mut Webapp) -> Result<()> {
let mut db = Database::read(PACKAGES_DATABASE_PATH)?;
packages.iter().try_for_each(|p| db.uninstall(p))
packages.iter().try_for_each(|p| db.uninstall(p, webapp))
}

pub fn install(force: bool, packages: Vec<String>, repository: Repository) -> Result<()> {
pub fn install(
force: bool,
packages: Vec<String>,
repository: Repository,
webapp: &mut Webapp,
) -> Result<()> {
packages.iter().try_for_each(|package| {
let rpkg_path = if Path::new(&package).exists() {
package.clone()
Expand Down Expand Up @@ -139,10 +145,10 @@ pub mod action {
dest.as_path().display().to_string()
};
let rpkg = Rpkg::from_path(&rpkg_path)?;
rpkg.install(force)?;
rpkg.install(force, webapp)?;
Ok(())
})?;
restart_webapp()
webapp.apply_changes()
}

pub fn list() -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions relay/sources/rudder-package/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum VerificationSuccess {

use crate::cmd::CmdOutput;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct SignatureVerifier {
keyring: PathBuf,
}
Expand Down
Loading

0 comments on commit 520accb

Please sign in to comment.