mirror of https://github.com/grafana/grafana
Plugins: Move store and plugin dto to pluginsintegration (#74655)
move store and plugin dtopull/74566/head^2
parent
499b02b3c6
commit
e855efb13d
@ -0,0 +1,38 @@ |
||||
package pluginstore |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/grafana/grafana/pkg/plugins" |
||||
) |
||||
|
||||
type FakePluginStore struct { |
||||
PluginList []Plugin |
||||
} |
||||
|
||||
func (pr *FakePluginStore) Plugin(_ context.Context, pluginID string) (Plugin, bool) { |
||||
for _, v := range pr.PluginList { |
||||
if v.ID == pluginID { |
||||
return v, true |
||||
} |
||||
} |
||||
|
||||
return Plugin{}, false |
||||
} |
||||
|
||||
func (pr *FakePluginStore) Plugins(_ context.Context, pluginTypes ...plugins.Type) []Plugin { |
||||
var result []Plugin |
||||
if len(pluginTypes) == 0 { |
||||
pluginTypes = plugins.PluginTypes |
||||
} |
||||
|
||||
for _, v := range pr.PluginList { |
||||
for _, t := range pluginTypes { |
||||
if v.Type == t { |
||||
result = append(result, v) |
||||
} |
||||
} |
||||
} |
||||
|
||||
return result |
||||
} |
@ -0,0 +1,78 @@ |
||||
package pluginstore |
||||
|
||||
import ( |
||||
"github.com/grafana/grafana-plugin-sdk-go/backend" |
||||
|
||||
"github.com/grafana/grafana/pkg/plugins" |
||||
) |
||||
|
||||
type Plugin struct { |
||||
plugins.JSONData |
||||
|
||||
fs plugins.FS |
||||
supportsStreaming bool |
||||
|
||||
Class plugins.Class |
||||
|
||||
// App fields
|
||||
IncludedInAppID string |
||||
DefaultNavURL string |
||||
Pinned bool |
||||
|
||||
// Signature fields
|
||||
Signature plugins.SignatureStatus |
||||
SignatureType plugins.SignatureType |
||||
SignatureOrg string |
||||
SignatureError *plugins.SignatureError |
||||
|
||||
// SystemJS fields
|
||||
Module string |
||||
BaseURL string |
||||
|
||||
AngularDetected bool |
||||
|
||||
// This will be moved to plugin.json when we have general support in gcom
|
||||
Alias string `json:"alias,omitempty"` |
||||
} |
||||
|
||||
func (p Plugin) SupportsStreaming() bool { |
||||
return p.supportsStreaming |
||||
} |
||||
|
||||
func (p Plugin) Base() string { |
||||
return p.fs.Base() |
||||
} |
||||
|
||||
func (p Plugin) IsApp() bool { |
||||
return p.Type == plugins.TypeApp |
||||
} |
||||
|
||||
func (p Plugin) IsCorePlugin() bool { |
||||
return p.Class == plugins.ClassCore |
||||
} |
||||
|
||||
func ToGrafanaDTO(p *plugins.Plugin) Plugin { |
||||
supportsStreaming := false |
||||
pc, exists := p.Client() |
||||
if exists && pc != nil && pc.(backend.StreamHandler) != nil { |
||||
supportsStreaming = false |
||||
} |
||||
|
||||
return Plugin{ |
||||
fs: p.FS, |
||||
supportsStreaming: supportsStreaming, |
||||
Class: p.Class, |
||||
JSONData: p.JSONData, |
||||
IncludedInAppID: p.IncludedInAppID, |
||||
DefaultNavURL: p.DefaultNavURL, |
||||
Pinned: p.Pinned, |
||||
Signature: p.Signature, |
||||
SignatureType: p.SignatureType, |
||||
SignatureOrg: p.SignatureOrg, |
||||
SignatureError: p.SignatureError, |
||||
Module: p.Module, |
||||
BaseURL: p.BaseURL, |
||||
AngularDetected: p.AngularDetected, |
||||
Alias: p.Alias, |
||||
} |
||||
} |
Loading…
Reference in new issue