mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 02:22:43 +08:00
Plugins: Add file store abstraction for handling plugin files (#65432)
* add file store * fix markdown fetch bug * add markdown tests * fix var name
This commit is contained in:
@ -95,25 +95,6 @@ func (p PluginDTO) IsCorePlugin() bool {
|
||||
return p.Class == Core
|
||||
}
|
||||
|
||||
func (p PluginDTO) File(name string) (fs.File, error) {
|
||||
cleanPath, err := util.CleanRelativePath(name)
|
||||
if err != nil {
|
||||
// CleanRelativePath should clean and make the path relative so this is not expected to fail
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.fs == nil {
|
||||
return nil, ErrFileNotExist
|
||||
}
|
||||
|
||||
f, err := p.fs.Open(cleanPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// JSONData represents the plugin's plugin.json
|
||||
type JSONData struct {
|
||||
// Common settings
|
||||
@ -325,6 +306,25 @@ func (p *Plugin) RunStream(ctx context.Context, req *backend.RunStreamRequest, s
|
||||
return pluginClient.RunStream(ctx, req, sender)
|
||||
}
|
||||
|
||||
func (p *Plugin) File(name string) (fs.File, error) {
|
||||
cleanPath, err := util.CleanRelativePath(name)
|
||||
if err != nil {
|
||||
// CleanRelativePath should clean and make the path relative so this is not expected to fail
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.FS == nil {
|
||||
return nil, ErrFileNotExist
|
||||
}
|
||||
|
||||
f, err := p.FS.Open(cleanPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (p *Plugin) RegisterClient(c backendplugin.Plugin) {
|
||||
p.client = c
|
||||
}
|
||||
|
Reference in New Issue
Block a user