Skip to content

Commit

Permalink
feat: config field exclusion by types
Browse files Browse the repository at this point in the history
* fix: config class and type mapping and added tests
* feat: if config class is empty, use the type
  • Loading branch information
adityathebe authored and moshloop committed Jan 31, 2024
1 parent a0e238f commit c85e977
Show file tree
Hide file tree
Showing 34 changed files with 395 additions and 228 deletions.
38 changes: 26 additions & 12 deletions api/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import (
"github.com/flanksource/gomplate/v3"
)

type Filter struct {
JSONPath string `json:"jsonpath,omitempty"`
// ConfigFieldExclusion defines fields with JSONPath that needs to
// be removed from the config.
type ConfigFieldExclusion struct {
// Optionally specify the config types
// from which the JSONPath fields need to be removed.
// If left empty, all config types are considered.
Types []string `json:"types,omitempty"`

JSONPath string `json:"jsonpath"`
}

type Script struct {
Expand Down Expand Up @@ -89,20 +96,23 @@ type TransformChange struct {
Exclude []string `json:"exclude,omitempty"`
}

func (t *TransformChange) IsEmpty() bool {
return len(t.Exclude) == 0
}

type Transform struct {
Script Script `yaml:",inline" json:",inline"`
Include []Filter `json:"include,omitempty"`
Script Script `yaml:",inline" json:",inline"`
// Fields to remove from the config, useful for removing sensitive data and fields
// that change often without a material impact i.e. Last Scraped Time
Exclude []Filter `json:"exclude,omitempty"`
Exclude []ConfigFieldExclusion `json:"exclude,omitempty"`
// Masks consist of configurations to replace sensitive fields
// with hash functions or static string.
Masks MaskList `json:"mask,omitempty"`
Change TransformChange `json:"changes,omitempty"`
}

func (t Transform) IsEmpty() bool {
return t.Script.IsEmpty() && len(t.Include) == 0 && len(t.Exclude) == 0 && t.Masks.IsEmpty()
return t.Script.IsEmpty() && t.Change.IsEmpty() && len(t.Exclude) == 0 && t.Masks.IsEmpty()
}

func (t Transform) String() string {
Expand All @@ -112,16 +122,17 @@ func (t Transform) String() string {
}

if !t.Masks.IsEmpty() {
s += fmt.Sprintf("masks=%s", t.Masks)
}

if len(t.Include) > 0 {
s += fmt.Sprintf(" include=%s", t.Include)
s += fmt.Sprintf(" masks=%s", t.Masks)
}

if len(t.Exclude) > 0 {
s += fmt.Sprintf(" exclude=%s", t.Exclude)
}

if !t.Change.IsEmpty() {
s += fmt.Sprintf(" change=%s", t.Change)
}

return s
}

Expand All @@ -140,7 +151,10 @@ type BaseScraper struct {
// items are extracted first and then the ID,Name,Type and transformations are applied for each item.
Items string `json:"items,omitempty"`
// A static value or JSONPath expression to use as the type for the resource.
Type string `json:"type,omitempty"`
Type string `json:"type,omitempty"`
// A static value or JSONPath expression to use as the class for the resource.
Class string `json:"class,omitempty"`

Transform Transform `json:"transform,omitempty"`
// Format of config item, defaults to JSON, available options are JSON, properties
Format string `json:"format,omitempty"`
Expand Down
46 changes: 24 additions & 22 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 c85e977

Please sign in to comment.