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
c99aa741
Commit
c99aa741
authored
Mar 10, 2016
by
Carl Bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4322 from utkarshcmu/add-api
#4258 Implemented GetDataSourceIdByName API
parents
8357cdf5
4fbff991
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
4 deletions
+46
-4
docs/sources/http_api/data_source.md
+21
-1
pkg/api/api.go
+2
-3
pkg/api/datasources.go
+19
-0
pkg/api/dtos/models.go
+4
-0
No files found.
docs/sources/http_api/data_source.md
View file @
c99aa741
...
@@ -74,7 +74,7 @@ page_keywords: grafana, admin, http, api, documentation, datasource
...
@@ -74,7 +74,7 @@ page_keywords: grafana, admin, http, api, documentation, datasource
"jsonData":null
"jsonData":null
}
}
## Get a single data source
s
by Name
## Get a single data source by Name
`GET /api/datasources/name/:name`
`GET /api/datasources/name/:name`
...
@@ -107,6 +107,26 @@ page_keywords: grafana, admin, http, api, documentation, datasource
...
@@ -107,6 +107,26 @@ page_keywords: grafana, admin, http, api, documentation, datasource
"jsonData":null
"jsonData":null
}
}
## Get data source Id by Name
`GET /api/datasources/id/:name`
**Example Request**
:
GET /api/datasources/id/test_datasource HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
**Example Response**
:
HTTP/1.1 200
Content-Type: application/json
{
"id":1
}
## Create data source
## Create data source
`POST /api/datasources`
`POST /api/datasources`
...
...
pkg/api/api.go
View file @
c99aa741
...
@@ -171,11 +171,10 @@ func Register(r *macaron.Macaron) {
...
@@ -171,11 +171,10 @@ func Register(r *macaron.Macaron) {
r
.
Put
(
"/:id"
,
bind
(
m
.
UpdateDataSourceCommand
{}),
UpdateDataSource
)
r
.
Put
(
"/:id"
,
bind
(
m
.
UpdateDataSourceCommand
{}),
UpdateDataSource
)
r
.
Delete
(
"/:id"
,
DeleteDataSource
)
r
.
Delete
(
"/:id"
,
DeleteDataSource
)
r
.
Get
(
"/:id"
,
wrap
(
GetDataSourceById
))
r
.
Get
(
"/:id"
,
wrap
(
GetDataSourceById
))
r
.
Get
(
"/name/:name"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
},
reqOrgAdmin
)
r
.
Group
(
"/datasources/name/:name"
,
func
()
{
r
.
Get
(
"/datasources/id/:name"
,
wrap
(
GetDataSourceIdByName
),
reqSignedIn
)
r
.
Get
(
"/"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
r
.
Get
(
"/frontend/settings/"
,
GetFrontendSettings
)
r
.
Get
(
"/frontend/settings/"
,
GetFrontendSettings
)
r
.
Any
(
"/datasources/proxy/:id/*"
,
reqSignedIn
,
ProxyDataSourceRequest
)
r
.
Any
(
"/datasources/proxy/:id/*"
,
reqSignedIn
,
ProxyDataSourceRequest
)
...
...
pkg/api/datasources.go
View file @
c99aa741
...
@@ -116,6 +116,25 @@ func GetDataSourceByName(c *middleware.Context) Response {
...
@@ -116,6 +116,25 @@ func GetDataSourceByName(c *middleware.Context) Response {
return
Json
(
200
,
&
dtos
)
return
Json
(
200
,
&
dtos
)
}
}
// Get /api/datasources/id/:name
func
GetDataSourceIdByName
(
c
*
middleware
.
Context
)
Response
{
query
:=
m
.
GetDataSourceByNameQuery
{
Name
:
c
.
Params
(
":name"
),
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
==
m
.
ErrDataSourceNotFound
{
return
ApiError
(
404
,
"Data source not found"
,
nil
)
}
return
ApiError
(
500
,
"Failed to query datasources"
,
err
)
}
ds
:=
query
.
Result
dtos
:=
dtos
.
AnyId
{
Id
:
ds
.
Id
,
}
return
Json
(
200
,
&
dtos
)
}
func
convertModelToDtos
(
ds
m
.
DataSource
)
dtos
.
DataSource
{
func
convertModelToDtos
(
ds
m
.
DataSource
)
dtos
.
DataSource
{
return
dtos
.
DataSource
{
return
dtos
.
DataSource
{
Id
:
ds
.
Id
,
Id
:
ds
.
Id
,
...
...
pkg/api/dtos/models.go
View file @
c99aa741
...
@@ -10,6 +10,10 @@ import (
...
@@ -10,6 +10,10 @@ import (
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/setting"
)
)
type
AnyId
struct
{
Id
int64
`json:"id"`
}
type
LoginCommand
struct
{
type
LoginCommand
struct
{
User
string
`json:"user" binding:"Required"`
User
string
`json:"user" binding:"Required"`
Password
string
`json:"password" binding:"Required"`
Password
string
`json:"password" binding:"Required"`
...
...
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