X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/82b785e9232ef6899b32cf71fb3163ded846f141..bdc069a04fd98529f5c79c6b8a7164fb9119723d:/lib/controller/rpc/conn.go diff --git a/lib/controller/rpc/conn.go b/lib/controller/rpc/conn.go index bf6166f44f..729d8bdde0 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" @@ -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. @@ -409,8 +423,15 @@ func (conn *Conn) UserSessionCreate(ctx context.Context, options UserSessionCrea } func (conn *Conn) UserBatchUpdate(ctx context.Context, options arvados.UserBatchUpdateOptions) (arvados.UserList, error) { - ep := arvados.APIEndpoint{Method: "PATCH", Path: "arvados/v1/users/batch_update"} + ep := arvados.EndpointUserBatchUpdate var resp arvados.UserList err := conn.requestAndDecode(ctx, &resp, ep, nil, options) return resp, err } + +func (conn *Conn) UserAuthenticate(ctx context.Context, options arvados.UserAuthenticateOptions) (arvados.APIClientAuthorization, error) { + ep := arvados.EndpointUserAuthenticate + var resp arvados.APIClientAuthorization + err := conn.requestAndDecode(ctx, &resp, ep, nil, options) + return resp, err +}