mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'cli_compose_download_url'
This commit is contained in:
commit
18c5e90076
@ -4,6 +4,7 @@ import (
|
|||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
|
||||||
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
||||||
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||||
@ -64,30 +65,31 @@ func InstallPlugin(pluginName, version string, c CommandLine) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
url := v.Url
|
|
||||||
commit := v.Commit
|
|
||||||
|
|
||||||
if version == "" {
|
if version == "" {
|
||||||
version = v.Version
|
version = v.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadURL := url + "/archive/" + commit + ".zip"
|
downloadURL := fmt.Sprintf("%s/%s/versions/%s/download",
|
||||||
|
c.GlobalString("repo"),
|
||||||
|
pluginName,
|
||||||
|
version)
|
||||||
|
|
||||||
log.Infof("installing %v @ %v\n", plugin.Id, version)
|
log.Infof("installing %v @ %v\n", plugin.Id, version)
|
||||||
log.Infof("from url: %v\n", downloadURL)
|
log.Infof("from url: %v\n", downloadURL)
|
||||||
log.Infof("on commit: %v\n", commit)
|
|
||||||
log.Infof("into: %v\n", pluginFolder)
|
log.Infof("into: %v\n", pluginFolder)
|
||||||
|
|
||||||
err = downloadFile(plugin.Id, pluginFolder, downloadURL)
|
err = downloadFile(plugin.Id, pluginFolder, downloadURL)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
||||||
|
|
||||||
res, _ := s.ReadPlugin(pluginFolder, pluginName)
|
res, _ := s.ReadPlugin(pluginFolder, pluginName)
|
||||||
|
|
||||||
for _, v := range res.Dependency.Plugins {
|
for _, v := range res.Dependency.Plugins {
|
||||||
InstallPlugin(v.Id, version, c)
|
InstallPlugin(v.Id, version, c)
|
||||||
log.Infof("Installed Dependency: %v ✔\n", v.Id)
|
log.Infof("Installed dependency: %v ✔\n", v.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins
|
var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins
|
||||||
|
|
||||||
var validateLsCommmand = func(pluginDir string) error {
|
var validateLsCommand = func(pluginDir string) error {
|
||||||
if pluginDir == "" {
|
if pluginDir == "" {
|
||||||
return errors.New("missing path flag")
|
return errors.New("missing path flag")
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ var validateLsCommmand = func(pluginDir string) error {
|
|||||||
|
|
||||||
func lsCommand(c CommandLine) error {
|
func lsCommand(c CommandLine) error {
|
||||||
pluginDir := c.GlobalString("path")
|
pluginDir := c.GlobalString("path")
|
||||||
if err := validateLsCommmand(pluginDir); err != nil {
|
if err := validateLsCommand(pluginDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMissingPath(t *testing.T) {
|
func TestMissingPath(t *testing.T) {
|
||||||
var org = validateLsCommmand
|
var org = validateLsCommand
|
||||||
|
|
||||||
Convey("ls command", t, func() {
|
Convey("ls command", t, func() {
|
||||||
validateLsCommmand = org
|
validateLsCommand = org
|
||||||
|
|
||||||
Convey("Missing path", func() {
|
Convey("Missing path", func() {
|
||||||
commandLine := &commandstest.FakeCommandLine{
|
commandLine := &commandstest.FakeCommandLine{
|
||||||
@ -61,7 +61,7 @@ func TestMissingPath(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
validateLsCommmand = func(pluginDir string) error {
|
validateLsCommand = func(pluginDir string) error {
|
||||||
return errors.New("dummie error")
|
return errors.New("dummie error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func main() {
|
|||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
Usage: "url to the plugin repository",
|
Usage: "url to the plugin repository",
|
||||||
Value: "https://raw.githubusercontent.com/grafana/grafana-plugin-repository/master/repo.json",
|
Value: "",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "debug, d",
|
Name: "debug, d",
|
||||||
|
@ -12,7 +12,8 @@ import (
|
|||||||
var IoHelper m.IoUtil = IoUtilImp{}
|
var IoHelper m.IoUtil = IoUtilImp{}
|
||||||
|
|
||||||
func ListAllPlugins(repoUrl string) (m.PluginRepo, error) {
|
func ListAllPlugins(repoUrl string) (m.PluginRepo, error) {
|
||||||
res, _ := goreq.Request{Uri: repoUrl, MaxRedirects: 3}.Do()
|
|
||||||
|
res, _ := goreq.Request{Uri: repoUrl + "/repo", MaxRedirects: 3}.Do()
|
||||||
|
|
||||||
var resp m.PluginRepo
|
var resp m.PluginRepo
|
||||||
err := res.Body.FromJsonTo(&resp)
|
err := res.Body.FromJsonTo(&resp)
|
||||||
|
Loading…
Reference in New Issue
Block a user