MM-28861 Marketplace feature flags (#16451)
* Installing plugins specified by feature flags using the marketplace. * Switch back to using getplugins client. * Respect disabling automatic installation of pluings. * pluginid -> plugin_id * Debug logs for enable plugin error Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
987eddce1f
Коммит
b40a93d68b
@@ -198,10 +198,13 @@ func (a *App) InitPlugins(pluginDir, webappPluginDir string) {
|
||||
}
|
||||
pluginsEnvironment.SetPrepackagedPlugins(plugins)
|
||||
|
||||
a.installFeatureFlagPlugins()
|
||||
|
||||
// Sync plugin active state when config changes. Also notify plugins.
|
||||
a.Srv().PluginsLock.Lock()
|
||||
a.RemoveConfigListener(a.Srv().PluginConfigListenerId)
|
||||
a.Srv().PluginConfigListenerId = a.AddConfigListener(func(*model.Config, *model.Config) {
|
||||
a.installFeatureFlagPlugins()
|
||||
a.SyncPluginsActiveState()
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
@@ -510,7 +513,8 @@ func (a *App) getRemoteMarketplacePlugin(pluginId, version string) (*model.BaseM
|
||||
}
|
||||
|
||||
filter := a.getBaseMarketplaceFilter()
|
||||
filter.Filter = pluginId
|
||||
filter.PluginId = pluginId
|
||||
filter.ReturnAllVersions = true
|
||||
|
||||
plugin, err := marketplaceClient.GetPlugin(filter, version)
|
||||
if err != nil {
|
||||
@@ -886,6 +890,47 @@ func (a *App) processPrepackagedPlugin(pluginPath *pluginSignaturePath) (*plugin
|
||||
return plugin, nil
|
||||
}
|
||||
|
||||
// installFeatureFlagPlugins handles the automatic installation/upgrade of plugins from feature flags
|
||||
func (a *App) installFeatureFlagPlugins() {
|
||||
ffControledPlugins := a.Config().FeatureFlags.Plugins()
|
||||
|
||||
// Respect the automatic prepackaged disable setting
|
||||
if !*a.Config().PluginSettings.AutomaticPrepackagedPlugins {
|
||||
return
|
||||
}
|
||||
|
||||
for pluginId, version := range ffControledPlugins {
|
||||
// Skip installing if the plugin has been previously disabled.
|
||||
pluginState := a.Config().PluginSettings.PluginStates[pluginId]
|
||||
if pluginState != nil && !pluginState.Enable {
|
||||
a.Log().Debug("Not auto installing/upgrade because plugin was disabled", mlog.String("plugin_id", pluginId), mlog.String("version", version))
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if we already installed this version as InstallMarketplacePlugin can't handle re-installs well.
|
||||
pluginStatus, err := a.Srv().GetPluginStatus(pluginId)
|
||||
if err == nil && pluginStatus.Version == version {
|
||||
continue
|
||||
}
|
||||
|
||||
if version != "" && version != "control" {
|
||||
_, err := a.InstallMarketplacePlugin(&model.InstallMarketplacePluginRequest{
|
||||
Id: pluginId,
|
||||
Version: version,
|
||||
})
|
||||
if err != nil {
|
||||
a.Log().Debug("Unable to install plugin from FF manifest", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version))
|
||||
} else {
|
||||
if err := a.EnablePlugin(pluginId); err != nil {
|
||||
a.Log().Debug("Unable to enable plugin installed from feature flag.", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version))
|
||||
} else {
|
||||
a.Log().Debug("Installed and enabled plugin.", mlog.String("plugin_id", pluginId), mlog.String("version", version))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getPrepackagedPlugin builds a PrepackagedPlugin from the plugin at the given path, additionally returning the directory in which it was extracted.
|
||||
func getPrepackagedPlugin(pluginPath *pluginSignaturePath, pluginFile io.ReadSeeker, tmpDir string) (*plugin.PrepackagedPlugin, string, error) {
|
||||
manifest, pluginDir, appErr := extractPlugin(pluginFile, tmpDir)
|
||||
|
||||
Ссылка в новой задаче
Block a user