1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00

Refactor duplicated code

Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
This commit is contained in:
Bastien Wermeille
2023-09-13 14:41:12 +02:00
parent 27f40497e8
commit 6ad2a82d22

View File

@@ -326,16 +326,19 @@ func (store *Store) LoadPlainFile(in []byte) (sops.TreeBranches, error) {
return branches, nil
}
func (store *Store) getIndentation() int {
if store.config.Indent != 0 {
return store.config.Indent
}
return IndentDefault
}
// EmitEncryptedFile returns the encrypted bytes of the yaml file corresponding to a
// sops.Tree runtime object
func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {
var b bytes.Buffer
e := yaml.NewEncoder(io.Writer(&b))
indent := IndentDefault
if store.config.Indent != 0 {
indent = store.config.Indent
}
e.SetIndent(indent)
e.SetIndent(store.getIndentation())
for _, branch := range in.Branches {
// Document root
var doc = yaml.Node{}
@@ -367,11 +370,7 @@ func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {
func (store *Store) EmitPlainFile(branches sops.TreeBranches) ([]byte, error) {
var b bytes.Buffer
e := yaml.NewEncoder(io.Writer(&b))
indent := IndentDefault
if store.config.Indent != 0 {
indent = store.config.Indent
}
e.SetIndent(indent)
e.SetIndent(store.getIndentation())
for _, branch := range branches {
// Document root
var doc = yaml.Node{}