X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4f1152fbdd0506d3d07449bedb2479f2938bcf73..3aaefcb3c76ff470b475d950398d01255e87712a:/lib/controller/rpc/conn.go?ds=sidebyside diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go index c3c66d00a3..cd98b64718 100644 --- a/lib/controller/rpc/conn.go +++ b/lib/controller/rpc/conn.go @@ -5,6 +5,7 @@ package rpc import ( + "bytes" "context" "crypto/tls" "encoding/json" @@ -14,6 +15,7 @@ import ( "net" "net/http" "net/url" + "strconv" "strings" "time" @@ -24,11 +26,11 @@ import ( type TokenProvider func(context.Context) ([]string, error) func PassthroughTokenProvider(ctx context.Context) ([]string, error) { - if incoming, ok := auth.FromContext(ctx); !ok { + incoming, ok := auth.FromContext(ctx) + if !ok { return nil, errors.New("no token provided") - } else { - return incoming.Tokens, nil } + return incoming.Tokens, nil } type Conn struct { @@ -100,19 +102,23 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva return fmt.Errorf("%T: requestAndDecode: Marshal opts: %s", conn, err) } var params map[string]interface{} - err = json.Unmarshal(j, ¶ms) + dec := json.NewDecoder(bytes.NewBuffer(j)) + dec.UseNumber() + err = dec.Decode(¶ms) if err != nil { - return fmt.Errorf("%T: requestAndDecode: Unmarshal opts: %s", conn, err) + return fmt.Errorf("%T: requestAndDecode: Decode opts: %s", conn, err) } if attrs, ok := params["attrs"]; ok && ep.AttrsKey != "" { params[ep.AttrsKey] = attrs delete(params, "attrs") } - if limit, ok := params["limit"].(float64); ok && limit < 0 { - // Negative limit means "not specified" here, but some - // servers/versions do not accept that, so we need to - // remove it entirely. - delete(params, "limit") + if limitStr, ok := params["limit"]; ok { + if limit, err := strconv.ParseInt(string(limitStr.(json.Number)), 10, 64); err == nil && limit < 0 { + // Negative limit means "not specified" here, but some + // servers/versions do not accept that, so we need to + // remove it entirely. + delete(params, "limit") + } } if len(tokens) > 1 { params["reader_tokens"] = tokens[1:] @@ -164,9 +170,8 @@ func (conn *Conn) relativeToBaseURL(location string) string { u.User = nil u.Host = "" return u.String() - } else { - return location } + return location } func (conn *Conn) CollectionCreate(ctx context.Context, options arvados.CreateOptions) (arvados.Collection, error) {