From bf4c47051d55af8fbdcf4318ea55a69725544acd Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Thu, 6 Jan 2022 19:10:59 +0300 Subject: [PATCH] Comment out all lines in the generated example manifests Signed-off-by: Alper Rifat Ulucinar --- pkg/pipeline/example.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/pipeline/example.go b/pkg/pipeline/example.go index dc4dbf26..52788b75 100644 --- a/pkg/pipeline/example.go +++ b/pkg/pipeline/example.go @@ -114,7 +114,7 @@ func (eg *ExampleGenerator) StoreExamples() error { b := bytes.Buffer{} b.WriteString("# This example manifest is auto-generated, and has not been tested.\n") b.WriteString("# Please make the necessary adjustments before using it.\n") - b.Write(buff) + b.Write(commentOut(buff)) // no sensitive info in the example manifest if err := ioutil.WriteFile(pm.manifestPath, b.Bytes(), 0644); err != nil { // nolint:gosec return errors.Wrapf(err, "cannot write example manifest file %s for resource %s", pm.manifestPath, n) @@ -123,6 +123,22 @@ func (eg *ExampleGenerator) StoreExamples() error { return nil } +func commentOut(buff []byte) []byte { + lines := strings.Split(string(buff), "\n") + commentedOutLines := make([]string, 0, len(lines)) + for _, l := range lines { + trimmed := strings.TrimSpace(l) + if len(trimmed) == 0 { + continue + } + if !strings.HasPrefix(trimmed, "#") { + l = "#" + l + } + commentedOutLines = append(commentedOutLines, l) + } + return []byte(strings.Join(commentedOutLines, "\n")) +} + func (eg *ExampleGenerator) resolveReferences(params map[string]interface{}) error { // nolint:gocyclo for k, v := range params { switch t := v.(type) {