4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-05 20:44:04 +00:00

Update mattermost library (#2152)

* Update mattermost library

* Fix linting
This commit is contained in:
Wim
2024-05-24 23:08:09 +02:00
committed by GitHub
parent 65d78e38af
commit d16645c952
1003 changed files with 89451 additions and 114025 deletions

View File

@ -0,0 +1,16 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cmdrunner
// addrTranslator implements stateless identity functions, as the host and plugin
// run in the same context wrt Unix and network addresses.
type addrTranslator struct{}
func (*addrTranslator) PluginToHost(pluginNet, pluginAddr string) (string, string, error) {
return pluginNet, pluginAddr, nil
}
func (*addrTranslator) HostToPlugin(hostNet, hostAddr string) (string, string, error) {
return hostNet, hostAddr, nil
}

View File

@ -0,0 +1,63 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cmdrunner
import (
"context"
"fmt"
"net"
"os"
"github.com/hashicorp/go-plugin/runner"
)
// ReattachFunc returns a function that allows reattaching to a plugin running
// as a plain process. The process may or may not be a child process.
func ReattachFunc(pid int, addr net.Addr) runner.ReattachFunc {
return func() (runner.AttachedRunner, error) {
p, err := os.FindProcess(pid)
if err != nil {
// On Unix systems, FindProcess never returns an error.
// On Windows, for non-existent pids it returns:
// os.SyscallError - 'OpenProcess: the paremter is incorrect'
return nil, ErrProcessNotFound
}
// Attempt to connect to the addr since on Unix systems FindProcess
// doesn't actually return an error if it can't find the process.
conn, err := net.Dial(addr.Network(), addr.String())
if err != nil {
p.Kill()
return nil, ErrProcessNotFound
}
conn.Close()
return &CmdAttachedRunner{
pid: pid,
process: p,
}, nil
}
}
// CmdAttachedRunner is mostly a subset of CmdRunner, except the Wait function
// does not assume the process is a child of the host process, and so uses a
// different implementation to wait on the process.
type CmdAttachedRunner struct {
pid int
process *os.Process
addrTranslator
}
func (c *CmdAttachedRunner) Wait(_ context.Context) error {
return pidWait(c.pid)
}
func (c *CmdAttachedRunner) Kill(_ context.Context) error {
return c.process.Kill()
}
func (c *CmdAttachedRunner) ID() string {
return fmt.Sprintf("%d", c.pid)
}

View File

@ -0,0 +1,129 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cmdrunner
import (
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin/runner"
)
var (
_ runner.Runner = (*CmdRunner)(nil)
// ErrProcessNotFound is returned when a client is instantiated to
// reattach to an existing process and it isn't found.
ErrProcessNotFound = errors.New("Reattachment process not found")
)
const unrecognizedRemotePluginMessage = `This usually means
the plugin was not compiled for this architecture,
the plugin is missing dynamic-link libraries necessary to run,
the plugin is not executable by this process due to file permissions, or
the plugin failed to negotiate the initial go-plugin protocol handshake
%s`
// CmdRunner implements the runner.Runner interface. It mostly just passes through
// to exec.Cmd methods.
type CmdRunner struct {
logger hclog.Logger
cmd *exec.Cmd
stdout io.ReadCloser
stderr io.ReadCloser
// Cmd info is persisted early, since the process information will be removed
// after Kill is called.
path string
pid int
addrTranslator
}
// NewCmdRunner returns an implementation of runner.Runner for running a plugin
// as a subprocess. It must be passed a cmd that hasn't yet been started.
func NewCmdRunner(logger hclog.Logger, cmd *exec.Cmd) (*CmdRunner, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
return &CmdRunner{
logger: logger,
cmd: cmd,
stdout: stdout,
stderr: stderr,
path: cmd.Path,
}, nil
}
func (c *CmdRunner) Start(_ context.Context) error {
c.logger.Debug("starting plugin", "path", c.cmd.Path, "args", c.cmd.Args)
err := c.cmd.Start()
if err != nil {
return err
}
c.pid = c.cmd.Process.Pid
c.logger.Debug("plugin started", "path", c.path, "pid", c.pid)
return nil
}
func (c *CmdRunner) Wait(_ context.Context) error {
return c.cmd.Wait()
}
func (c *CmdRunner) Kill(_ context.Context) error {
if c.cmd.Process != nil {
err := c.cmd.Process.Kill()
// Swallow ErrProcessDone, we support calling Kill multiple times.
if !errors.Is(err, os.ErrProcessDone) {
return err
}
return nil
}
return nil
}
func (c *CmdRunner) Stdout() io.ReadCloser {
return c.stdout
}
func (c *CmdRunner) Stderr() io.ReadCloser {
return c.stderr
}
func (c *CmdRunner) Name() string {
return c.path
}
func (c *CmdRunner) ID() string {
return fmt.Sprintf("%d", c.pid)
}
// peTypes is a list of Portable Executable (PE) machine types from https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
// mapped to GOARCH types. It is not comprehensive, and only includes machine types that Go supports.
var peTypes = map[uint16]string{
0x14c: "386",
0x1c0: "arm",
0x6264: "loong64",
0x8664: "amd64",
0xaa64: "arm64",
}
func (c *CmdRunner) Diagnose(_ context.Context) string {
return fmt.Sprintf(unrecognizedRemotePluginMessage, additionalNotesAboutCommand(c.cmd.Path))
}

View File

@ -0,0 +1,70 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build !windows
// +build !windows
package cmdrunner
import (
"debug/elf"
"debug/macho"
"debug/pe"
"fmt"
"os"
"os/user"
"runtime"
"strconv"
"syscall"
)
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
// why it won't run correctly. It runs as a best effort only.
func additionalNotesAboutCommand(path string) string {
notes := ""
stat, err := os.Stat(path)
if err != nil {
return notes
}
notes += "\nAdditional notes about plugin:\n"
notes += fmt.Sprintf(" Path: %s\n", path)
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
statT, ok := stat.Sys().(*syscall.Stat_t)
if ok {
currentUsername := "?"
if u, err := user.LookupId(strconv.FormatUint(uint64(os.Getuid()), 10)); err == nil {
currentUsername = u.Username
}
currentGroup := "?"
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(os.Getgid()), 10)); err == nil {
currentGroup = g.Name
}
username := "?"
if u, err := user.LookupId(strconv.FormatUint(uint64(statT.Uid), 10)); err == nil {
username = u.Username
}
group := "?"
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(statT.Gid), 10)); err == nil {
group = g.Name
}
notes += fmt.Sprintf(" Owner: %d [%s] (current: %d [%s])\n", statT.Uid, username, os.Getuid(), currentUsername)
notes += fmt.Sprintf(" Group: %d [%s] (current: %d [%s])\n", statT.Gid, group, os.Getgid(), currentGroup)
}
if elfFile, err := elf.Open(path); err == nil {
defer elfFile.Close()
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
} else if machoFile, err := macho.Open(path); err == nil {
defer machoFile.Close()
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
} else if peFile, err := pe.Open(path); err == nil {
defer peFile.Close()
machine, ok := peTypes[peFile.Machine]
if !ok {
machine = "unknown"
}
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
}
return notes
}

