diff pkg/auth/opendb.go @ 4935:c64dba002726 fairway-marks-import

Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 16 Feb 2020 15:16:22 +0100
parents 7cccf7fef3e8
children 1e6053a4ed98
line wrap: on
line diff
--- a/pkg/auth/opendb.go	Sat Feb 15 21:29:38 2020 +0100
+++ b/pkg/auth/opendb.go	Sun Feb 16 15:16:22 2020 +0100
@@ -145,6 +145,24 @@
 	return fn(conn)
 }
 
+// RunAllAs runs the given functions fns with a database connection impersonated
+// as the given role.
+// To make this work a metamorphic user has to be configured in
+// the system configuration.
+func RunAllAs(ctx context.Context, role string, fns ...func(*sql.Conn) error) error {
+	conn, err := metamorphConn(ctx, role)
+	if err != nil {
+		return err
+	}
+	defer conn.Close()
+	for _, fn := range fns {
+		if err := fn(conn); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
 // RunAsSessionUser is a convinience wrapper araound which extracts
 // the logged in user from a session and calls RunAs with it.
 func RunAsSessionUser(req *http.Request, fn func(*sql.Conn) error) error {