catalog

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 33 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHostServer

func NewHostServer(pluginName string, opts []grpc.ServerOption, hostServices []HostServiceServer) *grpc.Server

func PluginMain

func PluginMain(plugin Plugin)

func PluginNameFromHostServiceContext

func PluginNameFromHostServiceContext(ctx context.Context) (string, bool)

func WithPluginName

func WithPluginName(ctx context.Context, name string) context.Context

Types

type BuiltInPlugin

type BuiltInPlugin struct {
	Log          logrus.FieldLogger
	Plugin       Plugin
	HostServices []HostServiceServer
}

type Catalog

type Catalog interface {
	// Fill fills up a "catalog" with client interfaces to interface with
	// the plugins and services offered by loaded plugins. The shape of the
	// "catalog" determines the constraints and requirements of the plugins.
	//
	// The "catalog" can be a pointer to an interface:
	//
	//   // Fill() will fail if there are no plugins that implement NodeAttestor
	//   var na nodeattestor.NodeAttestor
	//   cat, _ := catalog.Load(...)
	//   cat.Fill(&c)	//   catalog.Fill(&na)
	//
	// The "catalog" can also be a pointer to a struct:
	//
	//    type TheCatalog struct {
	//       // A required interface. Fill() fails if there is not exactly
	//       // one plugin matching this interface.
	//       RequiredPlugin nodeattestor.NodeAttestor
	//
	//       // An optional interface. Fill() fails if there are more than
	//       // one plugin that match this interface.
	//       OptionalPlugin *nodeattestor.NodeAttestor
	//
	//       // A slice of interfaces.
	//       Plugins []nodeattestor.NodeAttestor
	//
	//       // A map from string to interface. The key of the map is the name
	//       // of the plugin that matched.
	//       PluginsByName map[string]nodeattestor.NodeAttestor
	//
	//       // A struct of interfaces. A plugin must satisfy all interfaces //
	//       // within the struct to match. Fill() fails if there is not
	//       // exactly one plugin that matches.
	//       RequiredPluginStruct StructOfInterface
	//
	//       // A pointer to a struct of interfaces. A plugin must satisfy all
	//       // interfaces within the struct to meet the criteria. Fill() fails
	//       // if there are more than one plugin that matches.
	//       OptionalPluginStruct *StructOfInterface
	//
	//       // A slice of a struct of interfaces.
	//       PluginStructs []StructOfInterface
	//
	//       // A map from string to struct of interfaces. The key of the map
	//       // is the name of the plugin that matched.
	//       PluginStructsByName map[string]StructOfInterface
	//   }
	//
	//   type StructOfInterface struct {
	//       // The PluginInfo interface is special and is implemented on all
	//       // plugins.
	//       catalog.PluginInfo
	//
	//       nodeattestor.NodeAttestor
	//   }
	//
	//   var c TheCatalog
	//   cat, _ := catalog.Load(...)
	//   cat.Fill(&c)
	//
	//   In addition, the slice and map struct fields support imposing minimum
	//   and maximum constraints on the number of plugins to populate that
	//   field. For example:
	//
	//   struct {
	//       AtLeastTwo []nodeattestor.NodeAttestor `catalog:"min=2"`
	//       AtMostTwo []nodeattestor.NodeAttestor `catalog:"max=2"`
	//       BetweenThreeAndFive []nodeattestor.NodeAttestor `catalog:"min=3,max=5"`
	//   }
	//
	Fill(x interface{}) error

	// Close() closes the catalog, shutting down servers and killing external
	// plugin processes.
	Close()
}

Catalog provides a method to obtain clients to loaded plugins and services.

func Load

func Load(ctx context.Context, config Config) (_ Catalog, err error)

type Closer

type Closer interface {
	Close()
}

func Fill

func Fill(ctx context.Context, config Config, x interface{}) (Closer, error)

type Config

type Config struct {
	Log logrus.FieldLogger

	// GlobalConfig is passed to plugins during configuration.
	GlobalConfig GlobalConfig

	// PluginConfig is the configuration of plugins to load.
	PluginConfig []PluginConfig

	// KnownPlugins is the set of known external plugins.
	KnownPlugins []PluginClient

	// KnownServices is the set of known external services.
	KnownServices []ServiceClient

	// HostServices is a set of services offered by the host.
	HostServices []HostServiceServer

	// BuiltIns is the set of builtin plugins available to the host.
	BuiltIns []Plugin
}

type ExternalPlugin

type ExternalPlugin struct {
	Log           logrus.FieldLogger
	Name          string
	Path          string
	Checksum      string
	Data          string
	Plugin        PluginClient
	KnownServices []ServiceClient
	HostServices  []HostServiceServer
}

type HCLPluginConfig

type HCLPluginConfig struct {
	PluginCmd      string   `hcl:"plugin_cmd"`
	PluginChecksum string   `hcl:"plugin_checksum"`
	PluginData     ast.Node `hcl:"plugin_data"`
	Enabled        *bool    `hcl:"enabled"`
}

HCLPluginConfig serves as an intermediary struct. We pass this to the HCL library for parsing, except the parser won't parse pluginData as a string.

func (HCLPluginConfig) IsEnabled

