Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sozo-walnut): remove sensitive data from dojo configuration file #2978

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions crates/sozo/walnut/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ version.workspace = true

[dependencies]
anyhow.workspace = true
clap.workspace = true
console.workspace = true
dojo-utils.workspace = true
reqwest.workspace = true
scarb.workspace = true
scarb-ui.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet.workspace = true
thiserror.workspace = true
toml.workspace = true
url.workspace = true
urlencoding = "2.1.3"
walkdir.workspace = true
dojo-utils.workspace = true
clap.workspace = true

[dev-dependencies]
starknet.workspace = true
3 changes: 3 additions & 0 deletions crates/sozo/walnut/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub enum Error {
#[error("Invalid file name")]
InvalidFileName,

#[error("Failed to serialize toml: {0}")]
TomlSerializationError(#[from] toml::ser::Error),

#[error("Namespace prefix not found in file name")]
NamespacePrefixNotFound,

Expand Down
40 changes: 35 additions & 5 deletions crates/sozo/walnut/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,41 @@
// Safe to unwrap here because we're iterating over files within root_dir,
// so path will always have root_dir as a prefix
let relative_path = path.strip_prefix(root_dir).unwrap();
let file_content = std::fs::read_to_string(path)?;
file_data.insert(
relative_path.to_string_lossy().into_owned(),
serde_json::Value::String(file_content),
);
let mut file_content = std::fs::read_to_string(path)?;

Check warning on line 89 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L89

Added line #L89 was not covered by tests

// Check if the file is a TOML file and its name starts with "dojo_"
if extension == "toml"
&& path
.file_stem()
.and_then(OsStr::to_str)
.map_or(false, |name| name.starts_with("dojo_"))

Check warning on line 96 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L92-L96

Added lines #L92 - L96 were not covered by tests
{
if let Ok(mut toml_data) = file_content.parse::<toml::Value>() {
if let Some(table) = toml_data.as_table_mut() {

Check warning on line 99 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L98-L99

Added lines #L98 - L99 were not covered by tests
// Remove the "env" table if it exists
table.remove("env");

Check warning on line 101 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L101

Added line #L101 was not covered by tests

// Serialize the modified TOML data back into a string, and
// handle any serialization error
file_content = toml::to_string(&toml_data)
.map_err(Error::TomlSerializationError)?;

Check warning on line 106 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L105-L106

Added lines #L105 - L106 were not covered by tests

// Insert the updated content into file_data, using the relative
// path as the key
file_data.insert(
relative_path.to_string_lossy().into_owned(),
Value::String(file_content),
);
}
}
} else {
// If the file is not a "dojo_" prefixed TOML file, just insert the
// original content
file_data.insert(
relative_path.to_string_lossy().into_owned(),
Value::String(file_content),
);
}

Check warning on line 123 in crates/sozo/walnut/src/verification.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/walnut/src/verification.rs#L110-L123

Added lines #L110 - L123 were not covered by tests
}
}
}
Expand Down
Loading