Plugins: Refactor Grafana and Plugin version update checkers (#44529)
* refactor * rework plugin update checking * make smarter * simplify * fix linter issue * make use of mutex * apply feedback to simplify * format imports * fix tests
This commit is contained in:
+12
-4
@@ -74,8 +74,6 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) response.Response {
|
||||
Category: pluginDef.Category,
|
||||
Info: pluginDef.Info,
|
||||
Dependencies: pluginDef.Dependencies,
|
||||
LatestVersion: pluginDef.GrafanaComVersion,
|
||||
HasUpdate: pluginDef.GrafanaComHasUpdate,
|
||||
DefaultNavUrl: pluginDef.DefaultNavURL,
|
||||
State: pluginDef.State,
|
||||
Signature: pluginDef.Signature,
|
||||
@@ -83,6 +81,12 @@ func (hs *HTTPServer) GetPluginList(c *models.ReqContext) response.Response {
|
||||
SignatureOrg: pluginDef.SignatureOrg,
|
||||
}
|
||||
|
||||
update, exists := hs.pluginsUpdateChecker.HasUpdate(c.Req.Context(), pluginDef.ID)
|
||||
if exists {
|
||||
listItem.LatestVersion = update
|
||||
listItem.HasUpdate = true
|
||||
}
|
||||
|
||||
if pluginSetting, exists := pluginSettingsMap[pluginDef.ID]; exists {
|
||||
listItem.Enabled = pluginSetting.Enabled
|
||||
listItem.Pinned = pluginSetting.Pinned
|
||||
@@ -127,8 +131,6 @@ func (hs *HTTPServer) GetPluginSettingByID(c *models.ReqContext) response.Respon
|
||||
BaseUrl: plugin.BaseURL,
|
||||
Module: plugin.Module,
|
||||
DefaultNavUrl: plugin.DefaultNavURL,
|
||||
LatestVersion: plugin.GrafanaComVersion,
|
||||
HasUpdate: plugin.GrafanaComHasUpdate,
|
||||
State: plugin.State,
|
||||
Signature: plugin.Signature,
|
||||
SignatureType: plugin.SignatureType,
|
||||
@@ -151,6 +153,12 @@ func (hs *HTTPServer) GetPluginSettingByID(c *models.ReqContext) response.Respon
|
||||
dto.JsonData = query.Result.JsonData
|
||||
}
|
||||
|
||||
update, exists := hs.pluginsUpdateChecker.HasUpdate(c.Req.Context(), plugin.ID)
|
||||
if exists {
|
||||
dto.LatestVersion = update
|
||||
dto.HasUpdate = true
|
||||
}
|
||||
|
||||
return response.JSON(200, dto)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user