github.com/outbrain/consul@v1.4.5/agent/connect/ca/plugin/plugin.go (about)

     1  package plugin
     2  
     3  import (
     4  	"context"
     5  	"net/rpc"
     6  
     7  	"github.com/hashicorp/consul/agent/connect/ca"
     8  	"github.com/hashicorp/go-plugin"
     9  	"google.golang.org/grpc"
    10  )
    11  
    12  // ProviderPlugin implements plugin.Plugin for initializing a plugin
    13  // server and client for both net/rpc and gRPC.
    14  type ProviderPlugin struct {
    15  	Impl ca.Provider
    16  }
    17  
    18  func (p ProviderPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
    19  	return &providerPluginRPCServer{impl: p.Impl}, nil
    20  }
    21  
    22  func (ProviderPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
    23  	return &providerPluginRPCClient{client: c}, nil
    24  }
    25  
    26  func (p ProviderPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error {
    27  	RegisterCAServer(s, &providerPluginGRPCServer{impl: p.Impl})
    28  	return nil
    29  }
    30  
    31  func (ProviderPlugin) GRPCClient(doneCtx context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
    32  	return &providerPluginGRPCClient{
    33  		client:     NewCAClient(c),
    34  		clientConn: c,
    35  		doneCtx:    doneCtx,
    36  	}, nil
    37  }
    38  
    39  // Verification
    40  var _ plugin.Plugin = ProviderPlugin{}
    41  var _ plugin.GRPCPlugin = ProviderPlugin{}