diff --git a/pkg/api/api_config.go b/pkg/api/api_config.go index bc05dbe5a65..0487c09a7ff 100644 --- a/pkg/api/api_config.go +++ b/pkg/api/api_config.go @@ -28,14 +28,24 @@ func renderConfig(data *configJsTmplModel) string { for i, ds := range data.DataSources { url := ds.Url + if ds.Access == m.DS_ACCESS_PROXY { url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10) } + var dsMap = map[string]interface{}{ "type": ds.Type, "url": url, } + if ds.Type == m.DS_INFLUXDB { + if ds.Access == m.DS_ACCESS_DIRECT { + dsMap["username"] = ds.User + dsMap["password"] = ds.Password + dsMap["url"] = url + "/db/" + ds.Database + } + } + // temp hack, first is always default // TODO: implement default ds account setting if i == 0 { diff --git a/pkg/api/api_datasources.go b/pkg/api/api_datasources.go index ed97b41738e..b78aa5320eb 100644 --- a/pkg/api/api_datasources.go +++ b/pkg/api/api_datasources.go @@ -26,6 +26,7 @@ func GetDataSources(c *middleware.Context) { Type: ds.Type, Access: ds.Access, Password: ds.Password, + Database: ds.Database, User: ds.User, BasicAuth: ds.BasicAuth, } diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 7b340d06d4b..5fcc773170d 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -47,6 +47,7 @@ type DataSource struct { Url string `json:"url"` Password string `json:"password"` User string `json:"user"` + Database string `json:"database"` BasicAuth bool `json:"basicAuth"` } diff --git a/pkg/models/datasource.go b/pkg/models/datasource.go index 909250450b9..b81312b9b6b 100644 --- a/pkg/models/datasource.go +++ b/pkg/models/datasource.go @@ -31,6 +31,7 @@ type DataSource struct { Url string Password string User string + Database string BasicAuth bool Created time.Time @@ -55,6 +56,7 @@ type AddDataSourceCommand struct { Access DsAccess Url string Password string + Database string User string } @@ -67,6 +69,7 @@ type UpdateDataSourceCommand struct { Url string Password string User string + Database string } type DeleteDataSourceCommand struct { diff --git a/pkg/stores/sqlstore/sqlstore_datasource.go b/pkg/stores/sqlstore/sqlstore_datasource.go index 71c6ea901eb..74488adece0 100644 --- a/pkg/stores/sqlstore/sqlstore_datasource.go +++ b/pkg/stores/sqlstore/sqlstore_datasource.go @@ -28,7 +28,7 @@ func GetDataSourceById(query *m.GetDataSourceByIdQuery) error { } func GetDataSources(query *m.GetDataSourcesQuery) error { - sess := x.Limit(100, 0).Where("account_id=?", query.AccountId) + sess := x.Limit(100, 0).Where("account_id=?", query.AccountId).Asc("name") query.Result = make([]*m.DataSource, 0) return sess.Find(&query.Result) @@ -53,6 +53,9 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error { Type: cmd.Type, Access: cmd.Access, Url: cmd.Url, + User: cmd.User, + Password: cmd.Password, + Database: cmd.Database, Created: time.Now(), Updated: time.Now(), } @@ -75,6 +78,9 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error { Type: cmd.Type, Access: cmd.Access, Url: cmd.Url, + User: cmd.User, + Password: cmd.Password, + Database: cmd.Database, Updated: time.Now(), } diff --git a/pkg/stores/sqlstore/sqlstore_test.go b/pkg/stores/sqlstore/sqlstore_test.go index 27bb4c4bec4..2eef0c6792c 100644 --- a/pkg/stores/sqlstore/sqlstore_test.go +++ b/pkg/stores/sqlstore/sqlstore_test.go @@ -34,9 +34,10 @@ func TestDataAccess(t *testing.T) { err := AddDataSource(&m.AddDataSourceCommand{ AccountId: 10, - Type: m.DS_GRAPHITE, + Type: m.DS_INFLUXDB, Access: m.DS_ACCESS_DIRECT, Url: "http://test", + Database: "site", }) So(err, ShouldBeNil) @@ -50,6 +51,7 @@ func TestDataAccess(t *testing.T) { ds := query.Result[0] So(ds.AccountId, ShouldEqual, 10) + So(ds.Database, ShouldEqual, "site") }) Convey("Given a datasource", func() {