@@ -2,6 +2,7 @@ package yaml //import "github.com/getsops/sops/v3/stores/yaml"
22
33import (
44 "bytes"
5+ "errors"
56 "fmt"
67 "io"
78 "strings"
@@ -326,19 +327,25 @@ func (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {
326327 return branches , nil
327328}
328329
329- func (store * Store ) getIndentation () int {
330- if store .config .Indent != 0 {
331- return store .config .Indent
330+ func (store * Store ) getIndentation () (int , error ) {
331+ if store .config .Indent > 0 {
332+ return store .config .Indent , nil
333+ } else if store .config .Indent < 0 {
334+ return 0 , errors .New ("YAML Negative indentation not accepted" )
332335 }
333- return IndentDefault
336+ return IndentDefault , nil
334337}
335338
336339// EmitEncryptedFile returns the encrypted bytes of the yaml file corresponding to a
337340// sops.Tree runtime object
338341func (store * Store ) EmitEncryptedFile (in sops.Tree ) ([]byte , error ) {
339342 var b bytes.Buffer
340343 e := yaml .NewEncoder (io .Writer (& b ))
341- e .SetIndent (store .getIndentation ())
344+ indent , err := store .getIndentation ()
345+ if err != nil {
346+ return nil , err
347+ }
348+ e .SetIndent (indent )
342349 for _ , branch := range in .Branches {
343350 // Document root
344351 var doc = yaml.Node {}
@@ -370,7 +377,11 @@ func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {
370377func (store * Store ) EmitPlainFile (branches sops.TreeBranches ) ([]byte , error ) {
371378 var b bytes.Buffer
372379 e := yaml .NewEncoder (io .Writer (& b ))
373- e .SetIndent (store .getIndentation ())
380+ indent , err := store .getIndentation ()
381+ if err != nil {
382+ return nil , err
383+ }
384+ e .SetIndent (indent )
374385 for _ , branch := range branches {
375386 // Document root
376387 var doc = yaml.Node {}
0 commit comments