diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-09-01 09:00:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-01 09:00:27 -0400 |
commit | 899ab31fff9b34bc125faf75b79a89e390deb2cf (patch) | |
tree | 41dc5832268504e54a0b2188eedcf89b7828dd12 /app/server.go | |
parent | 74b5e52c4eb54000dcb5a7b46c0977d732bce80f (diff) | |
download | chat-899ab31fff9b34bc125faf75b79a89e390deb2cf.tar.gz chat-899ab31fff9b34bc125faf75b79a89e390deb2cf.tar.bz2 chat-899ab31fff9b34bc125faf75b79a89e390deb2cf.zip |
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()
Diffstat (limited to 'app/server.go')
-rw-r--r-- | app/server.go | 32 |
1 files changed, 32 insertions, 0 deletions
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() +} |