View File

@ -0,0 +1,46 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build windows
// +build windows
package cmdrunner
import (
"debug/elf"
"debug/macho"
"debug/pe"
"fmt"
"os"
"runtime"
)
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
// why it won't run correctly. It runs as a best effort only.
func additionalNotesAboutCommand(path string) string {
notes := ""
stat, err := os.Stat(path)
if err != nil {
return notes
}
notes += "\nAdditional notes about plugin:\n"
notes += fmt.Sprintf(" Path: %s\n", path)
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
if elfFile, err := elf.Open(path); err == nil {
defer elfFile.Close()
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
} else if machoFile, err := macho.Open(path); err == nil {
defer machoFile.Close()
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
} else if peFile, err := pe.Open(path); err == nil {
defer peFile.Close()
machine, ok := peTypes[peFile.Machine]
if !ok {
machine = "unknown"
}
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
}
return notes
}

View File

@ -0,0 +1,25 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cmdrunner
import "time"
// pidAlive checks whether a pid is alive.
func pidAlive(pid int) bool {
return _pidAlive(pid)
}
// pidWait blocks for a process to exit.
func pidWait(pid int) error {
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
for range ticker.C {
if !pidAlive(pid) {
break
}
}
return nil
}

View File

@ -0,0 +1,23 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build !windows
// +build !windows
package cmdrunner
import (
"os"
"syscall"
)
// _pidAlive tests whether a process is alive or not by sending it Signal 0,
// since Go otherwise has no way to test this.
func _pidAlive(pid int) bool {
proc, err := os.FindProcess(pid)
if err == nil {
err = proc.Signal(syscall.Signal(0))
}
return err == nil
}

View File

@ -0,0 +1,33 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package cmdrunner
import (
"syscall"
)
const (
// Weird name but matches the MSDN docs
exit_STILL_ACTIVE = 259
processDesiredAccess = syscall.STANDARD_RIGHTS_READ |
syscall.PROCESS_QUERY_INFORMATION |
syscall.SYNCHRONIZE
)
// _pidAlive tests whether a process is alive or not
func _pidAlive(pid int) bool {
h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid))
if err != nil {
return false
}
defer syscall.CloseHandle(h)
var ec uint32
if e := syscall.GetExitCodeProcess(h, &ec); e != nil {
return false
}
return ec == exit_STILL_ACTIVE
}

View File

@ -0,0 +1,51 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grpcmux
import (
"io"
"net"
"github.com/hashicorp/yamux"
)
var _ net.Listener = (*blockedClientListener)(nil)
// blockedClientListener accepts connections for a specific gRPC broker stream
// ID on the client (host) side of the connection.
type blockedClientListener struct {
session *yamux.Session
waitCh chan struct{}
doneCh <-chan struct{}
}
func newBlockedClientListener(session *yamux.Session, doneCh <-chan struct{}) *blockedClientListener {
return &blockedClientListener{
waitCh: make(chan struct{}, 1),
doneCh: doneCh,
session: session,
}
}
func (b *blockedClientListener) Accept() (net.Conn, error) {
select {
case <-b.waitCh:
return b.session.Accept()
case <-b.doneCh:
return nil, io.EOF
}
}
func (b *blockedClientListener) Addr() net.Addr {
return b.session.Addr()
}
func (b *blockedClientListener) Close() error {
// We don't close the session, the client muxer is responsible for that.
return nil
}
func (b *blockedClientListener) unblock() {
b.waitCh <- struct{}{}
}

View File

@ -0,0 +1,49 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grpcmux
import (
"io"
"net"
)
var _ net.Listener = (*blockedServerListener)(nil)
// blockedServerListener accepts connections for a specific gRPC broker stream
// ID on the server (plugin) side of the connection.
type blockedServerListener struct {
addr net.Addr
acceptCh chan acceptResult
doneCh <-chan struct{}
}
type acceptResult struct {
conn net.Conn
err error
}
func newBlockedServerListener(addr net.Addr, doneCh <-chan struct{}) *blockedServerListener {
return &blockedServerListener{
addr: addr,
acceptCh: make(chan acceptResult),
doneCh: doneCh,
}
}
func (b *blockedServerListener) Accept() (net.Conn, error) {
select {
case accept := <-b.acceptCh:
return accept.conn, accept.err
case <-b.doneCh:
return nil, io.EOF
}
}
func (b *blockedServerListener) Addr() net.Addr {
return b.addr
}
func (b *blockedServerListener) Close() error {
return nil
}

