plugin: fix InstallPlugin() API by manually creating RPC code (#13041)
Flugin: fix InstallPlugin() API by manually creating RPC code previous implementation of InstallPlugin()-#12232 's RPC funcs wasn't working because `io.Reader` isn't supported by the RPC code generation tool. RPC does not support streaming data and RPC code generation tool does not handle this exception. thus, RPC funcs are now implemented manually to stream `io.Reader` through a separate multiplexed connection.
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
e03411795c
Коммит
0adbfa8478
@@ -720,3 +720,55 @@ func (s *apiRPCServer) LogError(args *Z_LogErrorArgs, returns *Z_LogErrorReturns
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_InstallPluginArgs struct {
|
||||
PluginStreamID uint32
|
||||
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) {
|
||||
pluginStreamID := g.muxBroker.NextId()
|
||||
|
||||
go func() {
|
||||
uploadPluginConnection, err := g.muxBroker.Accept(pluginStreamID)
|
||||
if err != nil {
|
||||
log.Print("Plugin failed to upload plugin. MuxBroker could not Accept connection", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
defer uploadPluginConnection.Close()
|
||||
serveIOReader(file, uploadPluginConnection)
|
||||
}()
|
||||
|
||||
_args := &Z_InstallPluginArgs{pluginStreamID, replace}
|
||||
_returns := &Z_InstallPluginReturns{}
|
||||
if err := g.client.Call("Plugin.InstallPlugin", _args, _returns); err != nil {
|
||||
log.Print("RPC call InstallPlugin to plugin failed.", mlog.Err(err))
|
||||
}
|
||||
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (g *apiRPCServer) InstallPlugin(args *Z_InstallPluginArgs, returns *Z_InstallPluginReturns) error {
|
||||
hook, ok := g.impl.(interface {
|
||||
InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError)
|
||||
})
|
||||
if !ok {
|
||||
return encodableError(fmt.Errorf("API InstallPlugin called but not implemented."))
|
||||
}
|
||||
|
||||
receivePluginConnection, err := g.muxBroker.Dial(args.PluginStreamID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[ERROR] Can't connect to remote plugin stream, error: %v", err.Error())
|
||||
return err
|
||||
}
|
||||
pluginReader := connectIOReader(receivePluginConnection)
|
||||
defer pluginReader.Close()
|
||||
|
||||
returns.A, returns.B = hook.InstallPlugin(pluginReader, args.B)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
@@ -3607,36 +3606,6 @@ 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
|
||||
|
||||
@@ -395,6 +395,7 @@ func removeExcluded(info *PluginInterfaceInfo) *PluginInterfaceInfo {
|
||||
"FileWillBeUploaded",
|
||||
"Implemented",
|
||||
"LoadPluginConfiguration",
|
||||
"InstallPlugin",
|
||||
"LogDebug",
|
||||
"LogError",
|
||||
"LogInfo",
|
||||
|
||||
Ссылка в новой задаче
Block a user