Skip to content

Commit

Permalink
Adds space to allow passing back of problems to fact generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaize Kaye committed Apr 15, 2024
1 parent c0181c7 commit 4910d8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions internal/handler/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down

0 comments on commit 4910d8b

Please sign in to comment.