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:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user