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:
Will Browne
2023-03-29 11:55:55 +01:00
committed by GitHub
parent 562d8dba5d
commit 7bbe255150
13 changed files with 212 additions and 189 deletions

View File

@ -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
}