Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Comment out all lines in the generated example manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Jan 6, 2022
1 parent a301620 commit bf4c470
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pkg/pipeline/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit bf4c470

Please sign in to comment.