Skip to content

Commit

Permalink
Merge pull request #353 from flanksource/feat/custom-properties
Browse files Browse the repository at this point in the history
feat: transform properties
  • Loading branch information
moshloop authored Jan 11, 2024
2 parents 965f33e + 0dc84a7 commit c0e81df
Show file tree
Hide file tree
Showing 24 changed files with 935 additions and 140 deletions.
10 changes: 8 additions & 2 deletions api/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,14 @@ type BaseScraper struct {

// DeleteFields is a JSONPath expression used to identify the deleted time of the config.
// If multiple fields are specified, the first non-empty value will be used.
DeleteFields []string `json:"deleteFields,omitempty"`
Tags JSONStringMap `json:"tags,omitempty"`
DeleteFields []string `json:"deleteFields,omitempty"`

// Tags allow you to set custom tags on the scraped config items.
Tags JSONStringMap `json:"tags,omitempty"`

// Properties are custom templatable properties for the scraped config items
// grouped by the config type.
Properties map[string]types.Properties `json:"properties,omitempty" template:"true"`
}

func (base BaseScraper) String() string {
Expand Down
18 changes: 18 additions & 0 deletions api/v1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
)

// Analyzer ...
Expand Down Expand Up @@ -230,6 +231,23 @@ type ScrapeResult struct {
Action string `json:",omitempty"`
ParentExternalID string `json:"-"`
ParentType string `json:"-"`
Properties types.Properties `json:"properties,omitempty"`
}

func (s ScrapeResult) AsMap() map[string]any {
output := make(map[string]any)

b, err := json.Marshal(s)
if err != nil {
logger.Errorf("failed to marshal change result: %v", err)
return output
}

if err := json.Unmarshal(b, &output); err != nil {
logger.Errorf("failed to unmarshal change result: %v", err)
}

return output
}

func NewScrapeResult(base BaseScraper) *ScrapeResult {
Expand Down
42 changes: 42 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0e81df

Please sign in to comment.