Skip to content

Commit

Permalink
Introduce struct with metadata to identify a dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf Pannemans <[email protected]>
  • Loading branch information
c0d1ngm0nk3y committed Aug 18, 2023
1 parent 9588657 commit 0f06618
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions buildmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 0f06618

Please sign in to comment.