Skip to content
Snippets Groups Projects

feat: allow restricted users to access all databases in clones created with the "--restricted" flag (#356)

Merged Denis O requested to merge 356-restriction-template-all-dbs into master
Files
3
@@ -193,3 +193,47 @@ func runSimpleSQL(command, connStr string) (string, error) {
return result, err
}
// runSQLQuery - execute query return result as string array
func runSQLQuery(command string, connStr string) ([]string, error) {
result := make([]string, 0)
db, err := sql.Open("postgres", connStr)
if err != nil {
return result, errors.Wrap(err, "cannot connect to database")
}
rows, err := db.Query(command)
if err != nil {
return result, errors.Wrap(err, "failed to execute query")
}
defer func(rows *sql.Rows) {
e := rows.Close()
if e != nil {
log.Err("cannot close database result.", e)
}
}(rows)
for rows.Next() {
var s string
if e := rows.Scan(&s); e != nil {
log.Err("query execution error:", e)
return result, e
}
result = append(result, s)
}
defer func() {
err := db.Close()
if err != nil {
log.Err("cannot close database connection.")
}
}()
return result, err
}
Loading