inspect: lazily load attestation data

Delay loading the attestation data immediately, and only compute it upon
request. We do this using a deferred function which allows to define the
computation in the same place as before, but perform the computation
later.

With this patch, we ensure that the attestation data is only pulled from
the remote if it is actually referenced in the format string -
otherwise, we can skip it, for improved performance.

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-01-10 13:00:39 +00:00
parent 1d2ac78443
commit 56950ece69
2 changed files with 99 additions and 62 deletions

View File

@ -213,7 +213,10 @@ type tplInput struct {
}
func (inp tplInput) SBOM() (sbomStub, error) {
sbom := inp.result.SBOM()
sbom, err := inp.result.SBOM()
if err != nil {
return sbomStub{}, nil
}
for _, v := range sbom {
return v, nil
}
@ -221,7 +224,10 @@ func (inp tplInput) SBOM() (sbomStub, error) {
}
func (inp tplInput) Provenance() (provenanceStub, error) {
provenance := inp.result.Provenance()
provenance, err := inp.result.Provenance()
if err != nil {
return provenanceStub{}, nil
}
for _, v := range provenance {
return v, nil
}
@ -237,9 +243,9 @@ type tplInputs struct {
}
func (inp tplInputs) SBOM() (map[string]sbomStub, error) {
return inp.result.SBOM(), nil
return inp.result.SBOM()
}
func (inp tplInputs) Provenance() (map[string]provenanceStub, error) {
return inp.result.Provenance(), nil
return inp.result.Provenance()
}