Skip to content

Commit fcff18d

Browse files
committed
Also parse floating point numbers if they represent integers.
Signed-off-by: Felix Fontein <felix@fontein.de>
1 parent c30e36e commit fcff18d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

stores/flatten.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,18 @@ func DecodeNonStrings(m map[string]interface{}) error {
248248
case string:
249249
vInt, err := strconv.Atoi(val)
250250
if err != nil {
251-
return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error())
251+
// Older versions of SOPS stored shamir_threshold as a floating point representation
252+
// of the actual integer. Try to parse a floating point number and see whether it
253+
// can be converted without loss to an integer.
254+
var vFloat float64
255+
vFloat, err = strconv.ParseFloat(val, 64)
256+
if err != nil {
257+
return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error())
258+
}
259+
vInt = int(vFloat)
260+
if float64(vInt) != vFloat {
261+
return fmt.Errorf("shamir_threshold is not an integer")
262+
}
252263
}
253264
m["shamir_threshold"] = vInt
254265
case int:

0 commit comments

Comments
 (0)