diff --git a/pkg/plugins/api_plugin.go b/pkg/plugins/api_plugin.go new file mode 100644 index 00000000000..b4296479ec1 --- /dev/null +++ b/pkg/plugins/api_plugin.go @@ -0,0 +1,31 @@ +package plugins + +import ( + "encoding/json" + "strings" + + "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"` +} + +type ApiPlugin struct { + PluginBase + Routes []*ApiPluginRoute `json:"routes"` +} + +func (app *ApiPlugin) Load(decoder *json.Decoder, pluginDir string) error { + if err := decoder.Decode(&app); err != nil { + return err + } + + ApiPlugins[app.Id] = app + return nil +} diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 375bdf1a52c..69230cac629 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -73,3 +73,12 @@ func NewEnabledPlugins() EnabledPlugins { Apps: make([]*AppPlugin, 0), } } + +func (app *ApiPlugin) Load(decoder *json.Decoder, pluginDir string) error { + if err := decoder.Decode(&app); err != nil { + return err + } + + ApiPlugins[app.Id] = app + return nil +}