aggregateAllSectionsData - Single pass aggregation, collects all data needed
(allResults []vsa.ComponentResult)
| 841 | |
| 842 | // aggregateAllSectionsData - Single pass aggregation, collects all data needed |
| 843 | func aggregateAllSectionsData(allResults []vsa.ComponentResult) AllSectionsData { |
| 844 | data := AllSectionsData{ |
| 845 | TotalImages: len(allResults), |
| 846 | FallbackReasons: make(map[string]bool), |
| 847 | PolicyDiffCounts: make(map[string]PolicyDiffCounts), |
| 848 | SignatureStatus: "VERIFIED", // Default, will be overridden if any not verified |
| 849 | } |
| 850 | |
| 851 | // Single iteration - collect everything at once |
| 852 | for i, result := range allResults { |
| 853 | shortDigest := shortenImageDigest(result.ImageRef) |
| 854 | |
| 855 | // Collect image status |
| 856 | imgStatus := ImageStatus{ |
| 857 | Index: i + 1, |
| 858 | Digest: shortDigest, |
| 859 | } |
| 860 | |
| 861 | // Process VSA result (always process if available, even if there's an error) |
| 862 | if result.Result != nil { |
| 863 | processVSAResult(result.Result, &imgStatus, &data, shortDigest) |
| 864 | } else if result.Error != nil { |
| 865 | // If there's an error but no Result, create a status from the error |
| 866 | reason := extractReasonFromMessage(result.Error.Error()) |
| 867 | imgStatus.VSAStatus = fmt.Sprintf("FAILED(reason=%s)", reason) |
| 868 | data.VSAFailed++ |
| 869 | data.FallbackReasons[reason] = true |
| 870 | // When VSA retrieval fails, signature cannot be verified |
| 871 | data.SignatureStatus = "NOT VERIFIED" |
| 872 | } |
| 873 | |
| 874 | // Handle fallback |
| 875 | if result.FallbackResult != nil { |
| 876 | data.FallbackUsed = true |
| 877 | data.FallbackCount++ |
| 878 | data.FallbackResults = append(data.FallbackResults, *result.FallbackResult) |
| 879 | |
| 880 | if result.FallbackResult.Component.Success { |
| 881 | imgStatus.FallbackStatus = "PASSED" |
| 882 | data.FallbackPassed++ |
| 883 | } else { |
| 884 | imgStatus.FallbackStatus = "FAILED" |
| 885 | data.FallbackFailed++ |
| 886 | } |
| 887 | } else { |
| 888 | data.FallbackNotUsed++ |
| 889 | } |
| 890 | |
| 891 | data.ImageStatuses = append(data.ImageStatuses, imgStatus) |
| 892 | } |
| 893 | |
| 894 | // Determine overall result |
| 895 | // Overall passes if: all VSA passed, OR fallback was used and at least one fallback passed |
| 896 | data.OverallPassed = (data.VSAPassed == data.TotalImages) || |
| 897 | (data.FallbackUsed && data.FallbackPassed > 0) |
| 898 | |
| 899 | return data |
| 900 | } |
no test coverage detected