PLT-8086 Fix plugin config watcher for enabling and disabling (#7770)
* Fix plugin config watcher for enabling and disabling * Make sure HTTP routes are served * Set content-type explicitly
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2dda86b25d
Коммит
2acb548615
@@ -93,6 +93,9 @@ func New(options ...Option) *App {
|
|||||||
app.Srv.Store = app.newStore()
|
app.Srv.Store = app.newStore()
|
||||||
app.initJobs()
|
app.initJobs()
|
||||||
|
|
||||||
|
app.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}", app.ServePluginRequest)
|
||||||
|
app.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}/{anything:.*}", app.ServePluginRequest)
|
||||||
|
|
||||||
app.Srv.Router.NotFoundHandler = http.HandlerFunc(app.Handle404)
|
app.Srv.Router.NotFoundHandler = http.HandlerFunc(app.Handle404)
|
||||||
|
|
||||||
app.Srv.WebSocketRouter = &WebSocketRouter{
|
app.Srv.WebSocketRouter = &WebSocketRouter{
|
||||||
|
|||||||
@@ -557,30 +557,33 @@ func (a *App) InitPlugins(pluginPath, webappPath string) {
|
|||||||
|
|
||||||
utils.RemoveConfigListener(a.PluginConfigListenerId)
|
utils.RemoveConfigListener(a.PluginConfigListenerId)
|
||||||
a.PluginConfigListenerId = utils.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
a.PluginConfigListenerId = utils.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||||
if !*prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
|
||||||
a.InitPlugins(pluginPath, webappPath)
|
|
||||||
} else if *prevCfg.PluginSettings.Enable && !*cfg.PluginSettings.Enable {
|
|
||||||
a.ShutDownPlugins()
|
|
||||||
} else if *prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
|
||||||
a.ActivatePlugins()
|
|
||||||
}
|
|
||||||
|
|
||||||
if a.PluginEnv == nil {
|
if a.PluginEnv == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
||||||
|
a.ActivatePlugins()
|
||||||
|
}
|
||||||
|
|
||||||
for _, err := range a.PluginEnv.Hooks().OnConfigurationChange() {
|
for _, err := range a.PluginEnv.Hooks().OnConfigurationChange() {
|
||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
a.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}", a.ServePluginRequest)
|
|
||||||
a.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}/{anything:.*}", a.ServePluginRequest)
|
|
||||||
|
|
||||||
a.ActivatePlugins()
|
a.ActivatePlugins()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
func (a *App) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
|
||||||
|
err := model.NewAppError("ServePluginRequest", "app.plugin.disabled.app_error", nil, "Enable plugins to serve plugin requests", http.StatusNotImplemented)
|
||||||
|
err.Translate(utils.T)
|
||||||
|
l4g.Error(err.Error())
|
||||||
|
w.WriteHeader(err.StatusCode)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write([]byte(err.ToJson()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
token := ""
|
token := ""
|
||||||
|
|
||||||
authHeader := r.Header.Get(model.HEADER_AUTH)
|
authHeader := r.Header.Get(model.HEADER_AUTH)
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ func runServer(configFileLocation string) {
|
|||||||
|
|
||||||
if webappDir, ok := utils.FindDir(model.CLIENT_DIR); ok {
|
if webappDir, ok := utils.FindDir(model.CLIENT_DIR); ok {
|
||||||
a.InitPlugins(*a.Config().PluginSettings.Directory, webappDir+"/plugins")
|
a.InitPlugins(*a.Config().PluginSettings.Directory, webappDir+"/plugins")
|
||||||
|
utils.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||||
|
if *cfg.PluginSettings.Enable {
|
||||||
|
a.InitPlugins(*cfg.PluginSettings.Directory, webappDir+"/plugins")
|
||||||
|
} else {
|
||||||
|
a.ShutDownPlugins()
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
l4g.Error("Unable to find webapp directory, could not initialize plugins")
|
l4g.Error("Unable to find webapp directory, could not initialize plugins")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user