Skip to content

Commit

Permalink
Merge branch 'main' into feature/trivy_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Sep 25, 2023
2 parents 6871af2 + cdb9a5c commit 0cacbc3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 28 deletions.
91 changes: 65 additions & 26 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,42 +272,81 @@ func (h *Messaging) sendToLagoonAPI(incoming *InsightsMessage, resource Resource

if insights.InputPayload == Payload {
for _, p := range incoming.Payload {
for _, filter := range parserFilters {
var result []interface{}
var source string
parserFilterLoopForPayloads(insights, p, h, apiClient, resource)
}
}

if insights.LagoonType == Facts {
json, err := json.Marshal(p)
if err != nil {
log.Println(fmt.Errorf(err.Error()))
}
if insights.InputPayload == BinaryPayload {
for _, p := range incoming.BinaryPayload {
parserFilterLoopForBinaryPayloads(insights, p, h, apiClient, resource)
}
}

result, source, err = filter(h, insights, fmt.Sprintf("%s", json), apiClient, resource)
return nil
}

func parserFilterLoopForBinaryPayloads(insights InsightsData, p string, h *Messaging, apiClient graphql.Client, resource ResourceDestination) {
for _, filter := range parserFilters {

if insights.LagoonType == Facts { // This should be more or less trivially true

result, source, err := filter(h, insights, p, apiClient, resource)
if err != nil {
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 {
log.Println(fmt.Errorf(err.Error()))
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)
}
}
}
}
}

func parserFilterLoopForPayloads(insights InsightsData, p PayloadInput, h *Messaging, apiClient graphql.Client, resource ResourceDestination) {
for _, filter := range parserFilters {
var result []interface{}
var source string

if insights.LagoonType == Facts { // This should be more or less trivially true
json, err := json.Marshal(p)
if err != nil {
log.Println(fmt.Errorf(err.Error()))
}

result, source, err = filter(h, insights, fmt.Sprintf("%s", json), apiClient, resource)
if err != nil {
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)
}
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)
}
}
}
}

return nil
}

func (h *Messaging) sendFactsToLagoonAPI(facts []LagoonFact, apiClient graphql.Client, resource ResourceDestination, source string) error {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func main() {
flag.StringVar(&lagoonAPIHost, "lagoon-api-host", "http://localhost:3000/graphql", "The host for the lagoon api.")
flag.StringVar(&jwtTokenSigningKey, "jwt-token-signing-key", "super-secret-string", "The jwt signing token key or secret.")
flag.StringVar(&jwtAudience, "jwt-audience", "api.dev", "The jwt audience.")
flag.StringVar(&jwtSubject, "jwt-subject", "actions-handler", "The jwt audience.")
flag.StringVar(&jwtIssuer, "jwt-issuer", "actions-handler", "The jwt audience.")
flag.StringVar(&jwtSubject, "jwt-subject", "insights-handler", "The jwt audience.")
flag.StringVar(&jwtIssuer, "jwt-issuer", "insights-handler", "The jwt issuer.")
flag.StringVar(&insightsQueueName, "insights-queue-name", "lagoon-insights:items", "The name of the queue in rabbitmq to use.")
flag.StringVar(&insightsExchange, "insights-exchange", "lagoon-insights", "The name of the exchange in rabbitmq to use.")
flag.StringVar(&s3SecretAccessKey, "secret-access-key", "minio123", "s3 secret access key to use.")
Expand Down

0 comments on commit 0cacbc3

Please sign in to comment.