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
1a708da1
Commit
1a708da1
authored
Jan 21, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3821 from raintank/apiPlugin
merge apiPlugins with appPlugins
parents
d9d4e6c8
f94599cd
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
84 deletions
+33
-84
pkg/api/api.go
+1
-1
pkg/api/app_routes.go
+13
-19
pkg/plugins/api_plugin.go
+0
-38
pkg/plugins/app_plugin.go
+19
-15
pkg/plugins/models.go
+0
-2
pkg/plugins/plugins.go
+0
-3
pkg/plugins/queries.go
+0
-6
No files found.
pkg/api/api.go
View file @
1a708da1
...
...
@@ -215,7 +215,7 @@ func Register(r *macaron.Macaron) {
// rendering
r
.
Get
(
"/render/*"
,
reqSignedIn
,
RenderToPng
)
InitAp
i
PluginRoutes
(
r
)
InitAp
p
PluginRoutes
(
r
)
r
.
NotFound
(
NotFoundHandler
)
}
pkg/api/ap
i_plugin
.go
→
pkg/api/ap
p_routes
.go
View file @
1a708da1
...
...
@@ -19,10 +19,10 @@ import (
"github.com/grafana/grafana/pkg/util"
)
func
InitApiPluginRoutes
(
r
*
macaron
.
Macaron
)
{
for
_
,
plugin
:=
range
plugins
.
ApiPlugins
{
log
.
Info
(
"Plugin: Adding proxy routes for api plugin"
)
func
InitAppPluginRoutes
(
r
*
macaron
.
Macaron
)
{
for
_
,
plugin
:=
range
plugins
.
Apps
{
for
_
,
route
:=
range
plugin
.
Routes
{
log
.
Info
(
"Plugin: Adding proxy route for app plugin"
)
url
:=
util
.
JoinUrlFragments
(
"/api/plugin-proxy/"
,
route
.
Path
)
handlers
:=
make
([]
macaron
.
Handler
,
0
)
if
route
.
ReqSignedIn
{
...
...
@@ -38,24 +38,24 @@ func InitApiPluginRoutes(r *macaron.Macaron) {
handlers
=
append
(
handlers
,
middleware
.
RoleAuth
(
m
.
ROLE_EDITOR
,
m
.
ROLE_ADMIN
))
}
}
handlers
=
append
(
handlers
,
Ap
iPlugin
(
route
,
plugin
.
IncludedInApp
Id
))
handlers
=
append
(
handlers
,
Ap
pPluginRoute
(
route
,
plugin
.
Id
))
r
.
Route
(
url
,
route
.
Method
,
handlers
...
)
log
.
Info
(
"Plugin: Adding route %s"
,
url
)
}
}
}
func
Ap
iPlugin
(
route
*
plugins
.
ApiPluginRoute
,
includedInA
ppId
string
)
macaron
.
Handler
{
func
Ap
pPluginRoute
(
route
*
plugins
.
AppPluginRoute
,
a
ppId
string
)
macaron
.
Handler
{
return
func
(
c
*
middleware
.
Context
)
{
path
:=
c
.
Params
(
"*"
)
proxy
:=
NewApiPluginProxy
(
c
,
path
,
route
,
includedInA
ppId
)
proxy
:=
NewApiPluginProxy
(
c
,
path
,
route
,
a
ppId
)
proxy
.
Transport
=
dataProxyTransport
proxy
.
ServeHTTP
(
c
.
Resp
,
c
.
Req
.
Request
)
}
}
func
NewApiPluginProxy
(
ctx
*
middleware
.
Context
,
proxyPath
string
,
route
*
plugins
.
Ap
iPluginRoute
,
includedInA
ppId
string
)
*
httputil
.
ReverseProxy
{
func
NewApiPluginProxy
(
ctx
*
middleware
.
Context
,
proxyPath
string
,
route
*
plugins
.
Ap
pPluginRoute
,
a
ppId
string
)
*
httputil
.
ReverseProxy
{
targetUrl
,
_
:=
url
.
Parse
(
route
.
Url
)
director
:=
func
(
req
*
http
.
Request
)
{
...
...
@@ -87,21 +87,15 @@ func NewApiPluginProxy(ctx *middleware.Context, proxyPath string, route *plugins
return
}
jsonData
:=
make
(
map
[
string
]
interface
{})
//lookup appSettings
query
:=
m
.
GetAppSettingByAppIdQuery
{
OrgId
:
ctx
.
OrgId
,
AppId
:
appId
}
if
includedInAppId
!=
""
{
//lookup appSettings
query
:=
m
.
GetAppSettingByAppIdQuery
{
OrgId
:
ctx
.
OrgId
,
AppId
:
includedInAppId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
ctx
.
JsonApiErr
(
500
,
"failed to get AppSettings of includedAppId."
,
err
)
return
}
jsonData
=
query
.
Result
.
JsonData
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
ctx
.
JsonApiErr
(
500
,
"failed to get AppSettings."
,
err
)
return
}
err
=
t
.
Execute
(
&
contentBuf
,
j
sonData
)
err
=
t
.
Execute
(
&
contentBuf
,
query
.
Result
.
J
sonData
)
if
err
!=
nil
{
ctx
.
JsonApiErr
(
500
,
fmt
.
Sprintf
(
"failed to execute header content template for header %s."
,
header
.
Name
),
err
)
return
...
...
pkg/plugins/api_plugin.go
deleted
100644 → 0
View file @
d9d4e6c8
package
plugins
import
(
"encoding/json"
"github.com/grafana/grafana/pkg/models"
)
type
ApiPluginRoute
struct
{
Path
string
`json:"path"`
Method
string
`json:"method"`
ReqSignedIn
bool
`json:"reqSignedIn"`
ReqGrafanaAdmin
bool
`json:"reqGrafanaAdmin"`
ReqRole
models
.
RoleType
`json:"reqRole"`
Url
string
`json:"url"`
Headers
[]
ApiPluginHeader
`json:"headers"`
}
type
ApiPlugin
struct
{
PluginBase
Routes
[]
*
ApiPluginRoute
`json:"routes"`
}
type
ApiPluginHeader
struct
{
Name
string
`json:"name"`
Content
string
`json:"content"`
}
func
(
app
*
ApiPlugin
)
Load
(
decoder
*
json
.
Decoder
,
pluginDir
string
)
error
{
if
err
:=
decoder
.
Decode
(
&
app
);
err
!=
nil
{
return
err
}
app
.
PluginDir
=
pluginDir
ApiPlugins
[
app
.
Id
]
=
app
return
nil
}
pkg/plugins/app_plugin.go
View file @
1a708da1
...
...
@@ -26,14 +26,30 @@ type AppIncludeInfo struct {
type
AppPlugin
struct
{
FrontendPluginBase
Css
*
AppPluginCss
`json:"css"`
Pages
[]
AppPluginPage
`json:"pages"`
Includes
[]
AppIncludeInfo
`json:"-"`
Css
*
AppPluginCss
`json:"css"`
Pages
[]
AppPluginPage
`json:"pages"`
Routes
[]
*
AppPluginRoute
`json:"routes"`
Includes
[]
AppIncludeInfo
`json:"-"`
Pinned
bool
`json:"-"`
Enabled
bool
`json:"-"`
}
type
AppPluginRoute
struct
{
Path
string
`json:"path"`
Method
string
`json:"method"`
ReqSignedIn
bool
`json:"reqSignedIn"`
ReqGrafanaAdmin
bool
`json:"reqGrafanaAdmin"`
ReqRole
models
.
RoleType
`json:"reqRole"`
Url
string
`json:"url"`
Headers
[]
AppPluginRouteHeader
`json:"headers"`
}
type
AppPluginRouteHeader
struct
{
Name
string
`json:"name"`
Content
string
`json:"content"`
}
func
(
app
*
AppPlugin
)
Load
(
decoder
*
json
.
Decoder
,
pluginDir
string
)
error
{
if
err
:=
decoder
.
Decode
(
&
app
);
err
!=
nil
{
return
err
...
...
@@ -59,18 +75,6 @@ func (app *AppPlugin) Load(decoder *json.Decoder, pluginDir string) error {
}
}
// check if we have child apiPlugins
for
_
,
plugin
:=
range
ApiPlugins
{
if
strings
.
HasPrefix
(
plugin
.
PluginDir
,
app
.
PluginDir
)
{
plugin
.
IncludedInAppId
=
app
.
Id
app
.
Includes
=
append
(
app
.
Includes
,
AppIncludeInfo
{
Name
:
plugin
.
Name
,
Id
:
plugin
.
Id
,
Type
:
plugin
.
Type
,
})
}
}
Apps
[
app
.
Id
]
=
app
return
nil
}
pkg/plugins/models.go
View file @
1a708da1
...
...
@@ -45,7 +45,6 @@ type PluginStaticRoute struct {
type
EnabledPlugins
struct
{
Panels
[]
*
PanelPlugin
DataSources
map
[
string
]
*
DataSourcePlugin
ApiList
[]
*
ApiPlugin
Apps
[]
*
AppPlugin
}
...
...
@@ -53,7 +52,6 @@ func NewEnabledPlugins() EnabledPlugins {
return
EnabledPlugins
{
Panels
:
make
([]
*
PanelPlugin
,
0
),
DataSources
:
make
(
map
[
string
]
*
DataSourcePlugin
),
ApiList
:
make
([]
*
ApiPlugin
,
0
),
Apps
:
make
([]
*
AppPlugin
,
0
),
}
}
pkg/plugins/plugins.go
View file @
1a708da1
...
...
@@ -17,7 +17,6 @@ import (
var
(
DataSources
map
[
string
]
*
DataSourcePlugin
Panels
map
[
string
]
*
PanelPlugin
ApiPlugins
map
[
string
]
*
ApiPlugin
StaticRoutes
[]
*
PluginStaticRoute
Apps
map
[
string
]
*
AppPlugin
PluginTypes
map
[
string
]
interface
{}
...
...
@@ -30,14 +29,12 @@ type PluginScanner struct {
func
Init
()
error
{
DataSources
=
make
(
map
[
string
]
*
DataSourcePlugin
)
ApiPlugins
=
make
(
map
[
string
]
*
ApiPlugin
)
StaticRoutes
=
make
([]
*
PluginStaticRoute
,
0
)
Panels
=
make
(
map
[
string
]
*
PanelPlugin
)
Apps
=
make
(
map
[
string
]
*
AppPlugin
)
PluginTypes
=
map
[
string
]
interface
{}{
"panel"
:
PanelPlugin
{},
"datasource"
:
DataSourcePlugin
{},
"api"
:
ApiPlugin
{},
"app"
:
AppPlugin
{},
}
...
...
pkg/plugins/queries.go
View file @
1a708da1
...
...
@@ -68,11 +68,5 @@ func GetEnabledPlugins(orgId int64) (*EnabledPlugins, error) {
}
}
for
_
,
api
:=
range
ApiPlugins
{
if
isPluginEnabled
(
api
.
IncludedInAppId
)
{
enabledPlugins
.
ApiList
=
append
(
enabledPlugins
.
ApiList
,
api
)
}
}
return
&
enabledPlugins
,
nil
}
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