diff --git a/go.mod b/go.mod index 849557af5..55c70b408 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( google.golang.org/api v0.7.0 google.golang.org/grpc v1.27.0 google.golang.org/protobuf v1.25.0 - gopkg.in/ini.v1 v1.44.0 + gopkg.in/ini.v1 v1.61.0 gopkg.in/urfave/cli.v1 v1.20.0 gotest.tools v2.2.0+incompatible // indirect ) diff --git a/go.sum b/go.sum index e017155d8..0a469aa08 100644 --- a/go.sum +++ b/go.sum @@ -413,8 +413,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/ini.v1 v1.44.0 h1:YRJzTUp0kSYWUVFF5XAbDFfyiqwsl0Vb9R8TVP5eRi0= -gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.61.0 h1:LBCdW4FmFYL4s/vDZD1RQYX7oAR6IjujCYgMdbHBR10= +gopkg.in/ini.v1 v1.61.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= diff --git a/stores/ini/store.go b/stores/ini/store.go index df5405294..c54ed1b6d 100644 --- a/stores/ini/store.go +++ b/stores/ini/store.go @@ -89,7 +89,10 @@ func (store Store) iniFromTreeBranches(branches sops.TreeBranches) ([]byte, erro } func (store Store) treeBranchesFromIni(in []byte) (sops.TreeBranches, error) { - iniFile, err := ini.Load(in) + iniFile, err := ini.LoadSources(ini.LoadOptions{ + IgnoreInlineComment: true, + AllowPythonMultilineValues: true, + }, in) if err != nil { return nil, err } @@ -137,7 +140,10 @@ func (store Store) treeItemFromSection(section *ini.Section) (sops.TreeItem, err // LoadEncryptedFile loads encrypted INI file's bytes onto a sops.Tree runtime object func (store *Store) LoadEncryptedFile(in []byte) (sops.Tree, error) { - iniFileOuter, err := ini.Load(in) + iniFileOuter, err := ini.LoadSources(ini.LoadOptions{ + IgnoreInlineComment: true, + AllowPythonMultilineValues: true, + }, in) if err != nil { return sops.Tree{}, err } diff --git a/stores/ini/store_test.go b/stores/ini/store_test.go index 9be162957..bbc728984 100644 --- a/stores/ini/store_test.go +++ b/stores/ini/store_test.go @@ -19,6 +19,12 @@ organization=Acme Widgets Inc. server=192.0.2.62 port=143 file="payroll.dat" + +[format] +test = value with#hash +pythonic = some + additional + value ` expected := sops.TreeBranches{ sops.TreeBranch{ @@ -64,6 +70,19 @@ file="payroll.dat" }, }, }, + sops.TreeItem{ + Key: "format", + Value: sops.TreeBranch{ + sops.TreeItem{ + Key: "test", + Value: "value with#hash", + }, + sops.TreeItem{ + Key: "pythonic", + Value: "some\nadditional\nvalue", + }, + }, + }, }, } branch, err := Store{}.treeBranchesFromIni([]byte(in)) @@ -127,6 +146,30 @@ func TestEncodeIniWithEscaping(t *testing.T) { assert.Equal(t, expected, branches) } +func TestEncodeIniWithPreserving(t *testing.T) { + branches := sops.TreeBranches{ + sops.TreeBranch{ + sops.TreeItem{ + Key: "DEFAULT", + Value: sops.TreeBranch{ + sops.TreeItem{ + Key: "hash", + Value: "foo#bar", + }, + sops.TreeItem{ + Key: "semicolon", + Value: "foo;bar", + }, + }, + }, + }, + } + out, err := Store{}.iniFromTreeBranches(branches) + assert.Nil(t, err) + expected, _ := Store{}.treeBranchesFromIni(out) + assert.Equal(t, expected, branches) +} + func TestUnmarshalMetadataFromNonSOPSFile(t *testing.T) { data := []byte(`hello=2`) store := Store{}