X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fb72a4315bfcf64621d023a38d1544319aa3666c..12b5341528770adc532b6c3e169036addd945d52:/lib/controller/rpc/conn.go diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go index f4bc1733ea..b5c56dbc4d 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,11 +15,12 @@ import ( "net" "net/http" "net/url" + "strconv" "strings" "time" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/auth" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/auth" ) type TokenProvider func(context.Context) ([]string, error) @@ -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:] @@ -145,6 +151,14 @@ func (conn *Conn) Login(ctx context.Context, options arvados.LoginOptions) (arva return resp, err } +func (conn *Conn) Logout(ctx context.Context, options arvados.LogoutOptions) (arvados.LogoutResponse, error) { + ep := arvados.EndpointLogout + var resp arvados.LogoutResponse + err := conn.requestAndDecode(ctx, &resp, ep, nil, options) + resp.RedirectLocation = conn.relativeToBaseURL(resp.RedirectLocation) + return resp, err +} + // If the given location is a valid URL and its origin is the same as // conn.baseURL, return it as a relative URL. Otherwise, return it // unmodified. @@ -327,25 +341,25 @@ func (conn *Conn) UserUpdateUUID(ctx context.Context, options arvados.UpdateUUID return resp, err } func (conn *Conn) UserMerge(ctx context.Context, options arvados.UserMergeOptions) (arvados.User, error) { - ep := arvados.EndpointUserUpdateUUID + ep := arvados.EndpointUserMerge var resp arvados.User err := conn.requestAndDecode(ctx, &resp, ep, nil, options) return resp, err } func (conn *Conn) UserActivate(ctx context.Context, options arvados.UserActivateOptions) (arvados.User, error) { - ep := arvados.EndpointUserUpdateUUID + ep := arvados.EndpointUserActivate var resp arvados.User err := conn.requestAndDecode(ctx, &resp, ep, nil, options) return resp, err } func (conn *Conn) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) { - ep := arvados.EndpointUserUpdateUUID + ep := arvados.EndpointUserSetup var resp map[string]interface{} err := conn.requestAndDecode(ctx, &resp, ep, nil, options) return resp, err } func (conn *Conn) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) { - ep := arvados.EndpointUserUpdateUUID + ep := arvados.EndpointUserUnsetup var resp arvados.User err := conn.requestAndDecode(ctx, &resp, ep, nil, options) return resp, err