Commit b70a3f09 by Torkel Ödegaard

started work datasources admin

parent f665a30d
......@@ -151,6 +151,7 @@ func (mapper SnakeMapper) Table2Obj(name string) string {
func (mapper SnakeMapper) TableName(t string) string {
return t
}
// provide prefix table name support
type PrefixMapper struct {
Mapper IMapper
......
......@@ -33,7 +33,7 @@ extension for Regexp matcher operation.
#include <string.h>
#include <stdio.h>
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
if (argc >= 2) {
......@@ -44,7 +44,7 @@ extension for Regexp matcher operation.
int vec[500];
int n, rc;
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
if (rc <= 0) {
sqlite3_result_error(context, errstr, 0);
return;
......@@ -52,7 +52,7 @@ extension for Regexp matcher operation.
sqlite3_result_int(context, 1);
}
}
#ifdef _WIN32
__declspec(dllexport)
#endif
......
......@@ -318,7 +318,7 @@ func BenchmarkQuery(b *testing.B) {
var i int
var f float64
var s string
// var t time.Time
// var t time.Time
if err := db.QueryRow("select null, 1, 1.1, 'foo'").Scan(&n, &i, &f, &s); err != nil {
panic(err)
}
......@@ -331,7 +331,7 @@ func BenchmarkParams(b *testing.B) {
var i int
var f float64
var s string
// var t time.Time
// var t time.Time
if err := db.QueryRow("select ?, ?, ?, ?", nil, 1, 1.1, "foo").Scan(&n, &i, &f, &s); err != nil {
panic(err)
}
......@@ -350,7 +350,7 @@ func BenchmarkStmt(b *testing.B) {
var i int
var f float64
var s string
// var t time.Time
// var t time.Time
if err := st.QueryRow(nil, 1, 1.1, "foo").Scan(&n, &i, &f, &s); err != nil {
panic(err)
}
......
Subproject commit 373118c5eecc5c3645254cb4b862124b55dae980
Subproject commit b3b096e204a8ad6eb2aba6b98802589ab3d1fa28
......@@ -25,6 +25,10 @@ func Register(m *macaron.Macaron) {
m.Post("/api/account/using/:id", auth, SetUsingAccount)
m.Get("/api/account/others", auth, GetOtherAccounts)
// datasources
m.Get("/admin/datasources/", auth, Index)
m.Get("/api/admin/datasources/", auth, GetDataSources)
// user register
m.Get("/register/*_", Index)
m.Post("/api/account", CreateAccount)
......
package api
import (
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
)
func GetDataSources(c *middleware.Context) {
query := m.GetDataSourcesQuery{AccountId: c.Account.Id}
err := bus.SendQuery(&query)
if err != nil {
c.JsonApiErr(500, "Failed to query datasources", err)
return
}
}
......@@ -18,6 +18,9 @@ type InProcBus struct {
handlerIndex map[string]QueryHandler
}
// temp stuff, not sure how to handle bus instance, and init yet
var globalBus = New()
func New() Bus {
bus := &InProcBus{}
bus.handlerIndex = make(map[string]QueryHandler)
......@@ -51,3 +54,12 @@ func (b *InProcBus) AddQueryHandler(handler QueryHandler) {
fmt.Printf("QueryType %v\n", queryTypeName)
b.handlerIndex[queryTypeName] = handler
}
// Package level functions
func AddQueryHandler(implName string, handler QueryHandler) {
globalBus.AddQueryHandler(handler)
}
func SendQuery(query Query) error {
return globalBus.SendQuery(query)
}
......@@ -20,7 +20,7 @@ func TestHandlerReturnsError(t *testing.T) {
err := bus.SendQuery(&TestQuery{})
if err == nil {
t.Fatal("Send query failed %v", err)
t.Fatal("Send query failed " + err.Error())
} else {
t.Log("Handler error received ok")
}
......@@ -38,7 +38,7 @@ func TestHandlerReturn(t *testing.T) {
err := bus.SendQuery(query)
if err != nil {
t.Fatal("Send query failed %v", err)
t.Fatal("Send query failed " + err.Error())
} else if query.Resp != "hello from handler" {
t.Fatal("Failed to get response from handler")
}
......
package dto
type GetDashboardQuery struct {
Id int64
Resp GetDashboardQueryResp
}
type GetDashboardQueryResp struct {
}
......@@ -46,8 +46,8 @@ func Logger() macaron.Handler {
content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
return
case 304:
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
return
content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
case 404:
content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
case 500:
......
......@@ -9,6 +9,7 @@ import (
"github.com/torkelo/grafana-pro/pkg/log"
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
)
type Context struct {
......@@ -60,8 +61,8 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
if err != nil {
log.Error(4, "%s: %v", message, err)
if macaron.Env != macaron.PROD {
resp["error"] = err
if setting.Env != setting.PROD {
resp["error"] = err.Error()
}
}
......
package models
import "time"
const (
DS_GRAPHITE = "GRAPHITE"
DS_INFLUXDB = "INFLUXDB"
DS_ES = "ES"
DS_ACESSS_DIRECT = "DIRECT"
DS_ACESSS_PROXY = "PROXY"
)
type DsType string
type DsAccess string
type DataSource struct {
Id int64
AccountId int64
Name string
Type DsType
Access DsAccess
Url string
Password string
User string
BasicAuth bool
Created time.Time
Updated time.Time
}
type GetDataSourcesQuery struct {
AccountId int64
Resp []*DataSource
}
......@@ -25,8 +25,15 @@ const (
HTTPS Scheme = "https"
)
const (
DEV string = "development"
PROD string = "production"
TEST string = "test"
)
var (
// App settings.
Env string = DEV
AppVer string
AppName string
AppUrl string
......
package sqlstore
import (
"errors"
"github.com/torkelo/grafana-pro/pkg/bus"
m "github.com/torkelo/grafana-pro/pkg/models"
)
func init() {
bus.AddQueryHandler("sql", GetDataSourcesQuery)
}
func GetDataSourcesQuery(query *m.GetDataSourcesQuery) error {
return errors.New("Hello from query handler")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment