Skip to content

Commit

Permalink
Returns problems from sbom processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaize Kaye committed Apr 16, 2024
1 parent 75d65e8 commit f7863ed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
20 changes: 2 additions & 18 deletions internal/handler/insightsParserFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@ func processSbomInsightsData(h *Messaging, insights InsightsData, v string, apiC
logger := slog.With("ProjectName", resource.Project, "EnvironmentName", resource.Environment, "Source", source)

// ret values
problemSlice := []lagoonclient.LagoonProblem{
{
Id: 0,
Environment: 0,
Identifier: "test",
Version: "",
FixedVersion: "",
Source: "",
Service: "",
Data: "",
Severity: "",
SeverityScore: 0,
AssociatedPackage: "",
Description: "",
Links: "",
},
}
var problemSlice []lagoonclient.LagoonProblem

if insights.InsightsType != Sbom {
return []LagoonFact{}, problemSlice, "", nil
Expand All @@ -57,7 +41,7 @@ func processSbomInsightsData(h *Messaging, insights InsightsData, v string, apiC
logger.Debug("Trivy is reachable")
}
if isAlive {
err = SbomToProblems(apiClient, h.TrivyServerEndpoint, "/tmp/", environment.Id, resource.Service, *bom)
problemSlice, err = SbomToProblems(apiClient, h.TrivyServerEndpoint, "/tmp/", environment.Id, resource.Service, *bom)
}
if err != nil {
return nil, problemSlice, "", err
Expand Down
5 changes: 5 additions & 0 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ func (h *Messaging) deleteExistingFactsBySource(apiClient graphql.Client, enviro
return nil
}

func (h *Messaging) SendProblemSliceToLagoon(result []lagoonclient.LagoonProblem, resource ResourceDestination, source string) error {
slog.Info(fmt.Sprintf("Found the following problems for Project '%v', environment '%v', source '%v"), resource.Project, resource.Environment, source)
return nil
}

func (h *Messaging) getApiClient() graphql.Client {
apiClient := graphql.NewClient(h.LagoonAPI.Endpoint, &http.Client{Transport: &authedTransport{wrapped: http.DefaultTransport, h: h}})
return apiClient
Expand Down
7 changes: 6 additions & 1 deletion internal/handler/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ 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))
err := h.SendProblemSliceToLagoon(problems, resource, sourceName)
if err != nil {
slog.Error("Unable to write problems to api", "Error", err.Error())
rejectMessage(false)
return
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/handler/trivyProcessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (

const problemSource = "insights-handler-trivy"

func SbomToProblems(apiClient graphql.Client, trivyRemoteAddress string, bomWriteDirectory string, environmentId int, service string, sbom cdx.BOM) error {
func SbomToProblems(apiClient graphql.Client, trivyRemoteAddress string, bomWriteDirectory string, environmentId int, service string, sbom cdx.BOM) ([]lagoonclient.LagoonProblem, error) {
problemsArray, err := executeProcessingTrivy(trivyRemoteAddress, bomWriteDirectory, sbom)
if err != nil {
return fmt.Errorf("unable to execute trivy processing: %v", err.Error())
return problemsArray, fmt.Errorf("unable to execute trivy processing: %v", err.Error())
}

for i := 0; i < len(problemsArray); i++ {
Expand All @@ -31,9 +31,9 @@ func SbomToProblems(apiClient graphql.Client, trivyRemoteAddress string, bomWrit

err = writeProblemsArrayToApi(apiClient, environmentId, problemSource, service, problemsArray)
if err != nil {
return fmt.Errorf("unable to execute trivy processing- writing problems to api: %v", err.Error())
return problemsArray, fmt.Errorf("unable to execute trivy processing- writing problems to api: %v", err.Error())
}
return nil
return problemsArray, nil
}

func convertBOMToProblemsArray(environment int, source string, service string, bom cdx.BOM) ([]lagoonclient.LagoonProblem, error) {
Expand Down

0 comments on commit f7863ed

Please sign in to comment.