diff --git a/internal/handler/main.go b/internal/handler/main.go index a855cb3..4ba390d 100644 --- a/internal/handler/main.go +++ b/internal/handler/main.go @@ -329,6 +329,18 @@ func parserFilterLoopForPayloads(insights InsightsData, p PayloadInput, h *Messa // 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) { + project, environment, apiErr := determineResourceFromLagoonAPI(apiClient, resource) + if apiErr != nil { + log.Println(apiErr) + } + + // Even if we don't find any new facts, we need to delete the existing ones + // since these may be the end product of a filter process + apiErr = h.deleteExistingFactsBySource(apiClient, environment, source, project) + if apiErr != nil { + log.Printf("%s", apiErr.Error()) + } + for _, r := range result { if fact, ok := r.(LagoonFact); ok { // Handle single fact @@ -347,31 +359,16 @@ func processResultset(result []interface{}, err error, h *Messaging, apiClient g } func (h *Messaging) sendFactsToLagoonAPI(facts []LagoonFact, apiClient graphql.Client, resource ResourceDestination, source string) error { - project, environment, apiErr := determineResourceFromLagoonAPI(apiClient, resource) - if apiErr != nil { - return apiErr - } - //if EnableDebug { - // log.Printf("Matched %d number of fact(s) for '%v:%v', from source '%s'", len(facts), project.Name, environment, source) - //} slog.Debug("Matched facts", "Number", len(facts), - "ProjectName", project.Name, - "EnvironmentId", environment.Id, - "EnvironmentName", environment.Name, + "ProjectName", resource.Project, + "EnvironmentId", resource.Environment, "Source", source, ) - // Even if we don't find any new facts, we need to delete the existing ones - // since these may be the end product of a filter process - apiErr = h.deleteExistingFactsBySource(apiClient, environment, source, project) - if apiErr != nil { - return fmt.Errorf("%s", apiErr.Error()) - } - if len(facts) > 0 { - apiErr = h.pushFactsToLagoonApi(facts, resource) + apiErr := h.pushFactsToLagoonApi(facts, resource) if apiErr != nil { return fmt.Errorf("%s", apiErr.Error()) } diff --git a/internal/handler/registerFilters.go b/internal/handler/registerFilters.go index 2cc9e98..73bf714 100644 --- a/internal/handler/registerFilters.go +++ b/internal/handler/registerFilters.go @@ -19,7 +19,7 @@ type FactTransformNameValue struct { type FactLookupNameValue struct { Name string `json:"name"` Value string `json:"value"` - ExactMatch bool `json:"exactMatch"` + ExactMatch bool `json:"exactMatch" yaml:"exactMatch"` } type FactTransform struct {