Skip to content

Commit 89b4979

Browse files
authored
Merge pull request #216 from replicatedhq/laverya/redactor-reformat
redactor reformat
2 parents d98172e + 6e87448 commit 89b4979

File tree

6 files changed

+210
-138
lines changed

6 files changed

+210
-138
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package v1beta1
22

3-
type MultiLine struct {
3+
type Regex struct {
44
Selector string `json:"selector,omitempty" yaml:"selector,omitempty"`
55
Redactor string `json:"redactor,omitempty" yaml:"redactor,omitempty"`
66
}
77

8+
type FileSelector struct {
9+
File string `json:"file,omitempty" yaml:"file,omitempty"`
10+
Files []string `json:"files,omitempty" yaml:"files,omitempty"`
11+
}
12+
13+
type Removals struct {
14+
Values []string `json:"values,omitempty" yaml:"values,omitempty"`
15+
Regex []Regex `json:"regex,omitempty" yaml:"regex,omitempty"`
16+
YamlPath []string `json:"yamlPath,omitempty" yaml:"yamlPath,omitempty"`
17+
}
18+
819
type Redact struct {
9-
Name string `json:"name,omitempty" yaml:"name,omitempty"`
10-
File string `json:"file,omitempty" yaml:"file,omitempty"`
11-
Files []string `json:"files,omitempty" yaml:"files,omitempty"`
12-
Values []string `json:"values,omitempty" yaml:"values,omitempty"`
13-
Regex []string `json:"regex,omitempty" yaml:"regex,omitempty"`
14-
MultiLine []MultiLine `json:"multiLine,omitempty" yaml:"multiLine,omitempty"`
15-
Yaml []string `json:"yaml,omitempty" yaml:"yaml,omitempty"`
20+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
21+
FileSelector FileSelector `json:"fileSelector,omitempty" yaml:"fileSelector,omitempty"`
22+
Removals Removals `json:"removals,omitempty" yaml:"removals,omitempty"`
1623
}

pkg/apis/troubleshoot/v1beta1/zz_generated.deepcopy.go

Lines changed: 67 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/collect/collector_test.go

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ pwd=somethinggoeshere;`,
3232
},
3333
Redactors: []*troubleshootv1beta1.Redact{
3434
{
35-
Name: "",
36-
File: "",
37-
Files: nil,
38-
Values: nil,
39-
Regex: []string{
40-
`abc`,
41-
`(another)(?P<mask>.*)(here)`,
35+
Name: "",
36+
Removals: troubleshootv1beta1.Removals{
37+
Values: nil,
38+
Regex: []troubleshootv1beta1.Regex{
39+
{Redactor: `abc`},
40+
{Redactor: `(another)(?P<mask>.*)(here)`},
41+
},
4242
},
4343
},
4444
},
@@ -65,11 +65,15 @@ pwd=somethinggoeshere;`,
6565
},
6666
Redactors: []*troubleshootv1beta1.Redact{
6767
{
68-
Name: "",
69-
File: "data/*",
70-
Values: nil,
71-
Regex: []string{
72-
`(another)(?P<mask>.*)(here)`,
68+
Name: "",
69+
FileSelector: troubleshootv1beta1.FileSelector{
70+
File: "data/*",
71+
},
72+
Removals: troubleshootv1beta1.Removals{
73+
Values: nil,
74+
Regex: []troubleshootv1beta1.Regex{
75+
{Redactor: `(another)(?P<mask>.*)(here)`},
76+
},
7377
},
7478
},
7579
},
@@ -96,11 +100,15 @@ pwd=somethinggoeshere;`,
96100
},
97101
Redactors: []*troubleshootv1beta1.Redact{
98102
{
99-
Name: "",
100-
File: "notdata/*",
101-
Values: nil,
102-
Regex: []string{
103-
`(another)(?P<mask>.*)(here)`,
103+
Name: "",
104+
FileSelector: troubleshootv1beta1.FileSelector{
105+
File: "notdata/*",
106+
},
107+
Removals: troubleshootv1beta1.Removals{
108+
Values: nil,
109+
Regex: []troubleshootv1beta1.Regex{
110+
{Redactor: `(another)(?P<mask>.*)(here)`},
111+
},
104112
},
105113
},
106114
},
@@ -128,13 +136,17 @@ pwd=somethinggoeshere;`,
128136
Redactors: []*troubleshootv1beta1.Redact{
129137
{
130138
Name: "",
131-
Files: []string{
132-
"notData/*",
133-
"data/*",
139+
FileSelector: troubleshootv1beta1.FileSelector{
140+
Files: []string{
141+
"notData/*",
142+
"data/*",
143+
},
134144
},
135-
Values: nil,
136-
Regex: []string{
137-
`(another)(?P<mask>.*)(here)`,
145+
Removals: troubleshootv1beta1.Removals{
146+
Values: nil,
147+
Regex: []troubleshootv1beta1.Regex{
148+
{Redactor: `(another)(?P<mask>.*)(here)`},
149+
},
138150
},
139151
},
140152
},
@@ -162,13 +174,17 @@ pwd=somethinggoeshere;`,
162174
Redactors: []*troubleshootv1beta1.Redact{
163175
{
164176
Name: "",
165-
Files: []string{
166-
"data/*/*",
177+
FileSelector: troubleshootv1beta1.FileSelector{
178+
Files: []string{
179+
"data/*/*",
180+
},
167181
},
168-
Values: []string{
169-
`abc`,
170-
`123`,
171-
`another`,
182+
Removals: troubleshootv1beta1.Removals{
183+
Values: []string{
184+
`abc`,
185+
`123`,
186+
`another`,
187+
},
172188
},
173189
},
174190
},
@@ -194,8 +210,10 @@ another line here`,
194210
},
195211
Redactors: []*troubleshootv1beta1.Redact{
196212
{
197-
Yaml: []string{
198-
`abc`,
213+
Removals: troubleshootv1beta1.Removals{
214+
YamlPath: []string{
215+
`abc`,
216+
},
199217
},
200218
},
201219
},
@@ -223,10 +241,12 @@ abc`,
223241
},
224242
Redactors: []*troubleshootv1beta1.Redact{
225243
{
226-
MultiLine: []troubleshootv1beta1.MultiLine{
227-
{
228-
Selector: "abc",
229-
Redactor: "xyz(123)",
244+
Removals: troubleshootv1beta1.Removals{
245+
Regex: []troubleshootv1beta1.Regex{
246+
{
247+
Selector: "abc",
248+
Redactor: "xyz(123)",
249+
},
230250
},
231251
},
232252
},
@@ -287,13 +307,13 @@ pwd=somethinggoeshere;`,
287307
},
288308
Redactors: []*troubleshootv1beta1.Redact{
289309
{
290-
Name: "",
291-
File: "",
292-
Files: nil,
293-
Values: nil,
294-
Regex: []string{
295-
`abc`,
296-
`(another)(?P<mask>.*)(here)`,
310+
Name: "",
311+
Removals: troubleshootv1beta1.Removals{
312+
Values: nil,
313+
Regex: []troubleshootv1beta1.Regex{
314+
{Redactor: `abc`},
315+
{Redactor: `(another)(?P<mask>.*)(here)`},
316+
},
297317
},
298318
},
299319
},

pkg/redact/redact.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,27 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
104104
continue
105105
}
106106

107-
for j, re := range redact.Regex {
108-
r, err := NewSingleLineRedactor(re, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false)
109-
if err != nil {
110-
return nil, errors.Wrapf(err, "redactor %q", re)
111-
}
112-
additionalRedactors = append(additionalRedactors, r)
113-
}
114-
115-
for j, literal := range redact.Values {
107+
for j, literal := range redact.Removals.Values {
116108
additionalRedactors = append(additionalRedactors, literalString(literal, path, redactorName(i, j, redact.Name, "literal")))
117109
}
118110

119-
for j, re := range redact.MultiLine {
120-
r, err := NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false)
121-
if err != nil {
122-
return nil, errors.Wrapf(err, "multiline redactor %+v", re)
111+
for j, re := range redact.Removals.Regex {
112+
var newRedactor Redactor
113+
if re.Selector != "" {
114+
newRedactor, err = NewMultiLineRedactor(re.Selector, re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "multiLine"), false)
115+
if err != nil {
116+
return nil, errors.Wrapf(err, "multiline redactor %+v", re)
117+
}
118+
} else {
119+
newRedactor, err = NewSingleLineRedactor(re.Redactor, MASK_TEXT, path, redactorName(i, j, redact.Name, "regex"), false)
120+
if err != nil {
121+
return nil, errors.Wrapf(err, "redactor %q", re)
122+
}
123123
}
124-
additionalRedactors = append(additionalRedactors, r)
124+
additionalRedactors = append(additionalRedactors, newRedactor)
125125
}
126126

127-
for j, yaml := range redact.Yaml {
127+
for j, yaml := range redact.Removals.YamlPath {
128128
r := NewYamlRedactor(yaml, path, redactorName(i, j, redact.Name, "yaml"))
129129
additionalRedactors = append(additionalRedactors, r)
130130
}
@@ -133,21 +133,21 @@ func buildAdditionalRedactors(path string, redacts []*troubleshootv1beta1.Redact
133133
}
134134

135135
func redactMatchesPath(path string, redact *troubleshootv1beta1.Redact) (bool, error) {
136-
if redact.File == "" && len(redact.Files) == 0 {
136+
if redact.FileSelector.File == "" && len(redact.FileSelector.Files) == 0 {
137137
return true, nil
138138
}
139139

140140
globs := []glob.Glob{}
141141

142-
if redact.File != "" {
143-
newGlob, err := glob.Compile(redact.File, '/')
142+
if redact.FileSelector.File != "" {
143+
newGlob, err := glob.Compile(redact.FileSelector.File, '/')
144144
if err != nil {
145-
return false, errors.Wrapf(err, "invalid file glob string %q", redact.File)
145+
return false, errors.Wrapf(err, "invalid file glob string %q", redact.FileSelector.File)
146146
}
147147
globs = append(globs, newGlob)
148148
}
149149

150-
for i, fileGlobString := range redact.Files {
150+
for i, fileGlobString := range redact.FileSelector.Files {
151151
newGlob, err := glob.Compile(fileGlobString, '/')
152152
if err != nil {
153153
return false, errors.Wrapf(err, "invalid file glob string %d %q", i, fileGlobString)

0 commit comments

Comments
 (0)