View File

@ -0,0 +1,105 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grpcmux
import (
"fmt"
"net"
"sync"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/yamux"
)
var _ GRPCMuxer = (*GRPCClientMuxer)(nil)
// GRPCClientMuxer implements the client (host) side of the gRPC broker's
// GRPCMuxer interface for multiplexing multiple gRPC broker connections over
// a single net.Conn.
//
// The client dials the initial net.Conn eagerly, and creates a yamux.Session
// as the implementation for multiplexing any additional connections.
//
// Each net.Listener returned from Listener will block until the client receives
// a knock that matches its gRPC broker stream ID. There is no default listener
// on the client, as it is a client for the gRPC broker's control services. (See
// GRPCServerMuxer for more details).
type GRPCClientMuxer struct {
logger hclog.Logger
session *yamux.Session
acceptMutex sync.Mutex
acceptListeners map[uint32]*blockedClientListener
}
func NewGRPCClientMuxer(logger hclog.Logger, addr net.Addr) (*GRPCClientMuxer, error) {
// Eagerly establish the underlying connection as early as possible.
logger.Debug("making new client mux initial connection", "addr", addr)
conn, err := net.Dial(addr.Network(), addr.String())
if err != nil {
return nil, err
}
if tcpConn, ok := conn.(*net.TCPConn); ok {
// Make sure to set keep alive so that the connection doesn't die
_ = tcpConn.SetKeepAlive(true)
}
cfg := yamux.DefaultConfig()
cfg.Logger = logger.Named("yamux").StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
})
cfg.LogOutput = nil
sess, err := yamux.Client(conn, cfg)
if err != nil {
return nil, err
}
logger.Debug("client muxer connected", "addr", addr)
m := &GRPCClientMuxer{
logger: logger,
session: sess,
acceptListeners: make(map[uint32]*blockedClientListener),
}
return m, nil
}
func (m *GRPCClientMuxer) Enabled() bool {
return m != nil
}
func (m *GRPCClientMuxer) Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error) {
ln := newBlockedClientListener(m.session, doneCh)
m.acceptMutex.Lock()
m.acceptListeners[id] = ln
m.acceptMutex.Unlock()
return ln, nil
}
func (m *GRPCClientMuxer) AcceptKnock(id uint32) error {
m.acceptMutex.Lock()
defer m.acceptMutex.Unlock()
ln, ok := m.acceptListeners[id]
if !ok {
return fmt.Errorf("no listener for id %d", id)
}
ln.unblock()
return nil
}
func (m *GRPCClientMuxer) Dial() (net.Conn, error) {
stream, err := m.session.Open()
if err != nil {
return nil, fmt.Errorf("error dialling new client stream: %w", err)
}
return stream, nil
}
func (m *GRPCClientMuxer) Close() error {
return m.session.Close()
}

View File

@ -0,0 +1,41 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grpcmux
import (
"net"
)
// GRPCMuxer enables multiple implementations of net.Listener to accept
// connections over a single "main" multiplexed net.Conn, and dial multiple
// client connections over the same multiplexed net.Conn.
//
// The first multiplexed connection is used to serve the gRPC broker's own
// control services: plugin.GRPCBroker, plugin.GRPCController, plugin.GRPCStdio.
//
// Clients must "knock" before dialling, to tell the server side that the
// next net.Conn should be accepted onto a specific stream ID. The knock is a
// bidirectional streaming message on the plugin.GRPCBroker service.
type GRPCMuxer interface {
// Enabled determines whether multiplexing should be used. It saves users
// of the interface from having to compare an interface with nil, which
// is a bit awkward to do correctly.
Enabled() bool
// Listener returns a multiplexed listener that will wait until AcceptKnock
// is called with a matching ID before its Accept function returns.
Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error)
// AcceptKnock unblocks the listener with the matching ID, and returns an
// error if it hasn't been created yet.
AcceptKnock(id uint32) error
// Dial makes a new multiplexed client connection. To dial a specific ID,
// a knock must be sent first.
Dial() (net.Conn, error)
// Close closes connections and releases any resources associated with the
// muxer.
Close() error
}

View File

