Skip to content

Commit

Permalink
Deny unknown fields (#272)
Browse files Browse the repository at this point in the history
- There were some structs missed with the first commit to address this issue (93abd77)
  • Loading branch information
BrianBorge committed Nov 16, 2024
1 parent 221fe5b commit e527264
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions buildpacks/ruby/src/layers/bundle_download_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl MetadataDiff for Metadata {
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub(crate) struct MetadataV1 {
pub(crate) version: ResolvedBundlerVersion,
}
Expand Down
3 changes: 3 additions & 0 deletions buildpacks/ruby/src/layers/bundle_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl MetadataDiff for Metadata {
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub(crate) struct MetadataV1 {
pub(crate) stack: String,
pub(crate) ruby_version: ResolvedRubyVersion,
Expand All @@ -170,6 +171,7 @@ pub(crate) struct MetadataV1 {
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub(crate) struct MetadataV2 {
pub(crate) distro_name: String,
pub(crate) distro_version: String,
Expand Down Expand Up @@ -321,6 +323,7 @@ fn display_name(cmd: &mut Command, env: &Env) -> String {
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub(crate) struct BundleDigest {
env: String,
gemfile: String,
Expand Down
1 change: 1 addition & 0 deletions buildpacks/ruby/src/layers/metrics_agent_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DOWNLOAD_URL: &str =
const DOWNLOAD_SHA: &str = "f9bf9f33c949e15ffed77046ca38f8dae9307b6a0181c6af29a25dec46eb2dac";

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub(crate) struct Metadata {
download_url: String,
}
Expand Down
2 changes: 2 additions & 0 deletions buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ fn install_ruby(metadata: &Metadata, layer_path: &Path) -> Result<(), RubyBuildp
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub(crate) struct MetadataV1 {
pub(crate) stack: String,
pub(crate) version: ResolvedRubyVersion,
}

#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub(crate) struct MetadataV2 {
pub(crate) distro_name: String,
pub(crate) distro_version: String,
Expand Down
1 change: 1 addition & 0 deletions buildpacks/ruby/src/layers/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ mod tests {

/// Struct for asserting the behavior of `cached_layer_write_metadata`
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
struct TestMetadata {
value: String,
}
Expand Down
1 change: 1 addition & 0 deletions buildpacks/ruby/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl From<RubyBuildpackError> for libcnb::Error<RubyBuildpackError> {
buildpack_main!(RubyBuildpack);

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
struct BundleWithout(String);

impl BundleWithout {
Expand Down
1 change: 1 addition & 0 deletions commons/src/cache/app_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub enum PathState {
/// allows for emails, that might live a long time, to reference a specific SHA of an
/// asset.
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub(crate) struct Metadata {
pub(crate) app_dir_path: PathBuf,
}
Expand Down
2 changes: 2 additions & 0 deletions commons/src/gemfile_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl GemfileLock {
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(deny_unknown_fields)]
pub struct ResolvedRubyVersion(pub String);

impl Display for ResolvedRubyVersion {
Expand All @@ -90,6 +91,7 @@ impl Display for ResolvedRubyVersion {
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(deny_unknown_fields)]
pub struct ResolvedBundlerVersion(pub String);

impl Display for ResolvedBundlerVersion {
Expand Down
6 changes: 6 additions & 0 deletions commons/src/metadata_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PLATFORM_ENV_VAR: &str = "user configured environment variables";
/// use commons::metadata_digest::MetadataDigest;
///
/// #[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
/// #[serde(deny_unknown_fields)]
/// pub(crate) struct BundleInstallLayerMetadata {
/// ruby_version: String,
/// force_bundle_install_key: String,
Expand Down Expand Up @@ -82,6 +83,7 @@ const PLATFORM_ENV_VAR: &str = "user configured environment variables";
/// # }
/// #
/// # #[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
/// # #[serde(deny_unknown_fields)]
/// # struct FakeLayerMetadata {
/// # digest: MetadataDigest,
/// # }
Expand Down Expand Up @@ -148,6 +150,7 @@ const PLATFORM_ENV_VAR: &str = "user configured environment variables";
/// add logic to your buildpack to re-run that command similar to the "escape valve" discussed
/// above, but triggered by buildpack author instead of the end user.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(deny_unknown_fields)]
pub struct MetadataDigest {
platform_env: Option<PlatformEnvDigest>,
files: Option<PathsDigest>, // Must be last for serde to be happy https://github.com/toml-rs/toml-rs/issues/142
Expand Down Expand Up @@ -235,9 +238,11 @@ impl MetadataDigest {
}

#[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
struct ShaString(String);

#[derive(Serialize, Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
struct PlatformEnvDigest(ShaString);
impl PlatformEnvDigest {
fn new(platform: &impl Platform) -> Self {
Expand All @@ -248,6 +253,7 @@ impl PlatformEnvDigest {
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(deny_unknown_fields)]
struct PathsDigest(HashMap<PathBuf, ShaString>);

/// Main struct for detecting changes between two iterations
Expand Down

0 comments on commit e527264

Please sign in to comment.