From 4910d8b636163f2cbc1255a4d7ec3238748523eb Mon Sep 17 00:00:00 2001 From: Blaize Kaye Date: Mon, 15 Apr 2024 14:37:26 +1200 Subject: [PATCH] Adds space to allow passing back of problems to fact generation --- internal/handler/main.go | 8 +++++--- internal/handler/messaging.go | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/handler/main.go b/internal/handler/main.go index 1bf13a4..4381f74 100644 --- a/internal/handler/main.go +++ b/internal/handler/main.go @@ -282,15 +282,17 @@ func (t *authedTransport) RoundTrip(req *http.Request) (*http.Response, error) { } type LagoonSourceFactMap map[string][]LagoonFact +type LagoonSourceProblemMap map[string][]lagoonclient.LagoonProblem // Incoming payload may contain facts or problems, so we need to handle these differently -func (h *Messaging) gatherFactsFromInsightData(incoming *InsightsMessage, resource ResourceDestination, insights InsightsData) ([]LagoonSourceFactMap, error) { +func (h *Messaging) gatherFactsFromInsightData(incoming *InsightsMessage, resource ResourceDestination, insights InsightsData) ([]LagoonSourceFactMap, []LagoonSourceProblemMap, error) { apiClient := h.getApiClient() // Here we collect all source fact maps before writing them _once_ lagoonSourceFactMapCollection := []LagoonSourceFactMap{} + lagoonSourceProblemMapCollection := []LagoonSourceProblemMap{} if resource.Project == "" && resource.Environment == "" { - return lagoonSourceFactMapCollection, fmt.Errorf("no resource definition labels could be found in payload (i.e. lagoon.sh/project or lagoon.sh/environment)") + return lagoonSourceFactMapCollection, lagoonSourceProblemMapCollection, fmt.Errorf("no resource definition labels could be found in payload (i.e. lagoon.sh/project or lagoon.sh/environment)") } slog.Debug("Processing data", "InputPayload", insights.InputPayload, "LagoonType", insights.LagoonType, "InsightsType", insights.InsightsType) @@ -328,7 +330,7 @@ func (h *Messaging) gatherFactsFromInsightData(incoming *InsightsMessage, resour lagoonSourceFactMapCollection = append(lagoonSourceFactMapCollection, lagoonSourceFactMap) } - return lagoonSourceFactMapCollection, nil + return lagoonSourceFactMapCollection, lagoonSourceProblemMapCollection, nil } func trivySBOMProcessing(apiClient graphql.Client, trivyServerEndpoint string, resource ResourceDestination, payload string) error { diff --git a/internal/handler/messaging.go b/internal/handler/messaging.go index 836877a..bdedf34 100644 --- a/internal/handler/messaging.go +++ b/internal/handler/messaging.go @@ -135,7 +135,7 @@ func (h *Messaging) processMessageQueue(message mq.Message) { insights.InsightsType != Direct { slog.Error("only 'sbom', 'direct', 'raw', and 'image' types are currently supported for api processing") } else { - lagoonSourceFactMapCollection, err := h.gatherFactsFromInsightData(incoming, resource, insights) + lagoonSourceFactMapCollection, lagoonSourceProblemMapCollection, err := h.gatherFactsFromInsightData(incoming, resource, insights) if err != nil { slog.Error("Unable to gather facts from incoming data", "Error", err.Error()) @@ -154,7 +154,11 @@ func (h *Messaging) processMessageQueue(message mq.Message) { } } } - + for _, lspm := range lagoonSourceProblemMapCollection { + for sourceName, problems := range lspm { + fmt.Println("GOT PROBLEM COUNT FOR SOURCE '%v': %v", sourceName, len(problems)) + } + } } } acknowledgeMessage()