From 0f066187c3a03f77ecd7831185553f99dfec23a8 Mon Sep 17 00:00:00 2001 From: Ralf Pannemans Date: Fri, 7 Jul 2023 16:59:55 +0200 Subject: [PATCH] Introduce struct with metadata to identify a dependency Signed-off-by: Ralf Pannemans --- buildmodule.go | 25 +++++++++++++++++++++++++ layer.go | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/buildmodule.go b/buildmodule.go index 03cc725..69dbb5c 100644 --- a/buildmodule.go +++ b/buildmodule.go @@ -95,6 +95,31 @@ type BuildModuleDependency struct { DeprecationDate time.Time `toml:"deprecation_date"` } +// DependencyLayerContributorMetadata returns the subset of data from BuildpackDependency that is use as expected metadata for the DependencyLayerContributor. +type DependencyLayerContributorMetadata struct { + // ID is the dependency ID. + ID string `toml:"id"` + + // Name is the dependency name. + Name string `toml:"name"` + + // Version is the dependency version. + Version string `toml:"version"` + + // SHA256 is the hash of the dependency. + SHA256 string `toml:"sha256"` +} + +// GetMetadata return the relevant metadata of this dependency +func (b BuildpackDependency) GetMetadata() DependencyLayerContributorMetadata { + return DependencyLayerContributorMetadata{ + ID: b.ID, + Name: b.Name, + Version: b.Version, + SHA256: b.SHA256, + } +} + // Equals compares the 2 structs if they are equal. This is very simiar to reflect.DeepEqual // except that properties that will not work (e.g. DeprecationDate) are ignored. func (b1 BuildModuleDependency) Equals(b2 BuildModuleDependency) bool { diff --git a/layer.go b/layer.go index 79c3cb0..f112220 100644 --- a/layer.go +++ b/layer.go @@ -218,7 +218,7 @@ type DependencyLayerContributor struct { func NewDependencyLayerContributor(dependency BuildModuleDependency, cache DependencyCache, types libcnb.LayerTypes) DependencyLayerContributor { return DependencyLayerContributor{ Dependency: dependency, - ExpectedMetadata: dependency, + ExpectedMetadata: dependency.GetMetadata(), DependencyCache: cache, ExpectedTypes: types, }