escape incoming sync backslashes (BREAKING)

This commit is contained in:
mbecker20
2025-02-26 14:55:58 -08:00
parent 990bef003a
commit c718ee0d2c
4 changed files with 32 additions and 10 deletions
+1 -1
View File
@@ -517,6 +517,6 @@ pub async fn init_execution_update(
// Don't actually send it here, let the handlers send it after they can set action state.
update.id = add_update_without_send(&update).await?;
}
Ok(update)
}
+1 -3
View File
@@ -143,9 +143,7 @@ fn read_resource_file(
path: file_path.display().to_string(),
contents: contents.clone(),
});
let more = toml::from_str::<ResourcesToml>(&contents)
// the error without this comes through with multiple lines (\n) and looks bad
.map_err(|e| anyhow!("{e:#}"))
let more = super::deserialize_resources_toml(&contents)
.context("failed to parse resource file contents")?;
log.push('\n');
let path_for_view =
+29 -5
View File
@@ -1,11 +1,21 @@
use std::{collections::HashMap, str::FromStr};
use anyhow::anyhow;
use komodo_client::entities::{
action::Action, alerter::Alerter, build::Build, builder::Builder,
deployment::Deployment, procedure::Procedure, repo::Repo,
server::Server, server_template::ServerTemplate, stack::Stack,
sync::ResourceSync, tag::Tag, toml::ResourceToml, ResourceTarget,
ResourceTargetVariant,
action::Action,
alerter::Alerter,
build::Build,
builder::Builder,
deployment::Deployment,
procedure::Procedure,
repo::Repo,
server::Server,
server_template::ServerTemplate,
stack::Stack,
sync::ResourceSync,
tag::Tag,
toml::{ResourceToml, ResourcesToml},
ResourceTarget, ResourceTargetVariant,
};
use mungos::mongodb::bson::oid::ObjectId;
use toml::ToToml;
@@ -209,3 +219,17 @@ impl AllResourcesById {
})
}
}
fn deserialize_resources_toml(
toml_str: &str,
) -> anyhow::Result<ResourcesToml> {
::toml::from_str::<ResourcesToml>(
&toml_str
// Escape the \ for the user on incoming.
// After deserialized by `toml` crate, the contents
// will match what would be passed on eg command line exactly.
.replace(r#"\"#, r#"\\"#),
)
// the error without this comes through with multiple lines (\n) and looks bad
.map_err(|e| anyhow!("{e:#}"))
}
+1 -1
View File
@@ -56,7 +56,7 @@ pub async fn get_remote_resources(
// ==========
let mut resources = ResourcesToml::default();
let resources = if !sync.config.file_contents.is_empty() {
toml::from_str::<ResourcesToml>(&sync.config.file_contents)
super::deserialize_resources_toml(&sync.config.file_contents)
.context("failed to parse resource file contents")
.map(|more| {
extend_resources(