Allow configuration of chunksize parameter
The code using values from the yaml package wasn't careful enought with the possible incoming types. Turns out, it is just an int but we've made this section somewhat bulletproof in case that package changes the behavior. This code likely never worked. The configuration system should be decoupled from the object instantiation. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
bccca791ad
commit
af0c2625e0
1 changed files with 18 additions and 3 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -148,9 +149,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
||||||
chunkSize := int64(defaultChunkSize)
|
chunkSize := int64(defaultChunkSize)
|
||||||
chunkSizeParam, ok := parameters["chunksize"]
|
chunkSizeParam, ok := parameters["chunksize"]
|
||||||
if ok {
|
if ok {
|
||||||
chunkSize, ok = chunkSizeParam.(int64)
|
switch v := chunkSizeParam.(type) {
|
||||||
if !ok || chunkSize < minChunkSize {
|
case string:
|
||||||
return nil, fmt.Errorf("The chunksize parameter should be a number that is larger than 5*1024*1024")
|
vv, err := strconv.ParseInt(v, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("chunksize parameter must be an integer, %v invalid", chunkSizeParam)
|
||||||
|
}
|
||||||
|
chunkSize = vv
|
||||||
|
case int64:
|
||||||
|
chunkSize = v
|
||||||
|
case int, uint, int32, uint32, uint64:
|
||||||
|
chunkSize = reflect.ValueOf(v).Convert(reflect.TypeOf(chunkSize)).Int()
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid valud for chunksize: %#v", chunkSizeParam)
|
||||||
|
}
|
||||||
|
|
||||||
|
if chunkSize <= minChunkSize {
|
||||||
|
return nil, fmt.Errorf("The chunksize %#v parameter should be a number that is larger than or equal to %d", chunkSize, minChunkSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue