16159: Adds error logging on token expiration failure. Fixes SQL query.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 2 Apr 2021 14:44:14 +0000 (11:44 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 2 Apr 2021 14:44:14 +0000 (11:44 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

lib/controller/localdb/login_testuser.go
lib/controller/localdb/logout.go

index e2f38f35b5d489bdac68ea24d67ff49aca21d771..7bb620baa9e5083adf882caae40678c16bb96c23 100644 (file)
@@ -7,12 +7,15 @@ package localdb
 import (
        "bytes"
        "context"
+       "errors"
        "fmt"
        "html/template"
+       "net/http"
 
        "git.arvados.org/arvados.git/lib/controller/rpc"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/ctxlog"
+       "git.arvados.org/arvados.git/sdk/go/httpserver"
        "github.com/sirupsen/logrus"
 )
 
@@ -24,7 +27,8 @@ type testLoginController struct {
 func (ctrl *testLoginController) Logout(ctx context.Context, opts arvados.LogoutOptions) (arvados.LogoutResponse, error) {
        err := ctrl.Parent.expireAPIClientAuthorization(ctx)
        if err != nil {
-               return arvados.LogoutResponse{}, err
+               ctxlog.FromContext(ctx).Errorf("attempting to expire token on logout: %q", err)
+               return arvados.LogoutResponse{}, httpserver.ErrorWithStatus(errors.New("could not expire token on logout"), http.StatusInternalServerError)
        }
        return noopLogout(ctrl.Cluster, opts)
 }
index 66089539cb703cc8789129886065d160da6f6127..e6b6f6c585c008c49eedd97f8ec5603db6d632e7 100644 (file)
@@ -58,7 +58,7 @@ func (conn *Conn) expireAPIClientAuthorization(ctx context.Context) error {
                return nil
        }
 
-       res, err := tx.ExecContext(ctx, "UPDATE api_client_authorizations SET expires_at=current_timestamp AT TIME ZONE 'UTC' WHERE (expires_at IS NULL OR expires_at > current_timestamp AT TIME ZONE 'UTC' AND api_token=$1)", tokenSecret)
+       res, err := tx.ExecContext(ctx, "UPDATE api_client_authorizations SET expires_at=current_timestamp AT TIME ZONE 'UTC' WHERE api_token=$1 AND (expires_at IS NULL OR expires_at > current_timestamp AT TIME ZONE 'UTC')", tokenSecret)
        if err != nil {
                return err
        }