2016-01-09 16:34:20 -06:00
|
|
|
package plugins
|
|
|
|
|
2017-08-31 07:05:52 -05:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
2016-01-09 16:34:20 -06:00
|
|
|
|
|
|
|
type DataSourcePlugin struct {
|
|
|
|
FrontendPluginBase
|
2017-09-04 07:09:02 -05:00
|
|
|
Annotations bool `json:"annotations"`
|
|
|
|
Metrics bool `json:"metrics"`
|
|
|
|
Alerting bool `json:"alerting"`
|
|
|
|
QueryOptions map[string]bool `json:"queryOptions,omitempty"`
|
|
|
|
BuiltIn bool `json:"builtIn,omitempty"`
|
|
|
|
Mixed bool `json:"mixed,omitempty"`
|
|
|
|
HasQueryHelp bool `json:"hasQueryHelp,omitempty"`
|
|
|
|
Routes []*AppPluginRoute `json:"routes"`
|
2016-01-09 16:34:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
|
|
|
|
if err := decoder.Decode(&p); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-02-10 04:03:12 -06:00
|
|
|
if err := p.registerPlugin(pluginDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-01-09 16:34:20 -06:00
|
|
|
|
2017-08-31 07:05:52 -05:00
|
|
|
// look for help markdown
|
2017-09-01 08:57:02 -05:00
|
|
|
helpPath := filepath.Join(p.PluginDir, "QUERY_HELP.md")
|
2017-08-31 07:05:52 -05:00
|
|
|
if _, err := os.Stat(helpPath); os.IsNotExist(err) {
|
2017-09-01 08:57:02 -05:00
|
|
|
helpPath = filepath.Join(p.PluginDir, "query_help.md")
|
2017-08-31 07:05:52 -05:00
|
|
|
}
|
|
|
|
if _, err := os.Stat(helpPath); err == nil {
|
2017-09-01 08:57:02 -05:00
|
|
|
p.HasQueryHelp = true
|
2017-08-31 07:05:52 -05:00
|
|
|
}
|
|
|
|
|
2016-02-10 04:03:12 -06:00
|
|
|
DataSources[p.Id] = p
|
2016-01-09 16:34:20 -06:00
|
|
|
return nil
|
|
|
|
}
|