Skip to content

Commit 9f9f4e7

Browse files
DanCechtorkelo
authored andcommitted
use new plugin-specific repo route when installing or updating a single plugin (grafana#4992)
1 parent 2f6b00b commit 9f9f4e7

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package commands
22

33
import (
4+
"github.com/fatih/color"
5+
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
46
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
57
)
68

@@ -14,20 +16,17 @@ func upgradeCommand(c CommandLine) error {
1416
return err
1517
}
1618

17-
remotePlugins, err2 := s.ListAllPlugins(c.GlobalString("repo"))
19+
v, err2 := s.GetPlugin(localPlugin.Id, c.GlobalString("repo"))
1820

1921
if err2 != nil {
2022
return err2
2123
}
2224

23-
for _, v := range remotePlugins.Plugins {
24-
if localPlugin.Id == v.Id {
25-
if ShouldUpgrade(localPlugin.Info.Version, v) {
26-
s.RemoveInstalledPlugin(pluginsDir, pluginName)
27-
return InstallPlugin(localPlugin.Id, "", c)
28-
}
29-
}
25+
if ShouldUpgrade(localPlugin.Info.Version, v) {
26+
s.RemoveInstalledPlugin(pluginsDir, pluginName)
27+
return InstallPlugin(localPlugin.Id, "", c)
3028
}
3129

30+
log.Infof("%s %s is up to date \n", color.GreenString("✔"), localPlugin.Id)
3231
return nil
3332
}

pkg/cmd/grafana-cli/services/services.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
4444
}
4545

4646
if res.Id == "" {
47-
return m.InstalledPlugin{}, errors.New("could not read find plugin " + pluginName)
47+
return m.InstalledPlugin{}, errors.New("could not find plugin " + pluginName + " in " + pluginDir)
4848
}
4949

5050
return res, nil
@@ -69,13 +69,21 @@ func RemoveInstalledPlugin(pluginPath, id string) error {
6969
}
7070

7171
func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
72-
resp, _ := ListAllPlugins(repoUrl)
72+
fullUrl := repoUrl + "/repo/" + pluginId
7373

74-
for _, i := range resp.Plugins {
75-
if i.Id == pluginId {
76-
return i, nil
77-
}
74+
res, err := goreq.Request{Uri: fullUrl, MaxRedirects: 3}.Do()
75+
if err != nil {
76+
return m.Plugin{}, err
77+
}
78+
if res.StatusCode != 200 {
79+
return m.Plugin{}, fmt.Errorf("Could not access %s statuscode %v", fullUrl, res.StatusCode)
7880
}
7981

80-
return m.Plugin{}, errors.New("could not find plugin named \"" + pluginId + "\"")
82+
var resp m.Plugin
83+
err = res.Body.FromJsonTo(&resp)
84+
if err != nil {
85+
return m.Plugin{}, errors.New("Could not load plugin data")
86+
}
87+
88+
return resp, nil
8189
}

0 commit comments

Comments
 (0)