Skip to content

Commit

Permalink
interim work
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Oct 10, 2023
1 parent 0ccfca8 commit dff6164
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
51 changes: 21 additions & 30 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,7 @@ func parserFilterLoopForBinaryPayloads(insights InsightsData, p string, h *Messa
log.Println(fmt.Errorf(err.Error()))
}

for _, r := range result {
if fact, ok := r.(LagoonFact); ok {
// Handle single fact
err = h.sendFactsToLagoonAPI([]LagoonFact{fact}, apiClient, resource, source)
if err != nil {
fmt.Println(err)
}
} else if facts, ok := r.([]LagoonFact); ok {
// Handle slice of facts
h.sendFactsToLagoonAPI(facts, apiClient, resource, source)
} else {
// Unexpected type returned from filter()
log.Printf("unexpected type returned from filter(): %T\n", r)
}
}
processResultset(result, err, h, apiClient, resource, source)
}
}

Expand All @@ -326,20 +312,25 @@ func parserFilterLoopForPayloads(insights InsightsData, p PayloadInput, h *Messa
log.Println(fmt.Errorf(err.Error()))
}

for _, r := range result {
if fact, ok := r.(LagoonFact); ok {
// Handle single fact
err = h.sendFactsToLagoonAPI([]LagoonFact{fact}, apiClient, resource, source)
if err != nil {
fmt.Println(err)
}
} else if facts, ok := r.([]LagoonFact); ok {
// Handle slice of facts
h.sendFactsToLagoonAPI(facts, apiClient, resource, source)
} else {
// Unexpected type returned from filter()
log.Printf("unexpected type returned from filter(): %T\n", r)
processResultset(result, err, h, apiClient, resource, source)
}
}

// processResultset will send results as facts to the lagoon api after processing via a parser filter
func processResultset(result []interface{}, err error, h *Messaging, apiClient graphql.Client, resource ResourceDestination, source string) {
for _, r := range result {
if fact, ok := r.(LagoonFact); ok {
// Handle single fact
err = h.sendFactsToLagoonAPI([]LagoonFact{fact}, apiClient, resource, source)
if err != nil {
fmt.Println(err)
}
} else if facts, ok := r.([]LagoonFact); ok {
// Handle slice of facts
h.sendFactsToLagoonAPI(facts, apiClient, resource, source)
} else {
// Unexpected type returned from filter()
log.Printf("unexpected type returned from filter(): %T\n", r)
}
}
}
Expand Down Expand Up @@ -390,11 +381,11 @@ func determineResourceFromLagoonAPI(apiClient graphql.Client, resource ResourceD
// Get project data (we need the project ID to be able to utilise the environmentByName query)
project, err := lagoonclient.GetProjectByName(context.TODO(), apiClient, resource.Project)
if err != nil {
return lagoonclient.Project{}, lagoonclient.Environment{}, fmt.Errorf("error: unable to determine resource destination (does %s:%s exist?)", resource.Project, resource.Environment)
return lagoonclient.Project{}, lagoonclient.Environment{}, fmt.Errorf("error: unable to determine resource destination (does %s:%s exist?): %v", resource.Project, resource.Environment, err.Error())
}

if project.Id == 0 || project.Name == "" {
return lagoonclient.Project{}, lagoonclient.Environment{}, fmt.Errorf("error: unable to determine resource destination (does %s:%s exist?)", resource.Project, resource.Environment)
return lagoonclient.Project{}, lagoonclient.Environment{}, fmt.Errorf("error: unable to determine resource destination (does %s:%s exist?): %v", resource.Project, resource.Environment, err.Error())
}

environment, err := lagoonclient.GetEnvironmentFromName(context.TODO(), apiClient, resource.Environment, project.Id)
Expand Down
14 changes: 7 additions & 7 deletions internal/handler/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func (h *Messaging) processMessageQueue(message mq.Message) {

// set up defer to ack the message after we're done processing

defer func(message mq.Message) {
// Ack to remove from queue
err := message.Ack(false)
if err != nil {
fmt.Printf("Failed to acknowledge message: %s\n", err.Error())
}
}(message)
//defer func(message mq.Message) {
// // Ack to remove from queue
// err := message.Ack(false)
// if err != nil {
// fmt.Printf("Failed to acknowledge message: %s\n", err.Error())
// }
//}(message)

acknowledgeMessage := func(message mq.Message) func() {
return func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/testassets/testSbom.gz.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"annotations": {},
"labels": {
"lagoon.sh/project": "high-cotton",
"lagoon.sh/environment": "Master",
"lagoon.sh/project": "organization-cotton",
"lagoon.sh/environment": "main",
"lagoon.sh/service": "cli",
"lagoon.sh/insightsType": "sbom-gz"
}
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ func main() {
problemsFromSBOM = getEnvBool("PROBLEMS_FROM_SBOM", problemsFromSBOM)
trivyServerEndpoint = getEnv("TRIVY_SERVER_ENDPOINT", trivyServerEndpoint)

if problemsFromSBOM == true {
log.Println("PROBLEMS FROM SBOM - enabled")
if trivyServerEndpoint == "" {
log.Fatalf("NO TRIVY SERVER ENDPOINT SET - exiting")
os.Exit(1)
}
}

// configure the backup handler settings
broker := handler.RabbitBroker{
Hostname: fmt.Sprintf("%s:%s", mqHost, mqPort),
Expand Down

0 comments on commit dff6164

Please sign in to comment.