summaryrefslogtreecommitdiffstats
path: root/crates/core/plugin_sm
diff options
context:
space:
mode:
authorinitard <alex.solomes@softwareag.com>2022-01-12 12:18:21 +0100
committerGitHub <noreply@github.com>2022-01-12 12:18:21 +0100
commit735f39337f41362003d60a482542c0fecd603b58 (patch)
tree72c245961b70481e93d48ec6a77aaad5baddbe08 /crates/core/plugin_sm
parent141e93c03c8f9d9a9dd7076830445b3fd9cd5154 (diff)
Feature/651/configurable temp path (#732)
* configurable download path (WIP) (#651) Signed-off-by: initard <solo@softwareag.com> * download path test (WIP) (#651) Signed-off-by: initard <solo@softwareag.com> * default download path #651 Signed-off-by: initard <solo@softwareag.com> * install to download.path test (#651) Signed-off-by: initard <solo@softwareag.com> * formatting issues (#651) Signed-off-by: initard <solo@softwareag.com> * formatting issues (#651) Signed-off-by: initard <solo@softwareag.com> * rename download path to tmp path & test fix (#651) Signed-off-by: initard <solo@softwareag.com> * cargo fmt Signed-off-by: initard <solo@softwareag.com> * download path integration test (#651) Signed-off-by: initard <solo@softwareag.com> * adding doc detailing how to set temp path (#651) Signed-off-by: initard <solo@softwareag.com> * test fix (#651) Signed-off-by: initard <solo@softwareag.com> * adding sudo to doc (#651) Signed-off-by: initard <solo@softwareag.com> * removing unused test (#651) Signed-off-by: initard <solo@softwareag.com> * renaming, refactoring and extra documentation (#651) Signed-off-by: initard <solo@softwareag.com> * fixing naming of tmp.path (#651) Signed-off-by: initard <solo@softwareag.com> * changes to tmp dto #651 Signed-off-by: initard <solo@softwareag.com> Co-authored-by: initard <solo@softwareag.com>
Diffstat (limited to 'crates/core/plugin_sm')
-rw-r--r--crates/core/plugin_sm/src/plugin.rs18
-rw-r--r--crates/core/plugin_sm/src/plugin_manager.rs4
-rw-r--r--crates/core/plugin_sm/tests/plugin.rs2
3 files changed, 18 insertions, 6 deletions
diff --git a/crates/core/plugin_sm/src/plugin.rs b/crates/core/plugin_sm/src/plugin.rs
index c4f45ebc..eafea473 100644
--- a/crates/core/plugin_sm/src/plugin.rs
+++ b/crates/core/plugin_sm/src/plugin.rs
@@ -4,6 +4,7 @@ use async_trait::async_trait;
use csv::ReaderBuilder;
use download::Downloader;
use serde::Deserialize;
+use std::path::Path;
use std::{path::PathBuf, process::Output};
use tokio::io::BufWriter;
use tokio::{fs::File, io::AsyncWriteExt};
@@ -48,12 +49,16 @@ pub trait Plugin {
&self,
update: &SoftwareModuleUpdate,
logger: &mut BufWriter<File>,
+ download_path: &Path,
) -> Result<(), SoftwareError> {
match update.clone() {
SoftwareModuleUpdate::Install { mut module } => {
let module_url = module.url.clone();
match module_url {
- Some(url) => self.install_from_url(&mut module, &url, logger).await?,
+ Some(url) => {
+ self.install_from_url(&mut module, &url, logger, &download_path)
+ .await?
+ }
None => self.install(&module, logger).await?,
}
@@ -67,6 +72,7 @@ pub trait Plugin {
&self,
mut updates: Vec<SoftwareModuleUpdate>,
logger: &mut BufWriter<File>,
+ download_path: &Path,
) -> Vec<SoftwareError> {
let mut failed_updates = Vec::new();
@@ -85,7 +91,7 @@ pub trait Plugin {
};
let module_url = module.url.clone();
if let Some(url) = module_url {
- match Self::download_from_url(module, &url, logger).await {
+ match Self::download_from_url(module, &url, logger, &download_path).await {
Err(prepare_error) => {
failed_updates.push(prepare_error);
break;
@@ -100,7 +106,7 @@ pub trait Plugin {
let outcome = self.update_list(&updates, logger).await;
if let Err(SoftwareError::UpdateListNotSupported(_)) = outcome {
for update in updates.iter() {
- if let Err(error) = self.apply(update, logger).await {
+ if let Err(error) = self.apply(update, logger, download_path).await {
failed_updates.push(error);
};
}
@@ -130,8 +136,9 @@ pub trait Plugin {
module: &mut SoftwareModule,
url: &DownloadInfo,
logger: &mut BufWriter<File>,
+ download_path: &Path,
) -> Result<(), SoftwareError> {
- let downloader = Self::download_from_url(module, url, logger).await?;
+ let downloader = Self::download_from_url(module, url, logger, download_path).await?;
let result = self.install(module, logger).await;
Self::cleanup_downloaded_artefacts(downloader, logger).await?;
@@ -142,8 +149,9 @@ pub trait Plugin {
module: &mut SoftwareModule,
url: &DownloadInfo,
logger: &mut BufWriter<File>,
+ download_path: &Path,
) -> Result<Downloader, SoftwareError> {
- let downloader = Downloader::new(&module.name, &module.version, "/tmp");
+ let downloader = Downloader::new(&module.name, &module.version, &download_path);
logger
.write_all(
diff --git a/crates/core/plugin_sm/src/plugin_manager.rs b/crates/core/plugin_sm/src/plugin_manager.rs
index 90bcd6ba..fa17f4e2 100644
--- a/crates/core/plugin_sm/src/plugin_manager.rs
+++ b/crates/core/plugin_sm/src/plugin_manager.rs
@@ -4,6 +4,7 @@ use agent_interface::{
SoftwareError, SoftwareListRequest, SoftwareListResponse, SoftwareType, SoftwareUpdateRequest,
SoftwareUpdateResponse, DEFAULT,
};
+use std::path::Path;
use std::{
collections::HashMap,
fs,
@@ -220,6 +221,7 @@ impl ExternalPlugins {
&self,
request: &SoftwareUpdateRequest,
mut log_file: LogFile,
+ download_path: &Path,
) -> SoftwareUpdateResponse {
let mut response = SoftwareUpdateResponse::new(request);
let mut logger = log_file.buffer();
@@ -228,7 +230,7 @@ impl ExternalPlugins {
for software_type in request.modules_types() {
let errors = if let Some(plugin) = self.by_software_type(&software_type) {
let updates = request.updates_for(&software_type);
- plugin.apply_all(updates, &mut logger).await
+ plugin.apply_all(updates, &mut logger, &download_path).await
} else {
vec![SoftwareError::UnknownSoftwareType {
software_type: software_type.clone(),
diff --git a/crates/core/plugin_sm/tests/plugin.rs b/crates/core/plugin_sm/tests/plugin.rs
index 966f666c..5e1573b8 100644
--- a/crates/core/plugin_sm/tests/plugin.rs
+++ b/crates/core/plugin_sm/tests/plugin.rs
@@ -362,6 +362,7 @@ mod tests {
};
let mut logger = dev_null().await;
+ let download = PathBuf::from("/tmp");
// Call plugin update-list via API.
let errors = plugin
.apply_all(
@@ -370,6 +371,7 @@ mod tests {
SoftwareModuleUpdate::Remove { module: module2 },
],
&mut logger,
+ &download,
)
.await;