From a56125475647215f01cec2e93579d3fe6192fdb9 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Tue, 9 Jun 2020 18:43:44 -0400 Subject: [PATCH 1/3] break apart redactor type --- .../troubleshoot/v1beta1/redact_shared.go | 16 ++- .../v1beta1/zz_generated.deepcopy.go | 82 +++++++++----- pkg/collect/collector_test.go | 104 +++++++++++------- pkg/redact/redact.go | 18 +-- pkg/redact/redact_test.go | 52 ++++++--- 5 files changed, 174 insertions(+), 98 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta1/redact_shared.go b/pkg/apis/troubleshoot/v1beta1/redact_shared.go index fe48c0597..f134a7b27 100644 --- a/pkg/apis/troubleshoot/v1beta1/redact_shared.go +++ b/pkg/apis/troubleshoot/v1beta1/redact_shared.go @@ -5,12 +5,20 @@ type MultiLine struct { Redactor string `json:"redactor,omitempty" yaml:"redactor,omitempty"` } -type Redact struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` - File string `json:"file,omitempty" yaml:"file,omitempty"` - Files []string `json:"files,omitempty" yaml:"files,omitempty"` +type FileSelector struct { + File string `json:"file,omitempty" yaml:"file,omitempty"` + Files []string `json:"files,omitempty" yaml:"files,omitempty"` +} + +type Removals struct { Values []string `json:"values,omitempty" yaml:"values,omitempty"` Regex []string `json:"regex,omitempty" yaml:"regex,omitempty"` MultiLine []MultiLine `json:"multiLine,omitempty" yaml:"multiLine,omitempty"` Yaml []string `json:"yaml,omitempty" yaml:"yaml,omitempty"` } + +type Redact struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + FileSelector FileSelector `json:"fileSelector,omitempty" yaml:"fileSelector,omitempty"` + Removals Removals `json:"removals,omitempty" yaml:"removals,omitempty"` +} diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 6b41a37ea..579d02450 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -762,6 +762,26 @@ func (in *Exec) DeepCopy() *Exec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FileSelector) DeepCopyInto(out *FileSelector) { + *out = *in + if in.Files != nil { + in, out := &in.Files, &out.Files + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileSelector. +func (in *FileSelector) DeepCopy() *FileSelector { + if in == nil { + return nil + } + out := new(FileSelector) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Get) DeepCopyInto(out *Get) { *out = *in @@ -1165,31 +1185,8 @@ func (in *Put) DeepCopy() *Put { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Redact) DeepCopyInto(out *Redact) { *out = *in - if in.Files != nil { - in, out := &in.Files, &out.Files - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Values != nil { - in, out := &in.Values, &out.Values - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.Regex != nil { - in, out := &in.Regex, &out.Regex - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.MultiLine != nil { - in, out := &in.MultiLine, &out.MultiLine - *out = make([]MultiLine, len(*in)) - copy(*out, *in) - } - if in.Yaml != nil { - in, out := &in.Yaml, &out.Yaml - *out = make([]string, len(*in)) - copy(*out, *in) - } + in.FileSelector.DeepCopyInto(&out.FileSelector) + in.Removals.DeepCopyInto(&out.Removals) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Redact. @@ -1302,6 +1299,41 @@ func (in *RedactorStatus) DeepCopy() *RedactorStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Removals) DeepCopyInto(out *Removals) { + *out = *in + if in.Values != nil { + in, out := &in.Values, &out.Values + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Regex != nil { + in, out := &in.Regex, &out.Regex + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.MultiLine != nil { + in, out := &in.MultiLine, &out.MultiLine + *out = make([]MultiLine, len(*in)) + copy(*out, *in) + } + if in.Yaml != nil { + in, out := &in.Yaml, &out.Yaml + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Removals. +func (in *Removals) DeepCopy() *Removals { + if in == nil { + return nil + } + out := new(Removals) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ResultRequest) DeepCopyInto(out *ResultRequest) { *out = *in diff --git a/pkg/collect/collector_test.go b/pkg/collect/collector_test.go index 9142336a9..275953f86 100644 --- a/pkg/collect/collector_test.go +++ b/pkg/collect/collector_test.go @@ -32,13 +32,13 @@ pwd=somethinggoeshere;`, }, Redactors: []*troubleshootv1beta1.Redact{ { - Name: "", - File: "", - Files: nil, - Values: nil, - Regex: []string{ - `abc`, - `(another)(?P.*)(here)`, + Name: "", + Removals: troubleshootv1beta1.Removals{ + Values: nil, + Regex: []string{ + `abc`, + `(another)(?P.*)(here)`, + }, }, }, }, @@ -65,11 +65,15 @@ pwd=somethinggoeshere;`, }, Redactors: []*troubleshootv1beta1.Redact{ { - Name: "", - File: "data/*", - Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Name: "", + FileSelector: troubleshootv1beta1.FileSelector{ + File: "data/*", + }, + Removals: troubleshootv1beta1.Removals{ + Values: nil, + Regex: []string{ + `(another)(?P.*)(here)`, + }, }, }, }, @@ -96,11 +100,15 @@ pwd=somethinggoeshere;`, }, Redactors: []*troubleshootv1beta1.Redact{ { - Name: "", - File: "notdata/*", - Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Name: "", + FileSelector: troubleshootv1beta1.FileSelector{ + File: "notdata/*", + }, + Removals: troubleshootv1beta1.Removals{ + Values: nil, + Regex: []string{ + `(another)(?P.*)(here)`, + }, }, }, }, @@ -128,13 +136,17 @@ pwd=somethinggoeshere;`, Redactors: []*troubleshootv1beta1.Redact{ { Name: "", - Files: []string{ - "notData/*", - "data/*", + FileSelector: troubleshootv1beta1.FileSelector{ + Files: []string{ + "notData/*", + "data/*", + }, }, - Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Removals: troubleshootv1beta1.Removals{ + Values: nil, + Regex: []string{ + `(another)(?P.*)(here)`, + }, }, }, }, @@ -162,13 +174,17 @@ pwd=somethinggoeshere;`, Redactors: []*troubleshootv1beta1.Redact{ { Name: "", - Files: []string{ - "data/*/*", + FileSelector: troubleshootv1beta1.FileSelector{ + Files: []string{ + "data/*/*", + }, }, - Values: []string{ - `abc`, - `123`, - `another`, + Removals: troubleshootv1beta1.Removals{ + Values: []string{ + `abc`, + `123`, + `another`, + }, }, }, }, @@ -194,8 +210,10 @@ another line here`, }, Redactors: []*troubleshootv1beta1.Redact{ { - Yaml: []string{ - `abc`, + Removals: troubleshootv1beta1.Removals{ + Yaml: []string{ + `abc`, + }, }, }, }, @@ -223,10 +241,12 @@ abc`, }, Redactors: []*troubleshootv1beta1.Redact{ { - MultiLine: []troubleshootv1beta1.MultiLine{ - { - Selector: "abc", - Redactor: "xyz(123)", + Removals: troubleshootv1beta1.Removals{ + MultiLine: []troubleshootv1beta1.MultiLine{ + { + Selector: "abc", + Redactor: "xyz(123)", + }, }, }, }, @@ -287,13 +307,13 @@ pwd=somethinggoeshere;`, }, Redactors: []*troubleshootv1beta1.Redact{ { - Name: "", - File: "", - Files: nil, - Values: nil, - Regex: []string{ - `abc`, - `(another)(?P.*)(here)`, + Name: "", + Removals: troubleshootv1beta1.Removals{ + Values: nil, + Regex: []string{ + `abc`, + `(another)(?P.*)(here)`, + }, }, }, }, diff --git a/pkg/redact/redact.go b/pkg/redact/redact.go index dd008a213..2378f12bf 100644 --- a/pkg/redact/redact.go +++ b/pkg/redact/redact.go @@ -104,7 +104,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact continue } - for j, re := range redact.Regex { + for j, re := range redact.Removals.Regex { r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false) if err != nil { return nil, errors.Wrapf(err, "redactor %q", re) @@ -112,11 +112,11 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact additionalRedactors = append(additionalRedactors, r) } - for j, literal := range redact.Values { + for j, literal := range redact.Removals.Values { additionalRedactors = append(additionalRedactors, literalString(literal, path, redactorName(i, j, redact.Name, "literal"))) } - for j, re := range redact.MultiLine { + for j, re := range redact.Removals.MultiLine { r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false) if err != nil { return nil, errors.Wrapf(err, "multiline redactor %+v", re) @@ -124,7 +124,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact additionalRedactors = append(additionalRedactors, r) } - for j, yaml := range redact.Yaml { + for j, yaml := range redact.Removals.Yaml { r := NewYamlRedactor(yaml, path, redactorName(i, j, redact.Name, "yaml")) additionalRedactors = append(additionalRedactors, r) } @@ -133,21 +133,21 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact } func redactMatchesPath(path string, redact *troubleshootv1beta1.Redact) (bool, error) { - if redact.File == "" && len(redact.Files) == 0 { + if redact.FileSelector.File == "" && len(redact.FileSelector.Files) == 0 { return true, nil } globs := []glob.Glob{} - if redact.File != "" { - newGlob, err := glob.Compile(redact.File, '/') + if redact.FileSelector.File != "" { + newGlob, err := glob.Compile(redact.FileSelector.File, '/') if err != nil { - return false, errors.Wrapf(err, "invalid file glob string %q", redact.File) + return false, errors.Wrapf(err, "invalid file glob string %q", redact.FileSelector.File) } globs = append(globs, newGlob) } - for i, fileGlobString := range redact.Files { + for i, fileGlobString := range redact.FileSelector.Files { newGlob, err := glob.Compile(fileGlobString, '/') if err != nil { return false, errors.Wrapf(err, "invalid file glob string %d %q", i, fileGlobString) diff --git a/pkg/redact/redact_test.go b/pkg/redact/redact_test.go index 1f937ba9e..415926c33 100644 --- a/pkg/redact/redact_test.go +++ b/pkg/redact/redact_test.go @@ -1662,8 +1662,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/path", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/path", + Files: nil, + }, }, }, want: true, @@ -1673,8 +1675,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path", redact: &troubleshootv1beta1.Redact{ - File: "", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "", + Files: nil, + }, }, }, want: true, @@ -1684,8 +1688,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/path/two", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/path/two", + Files: nil, + }, }, }, want: false, @@ -1695,8 +1701,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path/two", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/path/*", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/path/*", + Files: nil, + }, }, }, want: true, @@ -1706,8 +1714,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path/two", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/*/*", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/*/*", + Files: nil, + }, }, }, want: true, @@ -1717,10 +1727,12 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path/two", redact: &troubleshootv1beta1.Redact{ - File: "", - Files: []string{ - "/not/the/path", - "/my/test/*/*", + FileSelector: troubleshootv1beta1.FileSelector{ + File: "", + Files: []string{ + "/not/the/path", + "/my/test/*/*", + }, }, }, }, @@ -1731,8 +1743,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path/two", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/**", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/**", + Files: nil, + }, }, }, want: true, @@ -1742,8 +1756,10 @@ func Test_redactMatchesPath(t *testing.T) { args: args{ path: "/my/test/path/two", redact: &troubleshootv1beta1.Redact{ - File: "/my/test/*", - Files: nil, + FileSelector: troubleshootv1beta1.FileSelector{ + File: "/my/test/*", + Files: nil, + }, }, }, want: false, From e66d12dab242cdebf8c3d6ab8b63038dd056ec69 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Thu, 11 Jun 2020 16:16:47 -0400 Subject: [PATCH 2/3] combine multiline and single line regex --- .../troubleshoot/v1beta1/redact_shared.go | 9 ++--- .../v1beta1/zz_generated.deepcopy.go | 37 ++++++++----------- pkg/collect/collector_test.go | 26 ++++++------- pkg/redact/redact.go | 26 ++++++------- 4 files changed, 46 insertions(+), 52 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta1/redact_shared.go b/pkg/apis/troubleshoot/v1beta1/redact_shared.go index f134a7b27..53008f223 100644 --- a/pkg/apis/troubleshoot/v1beta1/redact_shared.go +++ b/pkg/apis/troubleshoot/v1beta1/redact_shared.go @@ -1,6 +1,6 @@ package v1beta1 -type MultiLine struct { +type Regex struct { Selector string `json:"selector,omitempty" yaml:"selector,omitempty"` Redactor string `json:"redactor,omitempty" yaml:"redactor,omitempty"` } @@ -11,10 +11,9 @@ type FileSelector struct { } type Removals struct { - Values []string `json:"values,omitempty" yaml:"values,omitempty"` - Regex []string `json:"regex,omitempty" yaml:"regex,omitempty"` - MultiLine []MultiLine `json:"multiLine,omitempty" yaml:"multiLine,omitempty"` - Yaml []string `json:"yaml,omitempty" yaml:"yaml,omitempty"` + Values []string `json:"values,omitempty" yaml:"values,omitempty"` + Regex []Regex `json:"regex,omitempty" yaml:"regex,omitempty"` + Yaml []string `json:"yaml,omitempty" yaml:"yaml,omitempty"` } type Redact struct { diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 579d02450..10cacfc5d 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -935,21 +935,6 @@ func (in *Logs) DeepCopy() *Logs { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MultiLine) DeepCopyInto(out *MultiLine) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiLine. -func (in *MultiLine) DeepCopy() *MultiLine { - if in == nil { - return nil - } - out := new(MultiLine) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeResourceFilters) DeepCopyInto(out *NodeResourceFilters) { *out = *in @@ -1299,6 +1284,21 @@ func (in *RedactorStatus) DeepCopy() *RedactorStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Regex) DeepCopyInto(out *Regex) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Regex. +func (in *Regex) DeepCopy() *Regex { + if in == nil { + return nil + } + out := new(Regex) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Removals) DeepCopyInto(out *Removals) { *out = *in @@ -1309,12 +1309,7 @@ func (in *Removals) DeepCopyInto(out *Removals) { } if in.Regex != nil { in, out := &in.Regex, &out.Regex - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.MultiLine != nil { - in, out := &in.MultiLine, &out.MultiLine - *out = make([]MultiLine, len(*in)) + *out = make([]Regex, len(*in)) copy(*out, *in) } if in.Yaml != nil { diff --git a/pkg/collect/collector_test.go b/pkg/collect/collector_test.go index 275953f86..9e0346be0 100644 --- a/pkg/collect/collector_test.go +++ b/pkg/collect/collector_test.go @@ -35,9 +35,9 @@ pwd=somethinggoeshere;`, Name: "", Removals: troubleshootv1beta1.Removals{ Values: nil, - Regex: []string{ - `abc`, - `(another)(?P.*)(here)`, + Regex: []troubleshootv1beta1.Regex{ + {Redactor: `abc`}, + {Redactor: `(another)(?P.*)(here)`}, }, }, }, @@ -71,8 +71,8 @@ pwd=somethinggoeshere;`, }, Removals: troubleshootv1beta1.Removals{ Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Regex: []troubleshootv1beta1.Regex{ + {Redactor: `(another)(?P.*)(here)`}, }, }, }, @@ -106,8 +106,8 @@ pwd=somethinggoeshere;`, }, Removals: troubleshootv1beta1.Removals{ Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Regex: []troubleshootv1beta1.Regex{ + {Redactor: `(another)(?P.*)(here)`}, }, }, }, @@ -144,8 +144,8 @@ pwd=somethinggoeshere;`, }, Removals: troubleshootv1beta1.Removals{ Values: nil, - Regex: []string{ - `(another)(?P.*)(here)`, + Regex: []troubleshootv1beta1.Regex{ + {Redactor: `(another)(?P.*)(here)`}, }, }, }, @@ -242,7 +242,7 @@ abc`, Redactors: []*troubleshootv1beta1.Redact{ { Removals: troubleshootv1beta1.Removals{ - MultiLine: []troubleshootv1beta1.MultiLine{ + Regex: []troubleshootv1beta1.Regex{ { Selector: "abc", Redactor: "xyz(123)", @@ -310,9 +310,9 @@ pwd=somethinggoeshere;`, Name: "", Removals: troubleshootv1beta1.Removals{ Values: nil, - Regex: []string{ - `abc`, - `(another)(?P.*)(here)`, + Regex: []troubleshootv1beta1.Regex{ + {Redactor: `abc`}, + {Redactor: `(another)(?P.*)(here)`}, }, }, }, diff --git a/pkg/redact/redact.go b/pkg/redact/redact.go index 2378f12bf..cd881d584 100644 --- a/pkg/redact/redact.go +++ b/pkg/redact/redact.go @@ -104,24 +104,24 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact continue } - for j, re := range redact.Removals.Regex { - r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false) - if err != nil { - return nil, errors.Wrapf(err, "redactor %q", re) - } - additionalRedactors = append(additionalRedactors, r) - } - for j, literal := range redact.Removals.Values { additionalRedactors = append(additionalRedactors, literalString(literal, path, redactorName(i, j, redact.Name, "literal"))) } - for j, re := range redact.Removals.MultiLine { - r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false) - if err != nil { - return nil, errors.Wrapf(err, "multiline redactor %+v", re) + for j, re := range redact.Removals.Regex { + var newRedactor Redactor + if re.Selector != "" { + newRedactor, err = NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false) + if err != nil { + return nil, errors.Wrapf(err, "multiline redactor %+v", re) + } + } else { + newRedactor, err = NewSingleLineRedactor(re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false) + if err != nil { + return nil, errors.Wrapf(err, "redactor %q", re) + } } - additionalRedactors = append(additionalRedactors, r) + additionalRedactors = append(additionalRedactors, newRedactor) } for j, yaml := range redact.Removals.Yaml { From 6e874483b67a58853a483deecf95e02e7e3438cc Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 15 Jun 2020 13:55:07 -0400 Subject: [PATCH 3/3] update yaml key name, fixup example troubleshoot --- .../troubleshoot/v1beta1/redact_shared.go | 6 ++--- .../v1beta1/zz_generated.deepcopy.go | 4 ++-- pkg/collect/collector_test.go | 2 +- pkg/redact/redact.go | 2 +- sample-troubleshoot.yaml | 22 ++++++++++--------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta1/redact_shared.go b/pkg/apis/troubleshoot/v1beta1/redact_shared.go index 53008f223..edc0e1b73 100644 --- a/pkg/apis/troubleshoot/v1beta1/redact_shared.go +++ b/pkg/apis/troubleshoot/v1beta1/redact_shared.go @@ -11,9 +11,9 @@ type FileSelector struct { } type Removals struct { - Values []string `json:"values,omitempty" yaml:"values,omitempty"` - Regex []Regex `json:"regex,omitempty" yaml:"regex,omitempty"` - Yaml []string `json:"yaml,omitempty" yaml:"yaml,omitempty"` + Values []string `json:"values,omitempty" yaml:"values,omitempty"` + Regex []Regex `json:"regex,omitempty" yaml:"regex,omitempty"` + YamlPath []string `json:"yamlPath,omitempty" yaml:"yamlPath,omitempty"` } type Redact struct { diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 6b500b388..0a3e6a364 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -1312,8 +1312,8 @@ func (in *Removals) DeepCopyInto(out *Removals) { *out = make([]Regex, len(*in)) copy(*out, *in) } - if in.Yaml != nil { - in, out := &in.Yaml, &out.Yaml + if in.YamlPath != nil { + in, out := &in.YamlPath, &out.YamlPath *out = make([]string, len(*in)) copy(*out, *in) } diff --git a/pkg/collect/collector_test.go b/pkg/collect/collector_test.go index 9e0346be0..71d8f5926 100644 --- a/pkg/collect/collector_test.go +++ b/pkg/collect/collector_test.go @@ -211,7 +211,7 @@ another line here`, Redactors: []*troubleshootv1beta1.Redact{ { Removals: troubleshootv1beta1.Removals{ - Yaml: []string{ + YamlPath: []string{ `abc`, }, }, diff --git a/pkg/redact/redact.go b/pkg/redact/redact.go index cd881d584..e3b9106a3 100644 --- a/pkg/redact/redact.go +++ b/pkg/redact/redact.go @@ -124,7 +124,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact additionalRedactors = append(additionalRedactors, newRedactor) } - for j, yaml := range redact.Removals.Yaml { + for j, yaml := range redact.Removals.YamlPath { r := NewYamlRedactor(yaml, path, redactorName(i, j, redact.Name, "yaml")) additionalRedactors = append(additionalRedactors, r) } diff --git a/sample-troubleshoot.yaml b/sample-troubleshoot.yaml index dd155cfda..7724050dd 100644 --- a/sample-troubleshoot.yaml +++ b/sample-troubleshoot.yaml @@ -39,14 +39,16 @@ metadata: spec: redactors: - name: replace password # names are not used internally, but are useful for recordkeeping - file: data/my-password-dump # this targets a single file - values: - - abc123 # this is a very good password, and I don't want it to be exposed + fileSelector: + file: data/my-password-dump # this targets a single file + removals: + values: + - abc123 # this is a very good password, and I don't want it to be exposed - name: all files # as no file is specified, this redactor will run against all files - regex: - - (another)(?P.*)(here) # this will replace anything between the strings `another` and `here` with `***HIDDEN***` - multiLine: - - selector: 'S3_ENDPOINT' # remove the value in lines following those that contain the string S3_ENDPOINT - redactor: '("value": ").*(")' - yaml: - - "abc.xyz.*" # redact all items in the array at key xyz within key abc in yaml documents + removals: + regex: + - redactor: (another)(?P.*)(here) # this will replace anything between the strings `another` and `here` with `***HIDDEN***` + - selector: 'S3_ENDPOINT' # remove the value in lines following those that contain the string S3_ENDPOINT + redactor: '("value": ").*(")' + yamlPath: + - "abc.xyz.*" # redact all items in the array at key xyz within key abc in yaml documents