@ -0,0 +1,190 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package grpcmux
import (
"errors"
"fmt"
"net"
"sync"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/yamux"
)
var _ GRPCMuxer = (*GRPCServerMuxer)(nil)
var _ net.Listener = (*GRPCServerMuxer)(nil)
// GRPCServerMuxer implements the server (plugin) side of the gRPC broker's
// GRPCMuxer interface for multiplexing multiple gRPC broker connections over
// a single net.Conn.
//
// The server side needs a listener to serve the gRPC broker's control services,
// which includes the service we will receive knocks on. That means we always
// accept the first connection onto a "default" main listener, and if we accept
// any further connections without receiving a knock first, they are also given
// to the default listener.
//
// When creating additional multiplexed listeners for specific stream IDs, we
// can't control the order in which gRPC servers will call Accept() on each
// listener, but we do need to control which gRPC server accepts which connection.
// As such, each multiplexed listener blocks waiting on a channel. It will be
// unblocked when a knock is received for the matching stream ID.
type GRPCServerMuxer struct {
addr net.Addr
logger hclog.Logger
sessionErrCh chan error
sess *yamux.Session
knockCh chan uint32
acceptMutex sync.Mutex
acceptChannels map[uint32]chan acceptResult
}
func NewGRPCServerMuxer(logger hclog.Logger, ln net.Listener) *GRPCServerMuxer {
m := &GRPCServerMuxer{
addr: ln.Addr(),
logger: logger,
sessionErrCh: make(chan error),
knockCh: make(chan uint32, 1),
acceptChannels: make(map[uint32]chan acceptResult),
}
go m.acceptSession(ln)
return m
}
// acceptSessionAndMuxAccept is responsible for establishing the yamux session,
// and then kicking off the acceptLoop function.
func (m *GRPCServerMuxer) acceptSession(ln net.Listener) {
defer close(m.sessionErrCh)
m.logger.Debug("accepting initial connection", "addr", m.addr)
conn, err := ln.Accept()
if err != nil {
m.sessionErrCh <- err
return
}
m.logger.Debug("initial server connection accepted", "addr", m.addr)
cfg := yamux.DefaultConfig()
cfg.Logger = m.logger.Named("yamux").StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
})
cfg.LogOutput = nil
m.sess, err = yamux.Server(conn, cfg)
if err != nil {
m.sessionErrCh <- err
return
}
}
func (m *GRPCServerMuxer) session() (*yamux.Session, error) {
select {
case err := <-m.sessionErrCh:
if err != nil {
return nil, err
}
case <-time.After(5 * time.Second):
return nil, errors.New("timed out waiting for connection to be established")
}
// Should never happen.
if m.sess == nil {
return nil, errors.New("no connection established and no error received")
}
return m.sess, nil
}
// Accept accepts all incoming connections and routes them to the correct
// stream ID based on the most recent knock received.
func (m *GRPCServerMuxer) Accept() (net.Conn, error) {
session, err := m.session()
if err != nil {
return nil, fmt.Errorf("error establishing yamux session: %w", err)
}
for {
conn, acceptErr := session.Accept()
select {
case id := <-m.knockCh:
m.acceptMutex.Lock()
acceptCh, ok := m.acceptChannels[id]
m.acceptMutex.Unlock()
if !ok {
if conn != nil {
_ = conn.Close()
}
return nil, fmt.Errorf("received knock on ID %d that doesn't have a listener", id)
}
m.logger.Debug("sending conn to brokered listener", "id", id)
acceptCh <- acceptResult{
conn: conn,
err: acceptErr,
}
default:
m.logger.Debug("sending conn to default listener")
return conn, acceptErr
}
}
}
func (m *GRPCServerMuxer) Addr() net.Addr {
return m.addr
}
func (m *GRPCServerMuxer) Close() error {
session, err := m.session()
if err != nil {
return err
}
return session.Close()
}
func (m *GRPCServerMuxer) Enabled() bool {
return m != nil
}
func (m *GRPCServerMuxer) Listener(id uint32, doneCh <-chan struct{}) (net.Listener, error) {
sess, err := m.session()
if err != nil {
return nil, err
}
ln := newBlockedServerListener(sess.Addr(), doneCh)
m.acceptMutex.Lock()
m.acceptChannels[id] = ln.acceptCh
m.acceptMutex.Unlock()
return ln, nil
}
func (m *GRPCServerMuxer) Dial() (net.Conn, error) {
sess, err := m.session()
if err != nil {
return nil, err
}
stream, err := sess.OpenStream()
if err != nil {
return nil, fmt.Errorf("error dialling new server stream: %w", err)
}
return stream, nil
}
func (m *GRPCServerMuxer) AcceptKnock(id uint32) error {
m.knockCh <- id
return nil
}

View File

