Skip to content

Commit c9fc965

Browse files
author
Michael Kane Juncker
committed
[stores/ini] Allow hash/semicolon in values and Python multi-line indented values - refs #751
1 parent 49c2514 commit c9fc965

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
google.golang.org/api v0.7.0
4747
google.golang.org/grpc v1.27.0
4848
google.golang.org/protobuf v1.25.0
49-
gopkg.in/ini.v1 v1.44.0
49+
gopkg.in/ini.v1 v1.61.0
5050
gopkg.in/urfave/cli.v1 v1.20.0
5151
gotest.tools v2.2.0+incompatible // indirect
5252
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
413413
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
414414
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
415415
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
416-
gopkg.in/ini.v1 v1.44.0 h1:YRJzTUp0kSYWUVFF5XAbDFfyiqwsl0Vb9R8TVP5eRi0=
417-
gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
416+
gopkg.in/ini.v1 v1.61.0 h1:LBCdW4FmFYL4s/vDZD1RQYX7oAR6IjujCYgMdbHBR10=
417+
gopkg.in/ini.v1 v1.61.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
418418
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
419419
gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4=
420420
gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=

stores/ini/store.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func (store Store) iniFromTreeBranches(branches sops.TreeBranches) ([]byte, erro
8989
}
9090

9191
func (store Store) treeBranchesFromIni(in []byte) (sops.TreeBranches, error) {
92-
iniFile, err := ini.Load(in)
92+
iniFile, err := ini.LoadSources(ini.LoadOptions{
93+
IgnoreInlineComment: true,
94+
AllowPythonMultilineValues: true,
95+
}, in)
9396
if err != nil {
9497
return nil, err
9598
}
@@ -137,7 +140,10 @@ func (store Store) treeItemFromSection(section *ini.Section) (sops.TreeItem, err
137140

138141
// LoadEncryptedFile loads encrypted INI file's bytes onto a sops.Tree runtime object
139142
func (store *Store) LoadEncryptedFile(in []byte) (sops.Tree, error) {
140-
iniFileOuter, err := ini.Load(in)
143+
iniFileOuter, err := ini.LoadSources(ini.LoadOptions{
144+
IgnoreInlineComment: true,
145+
AllowPythonMultilineValues: true,
146+
}, in)
141147
if err != nil {
142148
return sops.Tree{}, err
143149
}

stores/ini/store_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ organization=Acme Widgets Inc.
1919
server=192.0.2.62
2020
port=143
2121
file="payroll.dat"
22+
23+
[format]
24+
test = value with#hash
25+
pythonic = some
26+
additional
27+
value
2228
`
2329
expected := sops.TreeBranches{
2430
sops.TreeBranch{
@@ -64,6 +70,19 @@ file="payroll.dat"
6470
},
6571
},
6672
},
73+
sops.TreeItem{
74+
Key: "format",
75+
Value: sops.TreeBranch{
76+
sops.TreeItem{
77+
Key: "test",
78+
Value: "value with#hash",
79+
},
80+
sops.TreeItem{
81+
Key: "pythonic",
82+
Value: "some\nadditional\nvalue",
83+
},
84+
},
85+
},
6786
},
6887
}
6988
branch, err := Store{}.treeBranchesFromIni([]byte(in))
@@ -127,6 +146,30 @@ func TestEncodeIniWithEscaping(t *testing.T) {
127146
assert.Equal(t, expected, branches)
128147
}
129148

149+
func TestEncodeIniWithPreserving(t *testing.T) {
150+
branches := sops.TreeBranches{
151+
sops.TreeBranch{
152+
sops.TreeItem{
153+
Key: "DEFAULT",
154+
Value: sops.TreeBranch{
155+
sops.TreeItem{
156+
Key: "hash",
157+
Value: "foo#bar",
158+
},
159+
sops.TreeItem{
160+
Key: "semicolon",
161+
Value: "foo;bar",
162+
},
163+
},
164+
},
165+
},
166+
}
167+
out, err := Store{}.iniFromTreeBranches(branches)
168+
assert.Nil(t, err)
169+
expected, _ := Store{}.treeBranchesFromIni(out)
170+
assert.Equal(t, expected, branches)
171+
}
172+
130173
func TestUnmarshalMetadataFromNonSOPSFile(t *testing.T) {
131174
data := []byte(`hello=2`)
132175
store := Store{}

0 commit comments

Comments
 (0)