* Move plugins under Channels

We move all plugin related fields under *Channels.
This essentially migrates several methods from being under
*Server to under *Channels.

We also move the plugin startup and shutdown code
to be under Channels.Start and Channels.Shutdown.

While here, we remove the getPluginPublicKeyFiles
method which was a one-line method which uselessly
returned an error.

Lastly, we fix the product initialization order which
was incorrect previously. Products are dependent on
the main server.

So startup should be products -> server.
And shutdown should be server -> products.

```release-note
NONE
```

* Added app layer

```release-note
NONE
```

* Incorporate suggestions

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-11-08 11:57:22 +05:30
коммит произвёл GitHub
родитель 24248dc764
Коммит 25257d6ef6
14 изменённых файлов: 288 добавлений и 290 удалений

Просмотреть файл

@@ -4,9 +4,12 @@
package app
import (
"sync"
"sync/atomic"
"github.com/mattermost/mattermost-server/v6/app/request"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/mattermost/mattermost-server/v6/services/imageproxy"
"github.com/pkg/errors"
)
@@ -15,6 +18,10 @@ import (
type Channels struct {
srv *Server
pluginsEnvironment *plugin.Environment
pluginConfigListenerID string
pluginsLock sync.RWMutex
imageProxy *imageproxy.ImageProxy
asymmetricSigningKey atomic.Value
@@ -44,12 +51,33 @@ func NewChannels(s *Server) (*Channels, error) {
}
func (ch *Channels) Start() error {
// Start plugins
ctx := request.EmptyContext()
ch.initPlugins(ctx, *ch.srv.Config().PluginSettings.Directory, *ch.srv.Config().PluginSettings.ClientDirectory)
ch.AddConfigListener(func(prevCfg, cfg *model.Config) {
if *cfg.PluginSettings.Enable {
ch.initPlugins(ctx, *cfg.PluginSettings.Directory, *ch.srv.Config().PluginSettings.ClientDirectory)
} else {
ch.ShutDownPlugins()
}
})
if err := ch.ensureAsymmetricSigningKey(); err != nil {
return errors.Wrapf(err, "unable to ensure asymmetric signing key")
}
return nil
}
func (*Channels) Stop() error {
func (ch *Channels) Stop() error {
ch.ShutDownPlugins()
return nil
}
func (ch *Channels) AddConfigListener(listener func(*model.Config, *model.Config)) string {
return ch.srv.AddConfigListener(listener)
}
func (ch *Channels) RemoveConfigListener(id string) {
ch.srv.RemoveConfigListener(id)
}