@ -0,0 +1,264 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc (unknown)
// source: internal/plugin/grpc_broker.proto
package plugin
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ConnInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ServiceId uint32 `protobuf:"varint,1,opt,name=service_id,json=serviceId,proto3" json:"service_id,omitempty"`
Network string `protobuf:"bytes,2,opt,name=network,proto3" json:"network,omitempty"`
Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
Knock *ConnInfo_Knock `protobuf:"bytes,4,opt,name=knock,proto3" json:"knock,omitempty"`
}
func (x *ConnInfo) Reset() {
*x = ConnInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_plugin_grpc_broker_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ConnInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ConnInfo) ProtoMessage() {}
func (x *ConnInfo) ProtoReflect() protoreflect.Message {
mi := &file_internal_plugin_grpc_broker_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ConnInfo.ProtoReflect.Descriptor instead.
func (*ConnInfo) Descriptor() ([]byte, []int) {
return file_internal_plugin_grpc_broker_proto_rawDescGZIP(), []int{0}
}
func (x *ConnInfo) GetServiceId() uint32 {
if x != nil {
return x.ServiceId
}
return 0
}
func (x *ConnInfo) GetNetwork() string {
if x != nil {
return x.Network
}
return ""
}
func (x *ConnInfo) GetAddress() string {
if x != nil {
return x.Address
}
return ""
}
func (x *ConnInfo) GetKnock() *ConnInfo_Knock {
if x != nil {
return x.Knock
}
return nil
}
type ConnInfo_Knock struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Knock bool `protobuf:"varint,1,opt,name=knock,proto3" json:"knock,omitempty"`
Ack bool `protobuf:"varint,2,opt,name=ack,proto3" json:"ack,omitempty"`
Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"`
}
func (x *ConnInfo_Knock) Reset() {
*x = ConnInfo_Knock{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_plugin_grpc_broker_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ConnInfo_Knock) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ConnInfo_Knock) ProtoMessage() {}
func (x *ConnInfo_Knock) ProtoReflect() protoreflect.Message {
mi := &file_internal_plugin_grpc_broker_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ConnInfo_Knock.ProtoReflect.Descriptor instead.
func (*ConnInfo_Knock) Descriptor() ([]byte, []int) {
return file_internal_plugin_grpc_broker_proto_rawDescGZIP(), []int{0, 0}
}
func (x *ConnInfo_Knock) GetKnock() bool {
if x != nil {
return x.Knock
}
return false
}
func (x *ConnInfo_Knock) GetAck() bool {
if x != nil {
return x.Ack
}
return false
}
func (x *ConnInfo_Knock) GetError() string {
if x != nil {
return x.Error
}
return ""
}
var File_internal_plugin_grpc_broker_proto protoreflect.FileDescriptor
var file_internal_plugin_grpc_broker_proto_rawDesc = []byte{
0x0a, 0x21, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x12, 0x06, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x22, 0xd2, 0x01, 0x0a, 0x08,
0x43, 0x6f, 0x6e, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f,
0x72, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72,
0x6b, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2c, 0x0a, 0x05, 0x6b,
0x6e, 0x6f, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x6c, 0x75,
0x67, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x4b, 0x6e, 0x6f,
0x63, 0x6b, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x63, 0x6b, 0x1a, 0x45, 0x0a, 0x05, 0x4b, 0x6e, 0x6f,
0x63, 0x6b, 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x63, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28,
0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x63, 0x6b, 0x18,
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x61, 0x63, 0x6b, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72,
0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72,
0x32, 0x43, 0x0a, 0x0a, 0x47, 0x52, 0x50, 0x43, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x12, 0x35,
0x0a, 0x0b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x10, 0x2e,
0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x1a,
0x10, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x49, 0x6e, 0x66,
0x6f, 0x28, 0x01, 0x30, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_internal_plugin_grpc_broker_proto_rawDescOnce sync.Once
file_internal_plugin_grpc_broker_proto_rawDescData = file_internal_plugin_grpc_broker_proto_rawDesc
)
func file_internal_plugin_grpc_broker_proto_rawDescGZIP() []byte {
file_internal_plugin_grpc_broker_proto_rawDescOnce.Do(func() {
file_internal_plugin_grpc_broker_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_plugin_grpc_broker_proto_rawDescData)
})
return file_internal_plugin_grpc_broker_proto_rawDescData
}
var file_internal_plugin_grpc_broker_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_internal_plugin_grpc_broker_proto_goTypes = []interface{}{
(*ConnInfo)(nil), // 0: plugin.ConnInfo
(*ConnInfo_Knock)(nil), // 1: plugin.ConnInfo.Knock
}
var file_internal_plugin_grpc_broker_proto_depIdxs = []int32{
1, // 0: plugin.ConnInfo.knock:type_name -> plugin.ConnInfo.Knock
0, // 1: plugin.GRPCBroker.StartStream:input_type -> plugin.ConnInfo
0, // 2: plugin.GRPCBroker.StartStream:output_type -> plugin.ConnInfo
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_internal_plugin_grpc_broker_proto_init() }
func file_internal_plugin_grpc_broker_proto_init() {
if File_internal_plugin_grpc_broker_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_internal_plugin_grpc_broker_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ConnInfo); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_internal_plugin_grpc_broker_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ConnInfo_Knock); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_internal_plugin_grpc_broker_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_internal_plugin_grpc_broker_proto_goTypes,
DependencyIndexes: file_internal_plugin_grpc_broker_proto_depIdxs,
MessageInfos: file_internal_plugin_grpc_broker_proto_msgTypes,
}.Build()
File_internal_plugin_grpc_broker_proto = out.File
file_internal_plugin_grpc_broker_proto_rawDesc = nil
file_internal_plugin_grpc_broker_proto_goTypes = nil
file_internal_plugin_grpc_broker_proto_depIdxs = nil
}

View File

@ -0,0 +1,22 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
syntax = "proto3";
package plugin;
option go_package = "./plugin";
message ConnInfo {
uint32 service_id = 1;
string network = 2;
string address = 3;
message Knock {
bool knock = 1;
bool ack = 2;
string error = 3;
}
Knock knock = 4;
}
service GRPCBroker {
rpc StartStream(stream ConnInfo) returns (stream ConnInfo);
}

View File

