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
5a6981e7
Commit
5a6981e7
authored
Nov 27, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3354 from raintank/externalPlugin
Merge changes to external-plugins branch
parents
bd8f5e9b
79d29db1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
24 deletions
+49
-24
pkg/api/externalplugin.go
+17
-18
pkg/api/index.go
+22
-1
pkg/plugins/models.go
+5
-3
pkg/plugins/plugins_test.go
+5
-2
No files found.
pkg/api/externalplugin.go
View file @
5a6981e7
...
@@ -9,33 +9,32 @@ import (
...
@@ -9,33 +9,32 @@ import (
"github.com/Unknwon/macaron"
"github.com/Unknwon/macaron"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/util"
)
)
func
InitExternalPluginRoutes
(
r
*
macaron
.
Macaron
)
{
func
InitExternalPluginRoutes
(
r
*
macaron
.
Macaron
)
{
/*
// Handle Auth and role requirements
if route.ReqSignedIn {
c.Invoke(middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true}))
}
if route.ReqGrafanaAdmin {
c.Invoke(middleware.Auth(&middleware.AuthOptions{ReqSignedIn: true, ReqGrafanaAdmin: true}))
}
if route.ReqRole != nil {
if *route.ReqRole == m.ROLE_EDITOR {
c.Invoke(middleware.RoleAuth(m.ROLE_EDITOR, m.ROLE_ADMIN))
}
if *route.ReqRole == m.ROLE_ADMIN {
c.Invoke(middleware.RoleAuth(m.ROLE_ADMIN))
}
}
*/
for
_
,
plugin
:=
range
plugins
.
ExternalPlugins
{
for
_
,
plugin
:=
range
plugins
.
ExternalPlugins
{
log
.
Info
(
"Plugin: Adding proxy routes for backend plugin"
)
log
.
Info
(
"Plugin: Adding proxy routes for backend plugin"
)
for
_
,
route
:=
range
plugin
.
Routes
{
for
_
,
route
:=
range
plugin
.
Routes
{
url
:=
util
.
JoinUrlFragments
(
"/api/plugin-proxy/"
,
route
.
Path
)
url
:=
util
.
JoinUrlFragments
(
"/api/plugin-proxy/"
,
route
.
Path
)
r
.
Route
(
url
,
route
.
Method
,
ExternalPlugin
(
route
.
Url
))
handlers
:=
make
([]
macaron
.
Handler
,
0
)
if
route
.
ReqSignedIn
{
handlers
=
append
(
handlers
,
middleware
.
Auth
(
&
middleware
.
AuthOptions
{
ReqSignedIn
:
true
}))
}
if
route
.
ReqGrafanaAdmin
{
handlers
=
append
(
handlers
,
middleware
.
Auth
(
&
middleware
.
AuthOptions
{
ReqSignedIn
:
true
,
ReqGrafanaAdmin
:
true
}))
}
if
route
.
ReqSignedIn
&&
route
.
ReqRole
!=
""
{
if
route
.
ReqRole
==
m
.
ROLE_ADMIN
{
handlers
=
append
(
handlers
,
middleware
.
RoleAuth
(
m
.
ROLE_ADMIN
))
}
else
if
route
.
ReqRole
==
m
.
ROLE_EDITOR
{
handlers
=
append
(
handlers
,
middleware
.
RoleAuth
(
m
.
ROLE_EDITOR
,
m
.
ROLE_ADMIN
))
}
}
handlers
=
append
(
handlers
,
ExternalPlugin
(
route
.
Url
))
r
.
Route
(
url
,
route
.
Method
,
handlers
...
)
log
.
Info
(
"Plugin: Adding route %s"
,
url
)
log
.
Info
(
"Plugin: Adding route %s"
,
url
)
}
}
}
}
...
...
pkg/api/index.go
View file @
5a6981e7
...
@@ -70,7 +70,28 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
...
@@ -70,7 +70,28 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
data
.
PluginCss
=
append
(
data
.
PluginCss
,
css
.
Href
)
data
.
PluginCss
=
append
(
data
.
PluginCss
,
css
.
Href
)
}
}
for
_
,
item
:=
range
plugin
.
MainNavLinks
{
for
_
,
item
:=
range
plugin
.
MainNavLinks
{
data
.
MainNavLinks
=
append
(
data
.
MainNavLinks
,
&
dtos
.
NavLink
{
Text
:
item
.
Text
,
Href
:
item
.
Href
,
Icon
:
item
.
Icon
})
// only show menu items for the specified roles.
var
validRoles
[]
m
.
RoleType
if
string
(
item
.
ReqRole
)
==
""
||
item
.
ReqRole
==
m
.
ROLE_VIEWER
{
validRoles
=
[]
m
.
RoleType
{
m
.
ROLE_ADMIN
,
m
.
ROLE_EDITOR
,
m
.
ROLE_VIEWER
}
}
else
if
item
.
ReqRole
==
m
.
ROLE_EDITOR
{
validRoles
=
[]
m
.
RoleType
{
m
.
ROLE_ADMIN
,
m
.
ROLE_EDITOR
}
}
else
if
item
.
ReqRole
==
m
.
ROLE_ADMIN
{
validRoles
=
[]
m
.
RoleType
{
m
.
ROLE_ADMIN
}
}
ok
:=
true
if
len
(
validRoles
)
>
0
{
ok
=
false
for
_
,
role
:=
range
validRoles
{
if
role
==
c
.
OrgRole
{
ok
=
true
break
}
}
}
if
ok
{
data
.
MainNavLinks
=
append
(
data
.
MainNavLinks
,
&
dtos
.
NavLink
{
Text
:
item
.
Text
,
Href
:
item
.
Href
,
Icon
:
item
.
Icon
})
}
}
}
}
}
...
...
pkg/plugins/models.go
View file @
5a6981e7
...
@@ -41,9 +41,10 @@ type ExternalPluginJs struct {
...
@@ -41,9 +41,10 @@ type ExternalPluginJs struct {
}
}
type
ExternalPluginNavLink
struct
{
type
ExternalPluginNavLink
struct
{
Text
string
`json:"text"`
Text
string
`json:"text"`
Icon
string
`json:"icon"`
Icon
string
`json:"icon"`
Href
string
`json:"href"`
Href
string
`json:"href"`
ReqRole
models
.
RoleType
`json:"reqRole"`
}
}
type
ExternalPluginCss
struct
{
type
ExternalPluginCss
struct
{
...
@@ -51,6 +52,7 @@ type ExternalPluginCss struct {
...
@@ -51,6 +52,7 @@ type ExternalPluginCss struct {
}
}
type
ExternalPlugin
struct
{
type
ExternalPlugin
struct
{
Type
string
`json:"type"`
Routes
[]
*
ExternalPluginRoute
`json:"routes"`
Routes
[]
*
ExternalPluginRoute
`json:"routes"`
Js
[]
*
ExternalPluginJs
`json:"js"`
Js
[]
*
ExternalPluginJs
`json:"js"`
Css
[]
*
ExternalPluginCss
`json:"css"`
Css
[]
*
ExternalPluginCss
`json:"css"`
...
...
pkg/plugins/plugins_test.go
View file @
5a6981e7
...
@@ -4,14 +4,17 @@ import (
...
@@ -4,14 +4,17 @@ import (
"path/filepath"
"path/filepath"
"testing"
"testing"
"github.com/grafana/grafana/pkg/setting"
.
"github.com/smartystreets/goconvey/convey"
.
"github.com/smartystreets/goconvey/convey"
"gopkg.in/ini.v1"
)
)
func
TestPluginScans
(
t
*
testing
.
T
)
{
func
TestPluginScans
(
t
*
testing
.
T
)
{
Convey
(
"When scaning for plugins"
,
t
,
func
()
{
Convey
(
"When scaning for plugins"
,
t
,
func
()
{
path
,
_
:=
filepath
.
Abs
(
"../../public/app/plugins"
)
setting
.
StaticRootPath
,
_
=
filepath
.
Abs
(
"../../public/"
)
err
:=
scan
(
path
)
setting
.
Cfg
=
ini
.
Empty
()
err
:=
Init
()
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
So
(
len
(
DataSources
),
ShouldBeGreaterThan
,
1
)
...
...
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