mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Plugin framework: add ability to install other plugins to the… (#12232)
* add ability to upload other plugins to the plugin API * generated client rpc glue code * fix UploadPlugin API signature * generated plugin mocks * added upload plugin test * removed unused comment * using single line to call InstallPlugin with file Reader * fix minimum server version * added successful plugin upload test * renamed UploadPlugin to InstallPlugin
This commit is contained in:
committed by
Ali Farooq
parent
db97b49e7a
commit
d7ee3553fa
@@ -4,6 +4,8 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -557,6 +559,12 @@ type API interface {
|
||||
// Minimum server version: 5.6
|
||||
GetPluginStatus(id string) (*model.PluginStatus, *model.AppError)
|
||||
|
||||
// InstallPlugin will upload another plugin with tar.gz file.
|
||||
// Previous version will be replaced on replace true.
|
||||
//
|
||||
// Minimum server version: 5.18
|
||||
InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)
|
||||
|
||||
// KV Store Section
|
||||
|
||||
// KVSet stores a key-value pair, unique per plugin.
|
||||
|
||||
@@ -8,6 +8,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
@@ -3488,6 +3489,36 @@ func (s *apiRPCServer) GetPluginStatus(args *Z_GetPluginStatusArgs, returns *Z_G
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_InstallPluginArgs struct {
|
||||
A io.Reader
|
||||
B bool
|
||||
}
|
||||
|
||||
type Z_InstallPluginReturns struct {
|
||||
A *model.Manifest
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
||||
_args := &Z_InstallPluginArgs{file, replace}
|
||||
_returns := &Z_InstallPluginReturns{}
|
||||
if err := g.client.Call("Plugin.InstallPlugin", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to InstallPlugin API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) InstallPlugin(args *Z_InstallPluginArgs, returns *Z_InstallPluginReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.InstallPlugin(args.A, args.B)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API InstallPlugin called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_KVSetArgs struct {
|
||||
A string
|
||||
B []byte
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package plugintest
|
||||
|
||||
import (
|
||||
io "io"
|
||||
|
||||
model "github.com/mattermost/mattermost-server/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
@@ -2783,3 +2785,28 @@ func (_m *API) UploadFile(data []byte, channelId string, filename string) (*mode
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// InstallPlugin provides a mock function with given fields: file, replace
|
||||
func (_m *API) InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
||||
ret := _m.Called(file, replace)
|
||||
|
||||
var r0 *model.Manifest
|
||||
if rf, ok := ret.Get(0).(func(io.Reader, bool) *model.Manifest); ok {
|
||||
r0 = rf(file, replace)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Manifest)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(io.Reader, bool) *model.AppError); ok {
|
||||
r1 = rf(file, replace)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user