Skip to content

Commit

Permalink
Merge pull request #291 from flanksource/fix/empty-config-change-summary
Browse files Browse the repository at this point in the history
fix: config change summary from patch
  • Loading branch information
moshloop authored Aug 3, 2023
2 parents c8dddb6 + 3899549 commit 29d15a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/aws/smithy-go/ptr"
Expand Down Expand Up @@ -316,13 +317,19 @@ func generateConfigChange(newConf, prev models.ConfigItem) (*dutyModels.ConfigCh
return nil, fmt.Errorf("failed to create merge patch: %w", err)
}

var patchJSON map[string]any
if err := json.Unmarshal(patch, &patchJSON); err != nil {
return nil, fmt.Errorf("failed to unmarshal patch: %w", err)
}

return &dutyModels.ConfigChange{
ConfigID: newConf.ID,
ChangeType: "diff",
ExternalChangeId: utils.Sha256Hex(string(patch)),
ID: ulid.MustNew().AsUUID(),
Diff: diff,
Patches: string(patch),
Summary: strings.Join(utils.ExtractLeafNodesAndCommonParents(patchJSON), ", "),
}, nil
}

Expand Down
10 changes: 8 additions & 2 deletions scrapers/runscrapers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ func summarizeChanges(changes []v1.ChangeResult) []v1.ChangeResult {
continue
}

paths := utils.ExtractLeafNodesAndCommonParents(change.AsMap())
var patch map[string]any
if err := json.Unmarshal([]byte(change.Patches), &patch); err != nil {
logger.Errorf("failed to unmarshal patches as map[string]any: %v %v", change.Patches, err)
continue
}

paths := utils.ExtractLeafNodesAndCommonParents(patch)
if len(paths) == 0 {
continue
}

changes[i].Summary += strings.Join(paths, ",")
changes[i].Summary += strings.Join(paths, ", ")
}

return changes
Expand Down

0 comments on commit 29d15a5

Please sign in to comment.