Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
adf4e72c
Commit
adf4e72c
authored
Dec 17, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More general backend work, in the middle of the night... Zzzz
parent
c7ed348e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
5 deletions
+49
-5
grafana
+1
-1
pkg/api/api.go
+2
-2
pkg/api/api_datasources.go
+22
-2
pkg/api/dtos/models.go
+13
-0
pkg/middleware/middleware.go
+8
-0
pkg/stores/sqlstore/sqlstore_test.go
+3
-0
No files found.
grafana
@
0e970307
Subproject commit
adb1502e728e5a312a6e4dc680edbd1f75219ea1
Subproject commit
0e970307160dfed9b09f6d1bf06dd49ff38035b7
pkg/api/api.go
View file @
adf4e72c
...
...
@@ -27,8 +27,8 @@ func Register(m *macaron.Macaron) {
// datasources
m
.
Get
(
"/admin/datasources/"
,
auth
,
Index
)
m
.
Get
(
"/api/admin/datasource/list"
,
auth
,
GetDataSources
)
m
.
Post
(
"/api/admin/datasource/add"
,
auth
,
AddDataSource
)
m
.
Get
(
"/api/admin/datasource
s
/list"
,
auth
,
GetDataSources
)
m
.
Post
(
"/api/admin/datasource
s
/add"
,
auth
,
AddDataSource
)
// user register
m
.
Get
(
"/register/*_"
,
Index
)
...
...
pkg/api/api_datasources.go
View file @
adf4e72c
package
api
import
(
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
...
...
@@ -14,21 +15,40 @@ func GetDataSources(c *middleware.Context) {
c
.
JsonApiErr
(
500
,
"Failed to query datasources"
,
err
)
return
}
result
:=
make
([]
*
dtos
.
DataSource
,
len
(
query
.
Resp
))
for
_
,
ds
:=
range
query
.
Resp
{
result
=
append
(
result
,
&
dtos
.
DataSource
{
Id
:
ds
.
Id
,
AccountId
:
ds
.
AccountId
,
Name
:
ds
.
Name
,
Url
:
ds
.
Url
,
Type
:
ds
.
Type
,
Access
:
ds
.
Access
,
Password
:
ds
.
Password
,
User
:
ds
.
User
,
BasicAuth
:
ds
.
BasicAuth
,
})
}
c
.
JSON
(
200
,
result
)
}
func
AddDataSource
(
c
*
middleware
.
Context
)
{
cmd
:=
m
.
AddDataSourceCommand
{}
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"
bad request
"
,
nil
)
c
.
JsonApiErr
(
400
,
"
Validation failed
"
,
nil
)
return
}
cmd
.
AccountId
=
c
.
Account
.
Id
err
:=
bus
.
Dispatch
(
&
cmd
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to add datasource"
,
err
)
return
}
c
.
Status
(
204
)
c
.
JsonOK
(
"Datasource added"
)
}
pkg/api/dtos/models.go
View file @
adf4e72c
...
...
@@ -38,6 +38,19 @@ type Collaborator struct {
Role
string
`json:"role"`
}
type
DataSource
struct
{
Id
int64
`json:"id"`
AccountId
int64
`json:"accountId"`
Name
string
`json:"name"`
Type
models
.
DsType
`json:"type"`
Access
models
.
DsAccess
`json:"access"`
Url
string
`json:"url"`
Password
string
`json:"password"`
User
string
`json:"user"`
BasicAuth
bool
`json:"basicAuth"`
}
func
NewCurrentUser
(
account
*
models
.
Account
)
*
CurrentUser
{
model
:=
&
CurrentUser
{}
if
account
!=
nil
{
...
...
pkg/middleware/middleware.go
View file @
adf4e72c
...
...
@@ -56,6 +56,14 @@ func (ctx *Context) Handle(status int, title string, err error) {
ctx
.
HTML
(
status
,
strconv
.
Itoa
(
status
))
}
func
(
ctx
*
Context
)
JsonOK
(
message
string
)
{
resp
:=
make
(
map
[
string
]
interface
{})
resp
[
"message"
]
=
message
ctx
.
JSON
(
200
,
resp
)
}
func
(
ctx
*
Context
)
JsonApiErr
(
status
int
,
message
string
,
err
error
)
{
resp
:=
make
(
map
[
string
]
interface
{})
...
...
pkg/stores/sqlstore/sqlstore_test.go
View file @
adf4e72c
...
...
@@ -47,6 +47,9 @@ func TestDataAccess(t *testing.T) {
So
(
len
(
query
.
Resp
),
ShouldEqual
,
1
)
ds
:=
query
.
Resp
[
0
]
So
(
ds
.
AccountId
,
ShouldEqual
,
10
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment