Skip to content

Commit

Permalink
Merge pull request #309 from paketo-buildpacks/caching-fix
Browse files Browse the repository at this point in the history
Fixes caching by accounting for dep_date at metadata root level
  • Loading branch information
dmikusa authored Feb 6, 2024
2 parents dc21af8 + 49ad47c commit a3f457a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
17 changes: 14 additions & 3 deletions layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,30 @@ func (l *LayerContributor) normalizeDependencyDeprecationDate(input map[string]i
if dep, ok := input["dependency"].(map[string]interface{}); ok {
for k, v := range dep {
if k == "deprecation_date" {
deprecationDate, err := l.parseDeprecationDate(v)
if err != nil {
if err := l.replaceDeprecationDate(dep, v); err != nil {
return err
}
dep["deprecation_date"] = deprecationDate
break
}
}
} else if depr_date, ok := input["deprecation_date"]; ok {
if err := l.replaceDeprecationDate(input, depr_date); err != nil {
return err
}
}

return nil
}

func (l *LayerContributor) replaceDeprecationDate(metadata map[string]interface{}, value interface{}) error {
deprecationDate, err := l.parseDeprecationDate(value)
if err != nil {
return err
}
metadata["deprecation_date"] = deprecationDate
return nil
}

// parseDeprecationDate accepts both string and time.Time as input, and returns
// a truncated time.Time value.
func (l *LayerContributor) parseDeprecationDate(v interface{}) (deprecationDate time.Time, err error) {
Expand Down
50 changes: 50 additions & 0 deletions layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,56 @@ func testLayer(t *testing.T, context spec.G, it spec.S) {
Expect(called).To(BeFalse())
})

it("does not contribute when deprecation_date is found on metadata map root", func() {
dependency = libpak.BuildpackDependency{
ID: "test-id",
Name: "test-name",
Version: "1.1.1",
URI: fmt.Sprintf("%s/test-path", server.URL()),
SHA256: "576dd8416de5619ea001d9662291d62444d1292a38e96956bc4651c01f14bca1",
Stacks: []string{"test-stack"},
Licenses: []libpak.BuildpackDependencyLicense{
{
Type: "test-type",
URI: "test-uri",
},
},
CPEs: []string{"cpe:2.3:a:some:jre:11.0.2:*:*:*:*:*:*:*"},
PURL: "pkg:generic/[email protected]?arch=amd64",
}
dlc.ExpectedMetadata = dependency

layer.Metadata = map[string]interface{}{
"id": dependency.ID,
"name": dependency.Name,
"version": dependency.Version,
"uri": dependency.URI,
"sha256": dependency.SHA256,
"stacks": []interface{}{dependency.Stacks[0]},
"licenses": []map[string]interface{}{
{
"type": dependency.Licenses[0].Type,
"uri": dependency.Licenses[0].URI,
},
},
"cpes": []interface{}{"cpe:2.3:a:some:jre:11.0.2:*:*:*:*:*:*:*"},
"purl": "pkg:generic/[email protected]?arch=amd64",
"deprecation_date": "0001-01-01T00:00:00Z",
}

var called bool

_, err := dlc.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) {
defer artifact.Close()

called = true
return layer, nil
})
Expect(err).NotTo(HaveOccurred())

Expect(called).To(BeFalse())
})

it("does not call function with missing deprecation_date", func() {
dependency = libpak.BuildpackDependency{
ID: "test-id",
Expand Down

0 comments on commit a3f457a

Please sign in to comment.