changeset 1327:cabf4789e02b

To make golint happier made context.Context to be the first argument of auth.RunAs.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 25 Nov 2018 15:56:07 +0100
parents 515815565bd0
children d753ce6cf588
files pkg/auth/opendb.go pkg/controllers/json.go pkg/controllers/pwreset.go pkg/imports/queue.go pkg/models/extservices.go pkg/models/intservices.go
diffstat 6 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/auth/opendb.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/auth/opendb.go	Sun Nov 25 15:56:07 2018 +0100
@@ -126,7 +126,7 @@
 	return roles, rows.Err()
 }
 
-func RunAs(role string, ctx context.Context, fn func(*sql.Conn) error) error {
+func RunAs(ctx context.Context, role string, fn func(*sql.Conn) error) error {
 	conn, err := MetamorphConn(ctx, role)
 	if err != nil {
 		return err
@@ -144,5 +144,5 @@
 	if session == nil {
 		return ErrNotLoggedIn
 	}
-	return RunAs(session.User, req.Context(), fn)
+	return RunAs(req.Context(), session.User, fn)
 }
--- a/pkg/controllers/json.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/controllers/json.go	Sun Nov 25 15:56:07 2018 +0100
@@ -63,7 +63,7 @@
 
 	if token, ok := auth.GetToken(req); ok && !j.NoConn {
 		if session := auth.Sessions.Session(token); session != nil {
-			err = auth.RunAs(session.User, req.Context(), func(conn *sql.Conn) error {
+			err = auth.RunAs(req.Context(), session.User, func(conn *sql.Conn) error {
 				jr, err = j.Handle(input, req, conn)
 				return err
 			})
--- a/pkg/controllers/pwreset.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/controllers/pwreset.go	Sun Nov 25 15:56:07 2018 +0100
@@ -122,12 +122,13 @@
 	config.WaitReady()
 	for {
 		time.Sleep(cleanupPause)
+		ctx := context.Background()
 		err := auth.RunAs(
-			pwResetRole, context.Background(),
+			ctx, pwResetRole,
 			func(conn *sql.Conn) error {
 				good := time.Now().Add(-passwordResetValid)
 				_, err := conn.ExecContext(
-					context.Background(), cleanupRequestsSQL, good)
+					ctx, cleanupRequestsSQL, good)
 				return err
 			})
 		if err != nil {
@@ -208,7 +209,7 @@
 	ctx := context.Background()
 
 	if err := auth.RunAs(
-		pwResetRole, ctx,
+		ctx, pwResetRole,
 		func(conn *sql.Conn) error {
 
 			var count int64
@@ -304,7 +305,7 @@
 	ctx := req.Context()
 
 	if err = auth.RunAs(
-		pwResetRole, ctx, func(conn *sql.Conn) error {
+		ctx, pwResetRole, func(conn *sql.Conn) error {
 			err := conn.QueryRowContext(ctx, findRequestSQL, hash).Scan(&email, &user)
 			switch {
 			case err == sql.ErrNoRows:
--- a/pkg/imports/queue.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/imports/queue.go	Sun Nov 25 15:56:07 2018 +0100
@@ -160,7 +160,7 @@
 func (q *importQueue) addJob(kind JobKind, user, data string) (int64, error) {
 	ctx := context.Background()
 	var id int64
-	err := auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	err := auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		return conn.QueryRowContext(ctx, insertJobSQL, string(kind), user, data).Scan(&id)
 	})
 	if err == nil {
@@ -180,7 +180,7 @@
 
 func (lf logFeedback) log(kind, format string, args ...interface{}) {
 	ctx := context.Background()
-	err := auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	err := auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		_, err := conn.ExecContext(
 			ctx, logMessageSQL, int64(lf), kind, fmt.Sprintf(format, args...))
 		return err
@@ -215,7 +215,7 @@
 
 func reEnqueueRunning() error {
 	ctx := context.Background()
-	return auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	return auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		_, err := conn.ExecContext(ctx, reEnqueueRunningSQL)
 		return err
 	})
@@ -248,7 +248,7 @@
 
 	var ji idJob
 	ctx := context.Background()
-	err := auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	err := auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		tx, err := conn.BeginTx(ctx, nil)
 		if err != nil {
 			return err
@@ -275,7 +275,7 @@
 
 func updateState(id int64, state string) error {
 	ctx := context.Background()
-	return auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	return auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		_, err := conn.ExecContext(ctx, updateStateSQL, state, id)
 		return err
 	})
@@ -283,7 +283,7 @@
 
 func errorAndFail(id int64, format string, args ...interface{}) error {
 	ctx := context.Background()
-	err := auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error {
+	err := auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error {
 		tx, err := conn.BeginTx(ctx, nil)
 		if err != nil {
 			return err
@@ -372,7 +372,7 @@
 
 			errDo := survive(func() error {
 				ctx := context.Background()
-				return auth.RunAs(idj.user, ctx,
+				return auth.RunAs(ctx, idj.user,
 					func(conn *sql.Conn) error {
 						return job.Do(idj.id, ctx, conn, feedback)
 					})
--- a/pkg/models/extservices.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/models/extservices.go	Sun Nov 25 15:56:07 2018 +0100
@@ -61,7 +61,7 @@
 func (es *ExtServices) load() error {
 	// make empty slice to prevent retry if slice is empty.
 	es.entries = []ExtEntry{}
-	return auth.RunAs("sys_admin", context.Background(),
+	return auth.RunAs(context.Background(), "sys_admin",
 		func(conn *sql.Conn) error {
 			rows, err := conn.QueryContext(
 				context.Background(), selectExternalServices)
--- a/pkg/models/intservices.go	Sun Nov 25 10:51:54 2018 +0100
+++ b/pkg/models/intservices.go	Sun Nov 25 15:56:07 2018 +0100
@@ -59,10 +59,11 @@
 
 func (e *IntEntry) LoadStyle() (string, error) {
 	var style string
-	err := auth.RunAs("sys_admin", context.Background(),
+	ctx := context.Background()
+	err := auth.RunAs(ctx, "sys_admin",
 		func(conn *sql.Conn) error {
 			return conn.QueryRowContext(
-				context.Background(),
+				ctx,
 				selectStyleSQL,
 				e.Name).Scan(&style)
 		})
@@ -119,10 +120,11 @@
 func (ps *IntServices) load() error {
 	// make empty slice to prevent retry if slice is empty.
 	ps.entries = []IntEntry{}
-	return auth.RunAs("sys_admin", context.Background(),
+	ctx := context.Background()
+	return auth.RunAs(ctx, "sys_admin",
 		func(conn *sql.Conn) error {
 			rows, err := conn.QueryContext(
-				context.Background(), selectServicesSQL)
+				ctx, selectServicesSQL)
 			if err != nil {
 				return err
 			}