Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion stores/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ func DecodeNonStrings(m map[string]interface{}) error {
case string:
vInt, err := strconv.Atoi(val)
if err != nil {
return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error())
// Older versions of SOPS stored shamir_threshold as a floating point representation
// of the actual integer. Try to parse a floating point number and see whether it
// can be converted without loss to an integer.
vFloat, floatErr := strconv.ParseFloat(val, 64)
vInt = int(vFloat)
if floatErr != nil || float64(vInt) != vFloat {
return fmt.Errorf("shamir_threshold is not an integer: %s", err.Error())
}
}
m["shamir_threshold"] = vInt
case int:
Expand All @@ -274,5 +281,11 @@ func EncodeNonStrings(m map[string]interface{}) {
if vInt, ok := v.(int); ok {
m["shamir_threshold"] = fmt.Sprintf("%d", vInt)
}
// FlattenMetadata serializes the input as JSON and then deserializes it.
// The JSON unserializer treats every number as a float, so the above 'if'
// never applies in that situation.
if vFloat, ok := v.(float64); ok {
m["shamir_threshold"] = fmt.Sprintf("%.0f", vFloat)
}
}
}
Loading