File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -248,7 +248,14 @@ 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+ vFloat , floatErr := strconv .ParseFloat (val , 64 )
255+ vInt = int (vFloat )
256+ if floatErr != nil || float64 (vInt ) != vFloat {
257+ return fmt .Errorf ("shamir_threshold is not an integer: %s" , err .Error ())
258+ }
252259 }
253260 m ["shamir_threshold" ] = vInt
254261 case int :
@@ -274,5 +281,11 @@ func EncodeNonStrings(m map[string]interface{}) {
274281 if vInt , ok := v .(int ); ok {
275282 m ["shamir_threshold" ] = fmt .Sprintf ("%d" , vInt )
276283 }
284+ // FlattenMetadata serializes the input as JSON and then deserializes it.
285+ // The JSON unserializer treats every number as a float, so the above 'if'
286+ // never applies in that situation.
287+ if vFloat , ok := v .(float64 ); ok {
288+ m ["shamir_threshold" ] = fmt .Sprintf ("%.0f" , vFloat )
289+ }
277290 }
278291}
You can’t perform that action at this time.
0 commit comments