CLI: Reduce memory usage for plugin installation (#19639)

* grafana-cli: use tmp file when downloading plugin install file
This commit is contained in:
Olivier Lemasle
2019-11-06 13:42:58 +01:00
committed by Arve Knudsen
parent 46a4118461
commit b4712ec4b9
6 changed files with 115 additions and 65 deletions

View File

@ -1,12 +1,14 @@
package commandstest
import (
"os"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
)
type FakeGrafanaComClient struct {
GetPluginFunc func(pluginId, repoUrl string) (models.Plugin, error)
DownloadFileFunc func(pluginName, filePath, url string, checksum string) (content []byte, err error)
DownloadFileFunc func(pluginName string, tmpFile *os.File, url string, checksum string) (err error)
ListAllPluginsFunc func(repoUrl string) (models.PluginRepo, error)
}
@ -18,12 +20,12 @@ func (client *FakeGrafanaComClient) GetPlugin(pluginId, repoUrl string) (models.
return models.Plugin{}, nil
}
func (client *FakeGrafanaComClient) DownloadFile(pluginName, filePath, url string, checksum string) (content []byte, err error) {
func (client *FakeGrafanaComClient) DownloadFile(pluginName string, tmpFile *os.File, url string, checksum string) (err error) {
if client.DownloadFileFunc != nil {
return client.DownloadFileFunc(pluginName, filePath, url, checksum)
return client.DownloadFileFunc(pluginName, tmpFile, url, checksum)
}
return make([]byte, 0), nil
return nil
}
func (client *FakeGrafanaComClient) ListAllPlugins(repoUrl string) (models.PluginRepo, error) {