Merge pull request #143 from sosedoff/session-id-for-export
Session id for export
This commit is contained in:
commit
1d50e2f0bf
@ -22,7 +22,7 @@ var (
|
|||||||
|
|
||||||
func DB(c *gin.Context) *client.Client {
|
func DB(c *gin.Context) *client.Client {
|
||||||
if command.Opts.Sessions {
|
if command.Opts.Sessions {
|
||||||
return DbSessions[getSessionId(c)]
|
return DbSessions[getSessionId(c.Request)]
|
||||||
} else {
|
} else {
|
||||||
return DbClient
|
return DbClient
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ func setClient(c *gin.Context, newClient *client.Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionId := getSessionId(c)
|
sessionId := getSessionId(c.Request)
|
||||||
if sessionId == "" {
|
if sessionId == "" {
|
||||||
return errors.New("Session ID is required")
|
return errors.New("Session ID is required")
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"mime"
|
"mime"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -70,10 +71,10 @@ func desanitize64(query string) string {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSessionId(c *gin.Context) string {
|
func getSessionId(req *http.Request) string {
|
||||||
id := c.Request.Header.Get("x-session-id")
|
id := req.Header.Get("x-session-id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
id = c.Request.URL.Query().Get("_session_id")
|
id = req.URL.Query().Get("_session_id")
|
||||||
}
|
}
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_desanitize64(t *testing.T) {
|
func Test_desanitize64(t *testing.T) {
|
||||||
@ -23,3 +26,13 @@ func Test_cleanQuery(t *testing.T) {
|
|||||||
assert.Equal(t, "", cleanQuery("--something"))
|
assert.Equal(t, "", cleanQuery("--something"))
|
||||||
assert.Equal(t, "test", cleanQuery("--test\ntest\n -- test\n"))
|
assert.Equal(t, "test", cleanQuery("--test\ntest\n -- test\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_getSessionId(t *testing.T) {
|
||||||
|
req := &http.Request{Header: http.Header{}}
|
||||||
|
req.Header.Add("x-session-id", "token")
|
||||||
|
assert.Equal(t, "token", getSessionId(req))
|
||||||
|
|
||||||
|
req = &http.Request{}
|
||||||
|
req.URL, _ = url.Parse("http://foobar/?_session_id=token")
|
||||||
|
assert.Equal(t, "token", getSessionId(req))
|
||||||
|
}
|
||||||
|
@ -32,7 +32,7 @@ func dbCheckMiddleware() gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionId := getSessionId(c)
|
sessionId := getSessionId(c.Request)
|
||||||
if sessionId == "" {
|
if sessionId == "" {
|
||||||
c.JSON(400, Error{"Session ID is required"})
|
c.JSON(400, Error{"Session ID is required"})
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
File diff suppressed because one or more lines are too long
@ -211,7 +211,7 @@ function performTableAction(table, action, el) {
|
|||||||
var format = el.data("format");
|
var format = el.data("format");
|
||||||
var filename = table + "." + format;
|
var filename = table + "." + format;
|
||||||
var query = window.encodeURI("SELECT * FROM " + table);
|
var query = window.encodeURI("SELECT * FROM " + table);
|
||||||
var url = "http://" + window.location.host + "/api/query?format=" + format + "&filename=" + filename + "&query=" + query;
|
var url = "http://" + window.location.host + "/api/query?format=" + format + "&filename=" + filename + "&query=" + query + "&_session_id=" + getSessionId();
|
||||||
var win = window.open(url, "_blank");
|
var win = window.open(url, "_blank");
|
||||||
win.focus();
|
win.focus();
|
||||||
break;
|
break;
|
||||||
@ -542,7 +542,7 @@ function exportTo(format) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = "http://" + window.location.host + "/api/query?format=" + format + "&query=" + encodeQuery(query);
|
var url = "http://" + window.location.host + "/api/query?format=" + format + "&query=" + encodeQuery(query) + "&_session_id=" + getSessionId();
|
||||||
var win = window.open(url, '_blank');
|
var win = window.open(url, '_blank');
|
||||||
|
|
||||||
setCurrentTab("table_query");
|
setCurrentTab("table_query");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user