func (c HCLPluginConfig) IsEnabled() bool

type HCLPluginConfigMap

type HCLPluginConfigMap map[string]map[string]HCLPluginConfig

type HostServiceBroker

type HostServiceBroker interface {
	GetHostService(HostServiceClient) (has bool, err error)
}

HostServiceBroker is used by plugins that implement the NeedsHostBroker service to obtain host service clients.

type HostServiceClient

type HostServiceClient interface {
	HostServiceType() string

	// InitHostServiceClient initializes the host service client.
	InitHostServiceClient(conn *grpc.ClientConn)
}

HostServiceClient is used to initialize a host service client.

type HostServiceServer

type HostServiceServer interface {
	// HostServiceType returns the host service type
	HostServiceType() string

	// RegisterHostServiceServer registers the host service server.
	RegisterHostServiceServer(*grpc.Server)
}

HostServiceServer is used to register a host service server.

type LoadedPlugin

type LoadedPlugin struct {
	// contains filtered or unexported fields
}

func LoadBuiltInPlugin

func LoadBuiltInPlugin(ctx context.Context, builtin BuiltInPlugin) (plugin *LoadedPlugin, err error)

LoadBuiltIn loads a builtin plugin.

func LoadExternalPlugin

func LoadExternalPlugin(ctx context.Context, ext ExternalPlugin) (plugin *LoadedPlugin, err error)

func (*LoadedPlugin) BuiltIn added in v0.11.0

func (p *LoadedPlugin) BuiltIn() bool

func (*LoadedPlugin) Close

func (p *LoadedPlugin) Close()

func (*LoadedPlugin) Configure

func (p *LoadedPlugin) Configure(ctx context.Context, req *spi.ConfigureRequest) error

func (*LoadedPlugin) Fill

func (p *LoadedPlugin) Fill(x interface{}) (err error)

func (*LoadedPlugin) Name

func (p *LoadedPlugin) Name() string

type NeedsHostServices

type NeedsHostServices interface {
	BrokerHostServices(HostServiceBroker) error
}

NeedsHostServices is implemented by plugin/service implementations that need to obtain clients to host services.

type NeedsLogger

type NeedsLogger interface {
	SetLogger(hclog.Logger)
}

NeedsLogger is implemented by plugin/service implementations that need a logger that is connected to the SPIRE core logger.

type PipeAddr

type PipeAddr struct {
}

func (PipeAddr) Network

func (PipeAddr) Network() string

func (PipeAddr) String

func (PipeAddr) String() string

type PipeNet

type PipeNet struct {
	// contains filtered or unexported fields
}

func NewPipeNet

func NewPipeNet() *PipeNet

func (*PipeNet) Accept

func (n *PipeNet) Accept() (net.Conn, error)

func (*PipeNet) Addr

func (n *PipeNet) Addr() net.Addr

func (*PipeNet) Close

func (n *PipeNet) Close() error

func (*PipeNet) DialContext

func (n *PipeNet) DialContext(ctx context.Context, addr string) (conn net.Conn, err error)

type Plugin

type Plugin struct {
	Name     string
	Plugin   PluginServer
	Services []ServiceServer
}

func MakePlugin

func MakePlugin(name string, plugin PluginServer, services ...ServiceServer) Plugin

type PluginClient

type PluginClient interface {
	PluginType() string

	// NewPluginClient initializes and returns a service client.
	NewPluginClient(*grpc.ClientConn) interface{}
}

PluginClient is used to initialize and return a plugin client.

type PluginConfig

type PluginConfig struct {
	Name     string
	Type     string
	Path     string
	Checksum string
	Data     string
	Disabled bool
}

func ParsePluginConfigFromHCL

func ParsePluginConfigFromHCL(config string) ([]PluginConfig, error)

func PluginConfigFromHCL

func PluginConfigFromHCL(hclPlugins HCLPluginConfigMap) ([]PluginConfig, error)

type PluginInfo

type PluginInfo interface {
	Name() string
	BuiltIn() bool
}

type PluginServer

type PluginServer interface {
	// PluginType returns the plugin type
	PluginType() string

	// PluginClient returns the PluginClient interface for this server.
	PluginClient() PluginClient

	// Registers the implementation against the provided gRPC server and
	// returns the implementation. The implementation is used to wire up
	// logging and host services.
	RegisterPluginServer(server *grpc.Server) interface{}
}

PluginServer is the interface for both the primary interface and auxiliary services served by the plugin.

type ServiceClient

type ServiceClient interface {
	// ServiceType returns the service type
	ServiceType() string

	// NewServiceClient initializes and returns a service client.
	NewServiceClient(*grpc.ClientConn) interface{}
}

ServiceClient is used to initialize and return a service client.

type ServiceServer

type ServiceServer interface {
	// ServiceType returns the service type
	ServiceType() string

	// ServiceClient returns the PluginClient interface for this server.
	ServiceClient() ServiceClient

	// Registers the implementation against the provided gRPC server and
	// returns the implementation. The implementation is used to wire up
	// logging and host services.
	RegisterServiceServer(server *grpc.Server) interface{}
}

ServiceServer is the interface for both the primary interface and auxiliary services served by the plugin.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL