Skip to content

Commit

Permalink
remove managedFields metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lbi22 committed Oct 22, 2024
1 parent 5a2ad10 commit 6f73991
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func createElasticsearchClient(endpoint, username, password string) (*elasticsea
return es, nil
}


// Function to process and remove metadata.managedFields
func cleanMetadata(report map[string]interface{}) {
if _, exists := report["metadata"].(map[string]interface{})["managedFields"]; exists {
delete(report["metadata"].(map[string]interface{}), "managedFields")
}
}


// Remove invalid fields with only dots (".") from the report recursively
func removeInvalidFields(data interface{}) {
switch v := data.(type) {
Expand Down Expand Up @@ -117,6 +126,8 @@ func handleTrivyReport(w http.ResponseWriter, r *http.Request, es *elasticsearch
return
}

cleanMetadata(operatorObject)

// Example of using the fields in handleVulnerabilityReport
for field, value := range fieldsToPush {
log.Printf("Processing field: %s with value: %v", field, value)
Expand Down Expand Up @@ -154,6 +165,8 @@ func handleTrivyReport(w http.ResponseWriter, r *http.Request, es *elasticsearch
}

func handleVulnerabilityReport(w http.ResponseWriter, report map[string]interface{}, es *elasticsearch.Client, verb string) {


// Extract metadata
metadata, ok := report["metadata"].(map[string]interface{})
if !ok {
Expand Down

0 comments on commit 6f73991

Please sign in to comment.