From f0c383ecc885867e57011e514805bc3bd5f7c8da Mon Sep 17 00:00:00 2001 From: Javier Rodriguez Date: Fri, 11 Apr 2025 11:46:19 +0200 Subject: [PATCH] fix(attestation-result): Include material annotations to attestation results Signed-off-by: Javier Rodriguez --- app/cli/internal/action/attestation_status.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/cli/internal/action/attestation_status.go b/app/cli/internal/action/attestation_status.go index 4986fb13b..903d4ecc6 100644 --- a/app/cli/internal/action/attestation_status.go +++ b/app/cli/internal/action/attestation_status.go @@ -269,6 +269,9 @@ func populateContractMaterials(inputSchemaMaterials []*pbc.CraftingSchema_Materi if err := setMaterialValue(cm, materialResult); err != nil { return fmt.Errorf("setting material value: %w", err) } + + // Update the expected annotations of the material stated on the contract with the ones in the attestation + updateMaterialAnnotations(cm, materialResult) } res.Materials = append(res.Materials, *materialResult) @@ -277,6 +280,22 @@ func populateContractMaterials(inputSchemaMaterials []*pbc.CraftingSchema_Materi return nil } +// updateMaterialAnnotations iterates through all expected annotations for the material +// and attempts to find their corresponding values in the incoming attestation result. +func updateMaterialAnnotations(cm *v1.Attestation_Material, attsMaterial *AttestationStatusMaterial) { + // Loop through the expected annotations in the attestation material + for k := range cm.Annotations { + // Check if the annotation exists in the provided attestation material + for _, a := range attsMaterial.Annotations { + // If the annotation name matches, update its value + if a.Name == k { + a.Value = cm.Annotations[k] + break + } + } + } +} + // populateAdditionalMaterials populates the materials that are not defined in the contract schema func populateAdditionalMaterials(attsMaterials map[string]*v1.Attestation_Material, res *AttestationStatusResult, visitedMaterials map[string]struct{}) error { for name, m := range attsMaterials {