@ -0,0 +1,142 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: internal/plugin/grpc_broker.proto
package plugin
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
GRPCBroker_StartStream_FullMethodName = "/plugin.GRPCBroker/StartStream"
)
// GRPCBrokerClient is the client API for GRPCBroker service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GRPCBrokerClient interface {
StartStream(ctx context.Context, opts ...grpc.CallOption) (GRPCBroker_StartStreamClient, error)
}
type gRPCBrokerClient struct {
cc grpc.ClientConnInterface
}
func NewGRPCBrokerClient(cc grpc.ClientConnInterface) GRPCBrokerClient {
return &gRPCBrokerClient{cc}
}
func (c *gRPCBrokerClient) StartStream(ctx context.Context, opts ...grpc.CallOption) (GRPCBroker_StartStreamClient, error) {
stream, err := c.cc.NewStream(ctx, &GRPCBroker_ServiceDesc.Streams[0], GRPCBroker_StartStream_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &gRPCBrokerStartStreamClient{stream}
return x, nil
}
type GRPCBroker_StartStreamClient interface {
Send(*ConnInfo) error
Recv() (*ConnInfo, error)
grpc.ClientStream
}
type gRPCBrokerStartStreamClient struct {
grpc.ClientStream
}
func (x *gRPCBrokerStartStreamClient) Send(m *ConnInfo) error {
return x.ClientStream.SendMsg(m)
}
func (x *gRPCBrokerStartStreamClient) Recv() (*ConnInfo, error) {
m := new(ConnInfo)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// GRPCBrokerServer is the server API for GRPCBroker service.
// All implementations should embed UnimplementedGRPCBrokerServer
// for forward compatibility
type GRPCBrokerServer interface {
StartStream(GRPCBroker_StartStreamServer) error
}
// UnimplementedGRPCBrokerServer should be embedded to have forward compatible implementations.
type UnimplementedGRPCBrokerServer struct {
}
func (UnimplementedGRPCBrokerServer) StartStream(GRPCBroker_StartStreamServer) error {
return status.Errorf(codes.Unimplemented, "method StartStream not implemented")
}
// UnsafeGRPCBrokerServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GRPCBrokerServer will
// result in compilation errors.
type UnsafeGRPCBrokerServer interface {
mustEmbedUnimplementedGRPCBrokerServer()
}
func RegisterGRPCBrokerServer(s grpc.ServiceRegistrar, srv GRPCBrokerServer) {
s.RegisterService(&GRPCBroker_ServiceDesc, srv)
}
func _GRPCBroker_StartStream_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(GRPCBrokerServer).StartStream(&gRPCBrokerStartStreamServer{stream})
}
type GRPCBroker_StartStreamServer interface {
Send(*ConnInfo) error
Recv() (*ConnInfo, error)
grpc.ServerStream
}
type gRPCBrokerStartStreamServer struct {
grpc.ServerStream
}
func (x *gRPCBrokerStartStreamServer) Send(m *ConnInfo) error {
return x.ServerStream.SendMsg(m)
}
func (x *gRPCBrokerStartStreamServer) Recv() (*ConnInfo, error) {
m := new(ConnInfo)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// GRPCBroker_ServiceDesc is the grpc.ServiceDesc for GRPCBroker service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var GRPCBroker_ServiceDesc = grpc.ServiceDesc{
ServiceName: "plugin.GRPCBroker",
HandlerType: (*GRPCBrokerServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{
{
StreamName: "StartStream",
Handler: _GRPCBroker_StartStream_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "internal/plugin/grpc_broker.proto",
}

View File

@ -0,0 +1,141 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc (unknown)
// source: internal/plugin/grpc_controller.proto
package plugin
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Empty struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *Empty) Reset() {
*x = Empty{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_plugin_grpc_controller_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Empty) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Empty) ProtoMessage() {}
func (x *Empty) ProtoReflect() protoreflect.Message {
mi := &file_internal_plugin_grpc_controller_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Empty.ProtoReflect.Descriptor instead.
func (*Empty) Descriptor() ([]byte, []int) {
return file_internal_plugin_grpc_controller_proto_rawDescGZIP(), []int{0}
}
var File_internal_plugin_grpc_controller_proto protoreflect.FileDescriptor
var file_internal_plugin_grpc_controller_proto_rawDesc = []byte{
0x0a, 0x25, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x22,
0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x32, 0x3a, 0x0a, 0x0e, 0x47, 0x52, 0x50, 0x43,
0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x28, 0x0a, 0x08, 0x53, 0x68,
0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x0d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x0d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x45,
0x6d, 0x70, 0x74, 0x79, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_internal_plugin_grpc_controller_proto_rawDescOnce sync.Once
file_internal_plugin_grpc_controller_proto_rawDescData = file_internal_plugin_grpc_controller_proto_rawDesc
)
func file_internal_plugin_grpc_controller_proto_rawDescGZIP() []byte {
file_internal_plugin_grpc_controller_proto_rawDescOnce.Do(func() {
file_internal_plugin_grpc_controller_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_plugin_grpc_controller_proto_rawDescData)
})
return file_internal_plugin_grpc_controller_proto_rawDescData
}
var file_internal_plugin_grpc_controller_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_internal_plugin_grpc_controller_proto_goTypes = []interface{}{
(*Empty)(nil), // 0: plugin.Empty
}
var file_internal_plugin_grpc_controller_proto_depIdxs = []int32{
0, // 0: plugin.GRPCController.Shutdown:input_type -> plugin.Empty
0, // 1: plugin.GRPCController.Shutdown:output_type -> plugin.Empty
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_internal_plugin_grpc_controller_proto_init() }
func file_internal_plugin_grpc_controller_proto_init() {
if File_internal_plugin_grpc_controller_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_internal_plugin_grpc_controller_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Empty); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_internal_plugin_grpc_controller_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_internal_plugin_grpc_controller_proto_goTypes,
DependencyIndexes: file_internal_plugin_grpc_controller_proto_depIdxs,
MessageInfos: file_internal_plugin_grpc_controller_proto_msgTypes,
}.Build()
File_internal_plugin_grpc_controller_proto = out.File
file_internal_plugin_grpc_controller_proto_rawDesc = nil
file_internal_plugin_grpc_controller_proto_goTypes = nil
file_internal_plugin_grpc_controller_proto_depIdxs = nil
}

View File

@ -0,0 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
syntax = "proto3";
package plugin;
option go_package = "./plugin";
message Empty {
}
// The GRPCController is responsible for telling the plugin server to shutdown.
service GRPCController {
rpc Shutdown(Empty) returns (Empty);
}

View File

@ -0,0 +1,110 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: internal/plugin/grpc_controller.proto
package plugin
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
GRPCController_Shutdown_FullMethodName = "/plugin.GRPCController/Shutdown"
)
// GRPCControllerClient is the client API for GRPCController service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GRPCControllerClient interface {
Shutdown(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
}
type gRPCControllerClient struct {
cc grpc.ClientConnInterface
}
func NewGRPCControllerClient(cc grpc.ClientConnInterface) GRPCControllerClient {
return &gRPCControllerClient{cc}
}
func (c *gRPCControllerClient) Shutdown(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, GRPCController_Shutdown_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// GRPCControllerServer is the server API for GRPCController service.
// All implementations should embed UnimplementedGRPCControllerServer
// for forward compatibility
type GRPCControllerServer interface {
Shutdown(context.Context, *Empty) (*Empty, error)
}
// UnimplementedGRPCControllerServer should be embedded to have forward compatible implementations.
type UnimplementedGRPCControllerServer struct {
}
func (UnimplementedGRPCControllerServer) Shutdown(context.Context, *Empty) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Shutdown not implemented")
}
// UnsafeGRPCControllerServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GRPCControllerServer will
// result in compilation errors.
type UnsafeGRPCControllerServer interface {
mustEmbedUnimplementedGRPCControllerServer()
}
func RegisterGRPCControllerServer(s grpc.ServiceRegistrar, srv GRPCControllerServer) {
s.RegisterService(&GRPCController_ServiceDesc, srv)
}
func _GRPCController_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GRPCControllerServer).Shutdown(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: GRPCController_Shutdown_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GRPCControllerServer).Shutdown(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
// GRPCController_ServiceDesc is the grpc.ServiceDesc for GRPCController service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var GRPCController_ServiceDesc = grpc.ServiceDesc{
ServiceName: "plugin.GRPCController",
HandlerType: (*GRPCControllerServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Shutdown",
Handler: _GRPCController_Shutdown_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "internal/plugin/grpc_controller.proto",
}

View File

@ -0,0 +1,225 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc (unknown)
// source: internal/plugin/grpc_stdio.proto
package plugin
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type StdioData_Channel int32
const (
StdioData_INVALID StdioData_Channel = 0
StdioData_STDOUT StdioData_Channel = 1
StdioData_STDERR StdioData_Channel = 2
)
// Enum value maps for StdioData_Channel.
var (
StdioData_Channel_name = map[int32]string{
0: "INVALID",
1: "STDOUT",
2: "STDERR",
}
StdioData_Channel_value = map[string]int32{
"INVALID": 0,
"STDOUT": 1,
"STDERR": 2,
}
)
func (x StdioData_Channel) Enum() *StdioData_Channel {
p := new(StdioData_Channel)
*p = x
return p
}
func (x StdioData_Channel) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (StdioData_Channel) Descriptor() protoreflect.EnumDescriptor {
return file_internal_plugin_grpc_stdio_proto_enumTypes[0].Descriptor()
}
func (StdioData_Channel) Type() protoreflect.EnumType {
return &file_internal_plugin_grpc_stdio_proto_enumTypes[0]
}
func (x StdioData_Channel) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use StdioData_Channel.Descriptor instead.
func (StdioData_Channel) EnumDescriptor() ([]byte, []int) {
return file_internal_plugin_grpc_stdio_proto_rawDescGZIP(), []int{0, 0}
}
// StdioData is a single chunk of stdout or stderr data that is streamed
// from GRPCStdio.
type StdioData struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Channel StdioData_Channel `protobuf:"varint,1,opt,name=channel,proto3,enum=plugin.StdioData_Channel" json:"channel,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *StdioData) Reset() {
*x = StdioData{}
if protoimpl.UnsafeEnabled {
mi := &file_internal_plugin_grpc_stdio_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *StdioData) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*StdioData) ProtoMessage() {}
func (x *StdioData) ProtoReflect() protoreflect.Message {
mi := &file_internal_plugin_grpc_stdio_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use StdioData.ProtoReflect.Descriptor instead.
func (*StdioData) Descriptor() ([]byte, []int) {
return file_internal_plugin_grpc_stdio_proto_rawDescGZIP(), []int{0}
}
func (x *StdioData) GetChannel() StdioData_Channel {
if x != nil {
return x.Channel
}
return StdioData_INVALID
}
func (x *StdioData) GetData() []byte {
if x != nil {
return x.Data
}
return nil
}
var File_internal_plugin_grpc_stdio_proto protoreflect.FileDescriptor
var file_internal_plugin_grpc_stdio_proto_rawDesc = []byte{
0x0a, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x73, 0x74, 0x64, 0x69, 0x6f, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x12, 0x06, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74,
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x01, 0x0a, 0x09, 0x53, 0x74, 0x64, 0x69,
0x6f, 0x44, 0x61, 0x74, 0x61, 0x12, 0x33, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e,
0x53, 0x74, 0x64, 0x69, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65,
0x6c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61,
0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2e,
0x0a, 0x07, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x56,
0x41, 0x4c, 0x49, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x44, 0x4f, 0x55, 0x54,
0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x44, 0x45, 0x52, 0x52, 0x10, 0x02, 0x32, 0x47,
0x0a, 0x09, 0x47, 0x52, 0x50, 0x43, 0x53, 0x74, 0x64, 0x69, 0x6f, 0x12, 0x3a, 0x0a, 0x0b, 0x53,
0x74, 0x72, 0x65, 0x61, 0x6d, 0x53, 0x74, 0x64, 0x69, 0x6f, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70,
0x74, 0x79, 0x1a, 0x11, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x53, 0x74, 0x64, 0x69,
0x6f, 0x44, 0x61, 0x74, 0x61, 0x30, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x70, 0x6c, 0x75,
0x67, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_internal_plugin_grpc_stdio_proto_rawDescOnce sync.Once
file_internal_plugin_grpc_stdio_proto_rawDescData = file_internal_plugin_grpc_stdio_proto_rawDesc
)
func file_internal_plugin_grpc_stdio_proto_rawDescGZIP() []byte {
file_internal_plugin_grpc_stdio_proto_rawDescOnce.Do(func() {
file_internal_plugin_grpc_stdio_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_plugin_grpc_stdio_proto_rawDescData)
})
return file_internal_plugin_grpc_stdio_proto_rawDescData
}
var file_internal_plugin_grpc_stdio_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_internal_plugin_grpc_stdio_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_internal_plugin_grpc_stdio_proto_goTypes = []interface{}{
(StdioData_Channel)(0), // 0: plugin.StdioData.Channel
(*StdioData)(nil), // 1: plugin.StdioData
(*emptypb.Empty)(nil), // 2: google.protobuf.Empty
}
var file_internal_plugin_grpc_stdio_proto_depIdxs = []int32{
0, // 0: plugin.StdioData.channel:type_name -> plugin.StdioData.Channel
2, // 1: plugin.GRPCStdio.StreamStdio:input_type -> google.protobuf.Empty
1, // 2: plugin.GRPCStdio.StreamStdio:output_type -> plugin.StdioData
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_internal_plugin_grpc_stdio_proto_init() }
func file_internal_plugin_grpc_stdio_proto_init() {
if File_internal_plugin_grpc_stdio_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_internal_plugin_grpc_stdio_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*StdioData); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_internal_plugin_grpc_stdio_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_internal_plugin_grpc_stdio_proto_goTypes,
DependencyIndexes: file_internal_plugin_grpc_stdio_proto_depIdxs,
EnumInfos: file_internal_plugin_grpc_stdio_proto_enumTypes,
MessageInfos: file_internal_plugin_grpc_stdio_proto_msgTypes,
}.Build()
File_internal_plugin_grpc_stdio_proto = out.File
file_internal_plugin_grpc_stdio_proto_rawDesc = nil
file_internal_plugin_grpc_stdio_proto_goTypes = nil
file_internal_plugin_grpc_stdio_proto_depIdxs = nil
}

View File

@ -0,0 +1,33 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
syntax = "proto3";
package plugin;
option go_package = "./plugin";
import "google/protobuf/empty.proto";
// GRPCStdio is a service that is automatically run by the plugin process
// to stream any stdout/err data so that it can be mirrored on the plugin
// host side.
service GRPCStdio {
// StreamStdio returns a stream that contains all the stdout/stderr.
// This RPC endpoint must only be called ONCE. Once stdio data is consumed
// it is not sent again.
//
// Callers should connect early to prevent blocking on the plugin process.
rpc StreamStdio(google.protobuf.Empty) returns (stream StdioData);
}
// StdioData is a single chunk of stdout or stderr data that is streamed
// from GRPCStdio.
message StdioData {
enum Channel {
INVALID = 0;
STDOUT = 1;
STDERR = 2;
}
Channel channel = 1;
bytes data = 2;
}

View File

@ -0,0 +1,148 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: internal/plugin/grpc_stdio.proto
package plugin
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
GRPCStdio_StreamStdio_FullMethodName = "/plugin.GRPCStdio/StreamStdio"
)
// GRPCStdioClient is the client API for GRPCStdio service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GRPCStdioClient interface {
// StreamStdio returns a stream that contains all the stdout/stderr.
// This RPC endpoint must only be called ONCE. Once stdio data is consumed
// it is not sent again.
//
// Callers should connect early to prevent blocking on the plugin process.
StreamStdio(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (GRPCStdio_StreamStdioClient, error)
}
type gRPCStdioClient struct {
cc grpc.ClientConnInterface
}
func NewGRPCStdioClient(cc grpc.ClientConnInterface) GRPCStdioClient {
return &gRPCStdioClient{cc}
}
func (c *gRPCStdioClient) StreamStdio(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (GRPCStdio_StreamStdioClient, error) {
stream, err := c.cc.NewStream(ctx, &GRPCStdio_ServiceDesc.Streams[0], GRPCStdio_StreamStdio_FullMethodName, opts...)
if err != nil {
return nil, err
}
x := &gRPCStdioStreamStdioClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type GRPCStdio_StreamStdioClient interface {
Recv() (*StdioData, error)
grpc.ClientStream
}
type gRPCStdioStreamStdioClient struct {
grpc.ClientStream
}
func (x *gRPCStdioStreamStdioClient) Recv() (*StdioData, error) {
m := new(StdioData)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// GRPCStdioServer is the server API for GRPCStdio service.
// All implementations should embed UnimplementedGRPCStdioServer
// for forward compatibility
type GRPCStdioServer interface {
// StreamStdio returns a stream that contains all the stdout/stderr.
// This RPC endpoint must only be called ONCE. Once stdio data is consumed
// it is not sent again.
//
// Callers should connect early to prevent blocking on the plugin process.
StreamStdio(*emptypb.Empty, GRPCStdio_StreamStdioServer) error
}
// UnimplementedGRPCStdioServer should be embedded to have forward compatible implementations.
type UnimplementedGRPCStdioServer struct {
}
func (UnimplementedGRPCStdioServer) StreamStdio(*emptypb.Empty, GRPCStdio_StreamStdioServer) error {
return status.Errorf(codes.Unimplemented, "method StreamStdio not implemented")
}
// UnsafeGRPCStdioServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GRPCStdioServer will
// result in compilation errors.
type UnsafeGRPCStdioServer interface {
mustEmbedUnimplementedGRPCStdioServer()
}
func RegisterGRPCStdioServer(s grpc.ServiceRegistrar, srv GRPCStdioServer) {
s.RegisterService(&GRPCStdio_ServiceDesc, srv)
}
func _GRPCStdio_StreamStdio_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(emptypb.Empty)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(GRPCStdioServer).StreamStdio(m, &gRPCStdioStreamStdioServer{stream})
}
type GRPCStdio_StreamStdioServer interface {
Send(*StdioData) error
grpc.ServerStream
}
type gRPCStdioStreamStdioServer struct {
grpc.ServerStream
}
func (x *gRPCStdioStreamStdioServer) Send(m *StdioData) error {
return x.ServerStream.SendMsg(m)
}
// GRPCStdio_ServiceDesc is the grpc.ServiceDesc for GRPCStdio service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var GRPCStdio_ServiceDesc = grpc.ServiceDesc{
ServiceName: "plugin.GRPCStdio",
HandlerType: (*GRPCStdioServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{
{
StreamName: "StreamStdio",
Handler: _GRPCStdio_StreamStdio_Handler,
ServerStreams: true,
},
},
Metadata: "internal/plugin/grpc_stdio.proto",
}