comparison 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
comparison
equal deleted inserted replaced
4934:c6af373b0832 4935:c64dba002726
143 } 143 }
144 defer conn.Close() 144 defer conn.Close()
145 return fn(conn) 145 return fn(conn)
146 } 146 }
147 147
148 // RunAllAs runs the given functions fns with a database connection impersonated
149 // as the given role.
150 // To make this work a metamorphic user has to be configured in
151 // the system configuration.
152 func RunAllAs(ctx context.Context, role string, fns ...func(*sql.Conn) error) error {
153 conn, err := metamorphConn(ctx, role)
154 if err != nil {
155 return err
156 }
157 defer conn.Close()
158 for _, fn := range fns {
159 if err := fn(conn); err != nil {
160 return err
161 }
162 }
163 return nil
164 }
165
148 // RunAsSessionUser is a convinience wrapper araound which extracts 166 // RunAsSessionUser is a convinience wrapper araound which extracts
149 // the logged in user from a session and calls RunAs with it. 167 // the logged in user from a session and calls RunAs with it.
150 func RunAsSessionUser(req *http.Request, fn func(*sql.Conn) error) error { 168 func RunAsSessionUser(req *http.Request, fn func(*sql.Conn) error) error {
151 token, ok := GetToken(req) 169 token, ok := GetToken(req)
152 if !ok { 170 if !ok {