From 899ab31fff9b34bc125faf75b79a89e390deb2cf Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 1 Sep 2017 09:00:27 -0400 Subject: Implement experimental REST API endpoints for plugins (#7279) * Implement experimental REST API endpoints for plugins * Updates per feedback and rebase * Update tests * Further updates * Update extraction of plugins * Use OS temp dir for plugins instead of search path * Fail extraction on paths that attempt to traverse upward * Update pluginenv ActivePlugins() --- app/server.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'app/server.go') diff --git a/app/server.go b/app/server.go index b83aa9506..c3bcd562d 100644 --- a/app/server.go +++ b/app/server.go @@ -7,6 +7,7 @@ import ( "crypto/tls" "net" "net/http" + "os" "strings" "time" @@ -19,6 +20,7 @@ import ( "gopkg.in/throttled/throttled.v2/store/memstore" "github.com/mattermost/platform/model" + "github.com/mattermost/platform/plugin/pluginenv" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" ) @@ -28,6 +30,7 @@ type Server struct { WebSocketRouter *WebSocketRouter Router *mux.Router GracefulServer *graceful.Server + PluginEnv *pluginenv.Environment } var allowedMethods []string = []string{ @@ -186,6 +189,10 @@ func StartServer() { }() } + if *utils.Cfg.PluginSettings.Enable { + StartupPlugins("plugins", "webapp/dist") + } + go func() { var err error if *utils.Cfg.ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS { @@ -223,3 +230,28 @@ func StopServer() { l4g.Info(utils.T("api.server.stop_server.stopped.info")) } + +func StartupPlugins(pluginPath, webappPath string) { + l4g.Info("Starting up plugins") + + err := os.Mkdir(pluginPath, 0744) + if err != nil { + if os.IsExist(err) { + err = nil + } else { + l4g.Error("failed to start up plugins: " + err.Error()) + return + } + } + + Srv.PluginEnv, err = pluginenv.New( + pluginenv.SearchPath(pluginPath), + pluginenv.WebappPath(webappPath), + ) + + if err != nil { + l4g.Error("failed to start up plugins: " + err.Error()) + } + + ActivatePlugins() +} -- cgit v1.2.3-1-g7c22