Skip to content

Commit

Permalink
fix: Properly escape module json
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder committed Sep 14, 2024
1 parent ce71711 commit fbf57e5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions process/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@ workspace = true

[features]
sigstore = ["dep:tokio", "dep:sigstore"]

[patch.crates-io]
sigstore = { git = "https://github.com/gmpinder/sigstore-rs.git", rev = "cd0d10429fc09ddb08a8d1c7244a1623772113af" }
12 changes: 2 additions & 10 deletions recipe/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{borrow::Cow, path::PathBuf, process};
use std::{borrow::Cow, path::PathBuf};

use blue_build_utils::syntax_highlighting::highlight_ser;
use colored::Colorize;
use indexmap::IndexMap;
use log::{error, trace, warn};
use log::{trace, warn};
use miette::{bail, Result};
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
Expand Down Expand Up @@ -62,14 +62,6 @@ impl<'a> ModuleRequiredFields<'a> {
self.get_module_type_list("containerfile", "snippets")
}

#[must_use]
pub fn print_module_context(&'a self) -> String {
serde_json::to_string(self).unwrap_or_else(|e| {
error!("Failed to parse module!!!!!: {e}");
process::exit(1);
})
}

#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn get_copy_args(&'a self) -> Option<(Option<&'a str>, &'a str, &'a str)> {
Expand Down
2 changes: 1 addition & 1 deletion template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rinja = "0.3.0"
rinja = { version = "0.3.0", features = ["serde_json"] }
blue-build-recipe = { version = "=0.8.17", path = "../recipe" }
blue-build-utils = { version = "=0.8.17", path = "../utils" }

Expand Down
5 changes: 4 additions & 1 deletion template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ fn should_color() -> bool {

mod filters {
#[allow(clippy::unnecessary_wraps)]
pub fn replace<T: std::fmt::Display>(input: T, from: char, to: &str) -> rinja::Result<String> {
pub fn replace<T>(input: T, from: char, to: &str) -> rinja::Result<String>
where
T: std::fmt::Display,
{
Ok(format!("{input}").replace(from, to))
}
}
4 changes: 2 additions & 2 deletions template/templates/modules/modules.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN \
{%- endif %}
--mount=type=bind,from=ghcr.io/blue-build/cli:{{ exports_tag }}-build-scripts,src=/scripts/,dst=/tmp/scripts/ \
--mount=type=cache,dst=/var/cache/rpm-ostree,id=rpm-ostree-cache-{{ recipe.name }}-{{ recipe.image_version }},sharing=locked \
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module.print_module_context() }}' \
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}' \
&& ostree container commit
{%- endif %}
{%- endif %}
Expand Down Expand Up @@ -59,7 +59,7 @@ RUN \
--mount=type=bind,from=stage-modules,src=/modules,dst=/tmp/modules,rw \
{%- endif %}
--mount=type=bind,from=ghcr.io/blue-build/cli:{{ exports_tag }}-build-scripts,src=/scripts/,dst=/tmp/scripts/ \
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module.print_module_context() }}'
/tmp/scripts/run_module.sh '{{ module.module_type }}' '{{ module|json|safe }}'
{%- endif %}
{%- endif %}
{%- endfor %}
Expand Down

0 comments on commit fbf57e5

Please sign in to comment.