mirror of
https://github.com/minio/minio.git
synced 2025-03-03 07:10:07 -05:00
postpolicy: handle Amazon S3 compatible content-length-range condition (#3376)
Previously minio server expects content-length-range values as integer in JSON. However Amazon S3 handles content-length-range values as integer and strings. This patch adds support for string values.
This commit is contained in:
parent
38edd94282
commit
0d59ea1e94
@ -18,8 +18,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -34,16 +36,20 @@ func toString(val interface{}) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// toInteger _ Safely convert interface to integer without causing panic.
|
// toInteger _ Safely convert interface to integer without causing panic.
|
||||||
func toInteger(val interface{}) int64 {
|
func toInteger(val interface{}) (int64, error) {
|
||||||
switch v := val.(type) {
|
switch v := val.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
return int64(v)
|
return int64(v), nil
|
||||||
case int64:
|
case int64:
|
||||||
return v
|
return v, nil
|
||||||
case int:
|
case int:
|
||||||
return int64(v)
|
return int64(v), nil
|
||||||
|
case string:
|
||||||
|
i, err := strconv.Atoi(v)
|
||||||
|
return int64(i), err
|
||||||
}
|
}
|
||||||
return 0
|
|
||||||
|
return 0, errors.New("Invalid number format")
|
||||||
}
|
}
|
||||||
|
|
||||||
// isString - Safely check if val is of type string without causing panic.
|
// isString - Safely check if val is of type string without causing panic.
|
||||||
@ -140,9 +146,19 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) {
|
|||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
case "content-length-range":
|
case "content-length-range":
|
||||||
|
min, err := toInteger(condt[1])
|
||||||
|
if err != nil {
|
||||||
|
return parsedPolicy, err
|
||||||
|
}
|
||||||
|
|
||||||
|
max, err := toInteger(condt[2])
|
||||||
|
if err != nil {
|
||||||
|
return parsedPolicy, err
|
||||||
|
}
|
||||||
|
|
||||||
parsedPolicy.Conditions.ContentLengthRange = contentLengthRange{
|
parsedPolicy.Conditions.ContentLengthRange = contentLengthRange{
|
||||||
Min: toInteger(condt[1]),
|
Min: min,
|
||||||
Max: toInteger(condt[2]),
|
Max: max,
|
||||||
Valid: true,
|
Valid: true,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user