Skip to content

Commit b1e1dbb

Browse files
authored
Merge pull request #178 from replicatedhq/laverya/support-multidoc-collector-and-redactor-input
allow providing redactors as multidoc yaml after collectors
2 parents eb84fc6 + a58913d commit b1e1dbb

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

cmd/troubleshoot/cli/run.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
4747
return errors.Wrap(err, "failed to load collector spec")
4848
}
4949

50+
multidocs := strings.Split(string(collectorContent), "---")
51+
5052
troubleshootclientsetscheme.AddToScheme(scheme.Scheme)
5153
decode := scheme.Codecs.UniversalDeserializer().Decode
52-
obj, _, err := decode([]byte(collectorContent), nil, nil)
54+
obj, _, err := decode([]byte(multidocs[0]), nil, nil)
5355
if err != nil {
5456
return errors.Wrapf(err, "failed to parse %s", arg)
5557
}
5658

5759
collector := obj.(*troubleshootv1beta1.Collector)
5860

59-
var additionalRedactors *troubleshootv1beta1.Redactor
61+
additionalRedactors := &troubleshootv1beta1.Redactor{}
6062
if v.GetString("redactors") != "" {
6163
redactorContent, err := loadSpec(v, v.GetString("redactors"))
6264
if err != nil {
@@ -73,6 +75,18 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
7375
}
7476
}
7577

78+
for i, additionalDoc := range multidocs[1:] {
79+
obj, _, err := decode([]byte(additionalDoc), nil, nil)
80+
if err != nil {
81+
return errors.Wrapf(err, "failed to parse additional doc %d", i)
82+
}
83+
multidocRedactors, ok := obj.(*troubleshootv1beta1.Redactor)
84+
if !ok {
85+
continue
86+
}
87+
additionalRedactors.Spec.Redactors = append(additionalRedactors.Spec.Redactors, multidocRedactors.Spec.Redactors...)
88+
}
89+
7690
s := spin.New()
7791
finishedCh := make(chan bool, 1)
7892
progressChan := make(chan interface{}, 0) // non-zero buffer can result in missed messages

sample-redactors.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

sample-troubleshoot.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ spec:
1818
data: |
1919
my super secret password is abc123
2020
another redaction will go here
21+
---
22+
apiVersion: troubleshoot.replicated.com/v1beta1
23+
kind: Redactor
24+
metadata:
25+
name: my-application-name
26+
spec:
27+
redactors:
28+
- name: replace password # names are not used internally, but are useful for recordkeeping
29+
file: data/my-password-dump # this targets a single file
30+
values:
31+
- abc123 # this is a very good password, and I don't want it to be exposed
32+
- name: all files # as no file is specified, this redactor will run against all files
33+
regex:
34+
- (another)(?P<mask>.*)(here) # this will replace anything between the strings `another` and `here` with `***HIDDEN***`

0 commit comments

Comments
 (0)