unpack prepacked plugins on plugins initialization (#9149)
* unpack prepackaged plugins on plugins initialization * leverage utils.FindDir
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
f8f80d80df
Коммит
8948b91d7a
@@ -66,7 +66,7 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
manifest, unpackErr := c.App.InstallPlugin(file)
|
||||
manifest, unpackErr := c.App.InstallPlugin(file, false)
|
||||
|
||||
if unpackErr != nil {
|
||||
c.Err = unpackErr
|
||||
|
||||
@@ -6,11 +6,13 @@ package app
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func (a *App) SyncPluginsActiveState() {
|
||||
@@ -101,6 +103,25 @@ func (a *App) InitPlugins(pluginDir, webappPluginDir string) {
|
||||
a.Plugins = env
|
||||
}
|
||||
|
||||
prepackagedPluginsDir, found := utils.FindDir("prepackaged_plugins")
|
||||
if found {
|
||||
if err := filepath.Walk(prepackagedPluginsDir, func(walkPath string, info os.FileInfo, err error) error {
|
||||
if !strings.HasSuffix(walkPath, ".tar.gz") {
|
||||
return nil
|
||||
}
|
||||
|
||||
if fileReader, err := os.Open(walkPath); err != nil {
|
||||
mlog.Error("Failed to open prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath))
|
||||
} else if _, err := a.InstallPlugin(fileReader, true); err != nil {
|
||||
mlog.Error("Failed to unpack prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath))
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
mlog.Error("Failed to complete unpacking prepackaged plugins", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
// Sync plugin active state when config changes. Also notify plugins.
|
||||
a.RemoveConfigListener(a.PluginConfigListenerId)
|
||||
a.PluginConfigListenerId = a.AddConfigListener(func(*model.Config, *model.Config) {
|
||||
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
)
|
||||
|
||||
// InstallPlugin unpacks and installs a plugin but does not enable or activate it.
|
||||
func (a *App) InstallPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
|
||||
return a.installPlugin(pluginFile)
|
||||
func (a *App) InstallPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
||||
return a.installPlugin(pluginFile, replace)
|
||||
}
|
||||
|
||||
func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
|
||||
func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
||||
if a.Plugins == nil || !*a.Config().PluginSettings.Enable {
|
||||
return nil, model.NewAppError("installPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -63,7 +63,13 @@ func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppEr
|
||||
// Check that there is no plugin with the same ID
|
||||
for _, bundle := range bundles {
|
||||
if bundle.Manifest != nil && bundle.Manifest.Id == manifest.Id {
|
||||
return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest)
|
||||
if !replace {
|
||||
return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if err := a.RemovePlugin(manifest.Id); err != nil {
|
||||
return nil, model.NewAppError("installPlugin", "app.plugin.install_id_failed_remove.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ func pluginAddCmdF(command *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := a.InstallPlugin(fileReader); err != nil {
|
||||
if _, err := a.InstallPlugin(fileReader, false); err != nil {
|
||||
CommandPrintErrorln("Unable to add plugin: " + args[i] + ". Error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Added plugin: " + plugin)
|
||||
|
||||
@@ -3074,6 +3074,10 @@
|
||||
"id": "app.plugin.install_id.app_error",
|
||||
"translation": "Unable to install plugin. A plugin with the same ID is already installed."
|
||||
},
|
||||
{
|
||||
"id": "app.plugin.install_id_failed_remove.app_error",
|
||||
"translation": "Unable to install plugin. A plugin with the same ID is already installed and failed to be removed."
|
||||
},
|
||||
{
|
||||
"id": "app.plugin.invalid_id.app_error",
|
||||
"translation": "Plugin Id must be at least {{.Min}} characters, at most {{.Max}} characters and match {{.Regex}}."
|
||||
|
||||
Ссылка в новой задаче
Block a user