From 8f594e876470fa72c6fb0389e8f89fabcde9e017 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 27 Apr 2020 16:50:25 -0400 Subject: [PATCH] add support for custom multiline redactors, add yaml redactors to spec --- .../troubleshoot/v1beta1/redact_shared.go | 19 +++++++++----- .../v1beta1/zz_generated.deepcopy.go | 25 +++++++++++++++++++ pkg/redact/redact.go | 10 +++++++- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta1/redact_shared.go b/pkg/apis/troubleshoot/v1beta1/redact_shared.go index d6937b8b..fe48c059 100644 --- a/pkg/apis/troubleshoot/v1beta1/redact_shared.go +++ b/pkg/apis/troubleshoot/v1beta1/redact_shared.go @@ -1,9 +1,16 @@ package v1beta1 -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"` - Values []string `json:"values,omitempty" yaml:"values,omitempty"` - Regex []string `json:"regex,omitempty" yaml:"regex,omitempty"` +type MultiLine struct { + Selector string `json:"selector,omitempty" yaml:"selector,omitempty"` + 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"` + 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"` } diff --git a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go index 95e8c460..6b41a37e 100644 --- a/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go @@ -915,6 +915,21 @@ 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 @@ -1165,6 +1180,16 @@ func (in *Redact) DeepCopyInto(out *Redact) { *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 Redact. diff --git a/pkg/redact/redact.go b/pkg/redact/redact.go index 16a5df59..9c85a6d2 100644 --- a/pkg/redact/redact.go +++ b/pkg/redact/redact.go @@ -65,7 +65,7 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact for _, re := range redact.Regex { r, err := NewSingleLineRedactor(re, MASK_TEXT) if err != nil { - return nil, err // maybe skip broken ones? + return nil, errors.Wrapf(err, "redactor %q", re) } additionalRedactors = append(additionalRedactors, r) } @@ -73,6 +73,14 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact for _, literal := range redact.Values { additionalRedactors = append(additionalRedactors, literalString(literal)) } + + for _, re := range redact.MultiLine { + r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT) + if err != nil { + return nil, errors.Wrapf(err, "multiline redactor %+v", re) + } + additionalRedactors = append(additionalRedactors, r) + } } return additionalRedactors, nil }