{"modulePath":"github.com/newstack-cloud/bluelink/libs/plugin-framework","version":"v0.17.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Constants\n\n```go\nconst (\n\t// DeployEnginePluginPathEnvVar is the name of the environment variable\n\t// that should be set to a colon-separated list of directories to search\n\t// for plugins in.\n\tDeployEnginePluginPathEnvVar = \"BLUELINK_DEPLOY_ENGINE_PLUGIN_PATH\"\n\t// DeployEnginePluginLaunchAttemptLimitEnvVar is the name of the environment\n\t// variable that should be set to the number of times to attempt launching\n\t// a plugin before giving up.\n\tDeployEnginePluginLaunchAttemptLimitEnvVar = \"BLUELINK_DEPLOY_ENGINE_PLUGIN_LAUNCH_ATTEMPT_LIMIT\"\n\t// DeployEnginePluginLogFileRootDirEnvVar is the name of the environment variable\n\t// that should be set to the root directory for plugin log files.\n\tDeployEnginePluginLogFileRootDirEnvVar = \"BLUELINK_DEPLOY_ENGINE_PLUGIN_LOG_FILE_ROOT_DIR\"\n)\n```\n\n```go\nconst (\n\t// DefaultPluginLaunchAttemptLimit is the default number of times to attempt\n\t// launching a plugin before giving up.\n\tDefaultPluginLaunchAttemptLimit = 5\n\t// DefaultLaunchWaitTimeout is the default timeout to wait for a plugin to register\n\t// with the host service.\n\tDefaultLaunchWaitTimeout = 20 * time.Millisecond\n\t// DefaultCheckRegisteredInterval is the default interval to check if a plugin has\n\t// registered with the host service.\n\tDefaultCheckRegisteredInterval = 5 * time.Millisecond\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrPluginRegistrationTimeout is returned when a plugin does not register\n\t// with the host service within the wait timeout.\n\tErrPluginRegistrationTimeout = errors.New(\"plugin registration timeout\")\n)\n```\n\n```go\nvar (\n\t// ErrUnsupportedProviderProtocolVersion is returned when the protocol version\n\t// is not supported.\n\tErrUnsupportedProviderProtocolVersion = errors.New(\"unsupported provider protocol version\")\n)\n```\n\n```go\nvar (\n\t// ErrUnsupportedTransformerProtocolVersion is returned when the protocol version\n\t// is not supported.\n\tErrUnsupportedTransformerProtocolVersion = errors.New(\"unsupported transformer protocol version\")\n)\n```\n\n## Functions\n\n```go\nfunc CreatePluginInstance(info *pluginservicev1.PluginInstanceInfo, hostID string) (any, func(), error)\n```\nCreatePluginInstance is a function that creates a new instance of a plugin. This implements the pluginservicev1.PluginFactory interface.\n\n```go\nfunc ServeProviderV1(\n\tctx context.Context,\n\tproviderServer any,\n\tpluginServiceClient pluginservicev1.ServiceClient,\n\thostInfoContainer pluginutils.HostInfoContainer,\n\tconfig ServePluginConfiguration,\n) (func(), error)\n```\nServeProviderV1 handles serving the v1 provider plugin with the given providerServer and options. This will deal with registering the provider with the host service.\n\n```go\nfunc ServeTransformerV1(\n\tctx context.Context,\n\ttransformerServer any,\n\tpluginServiceClient pluginservicev1.ServiceClient,\n\thostInfoContainer pluginutils.HostInfoContainer,\n\tconfig ServePluginConfiguration,\n) (func(), error)\n```\nServeTransformerV1 handles serving the v1 transformer plugin with the given transformerServer and options. This will deal with registering the transformer with the host service.\n\n## Types\n\n```go\ntype Launcher struct {\n\t// contains filtered or unexported fields\n}\n```\nLauncher is a service that launches plugins and waits for them to register with the host service.\n\n```go\nfunc NewLauncher(\n\tpluginPath string,\n\tmanager pluginservicev1.Manager,\n\texecutor PluginExecutor,\n\tlogger core.Logger,\n\topts ...LauncherOption,\n) *Launcher\n```\nNewLauncher creates a new Launcher.\n\n```go\nfunc (l *Launcher) Launch(ctx context.Context) (*PluginMaps, error)\n```\nLaunch discovers, executes plugin binaries and waits for the plugins to have registered with the host service. This returns a set of adaptors that can be used as maps of providers and transformers to be used to create a blueprint loader.\n\nThe provided plugin path is expected to be a list of root directories separated by os.PathListSeparator (colon on Unix, semicolon on Windows).\n\nThe provided context should set a deadline to avoid waiting indefinitely for plugins to register with the host service.\n\n```go\ntype LauncherOption func(*Launcher)\n```\nLauncherOption is a function that configures a Launcher.\n\n```go\nfunc WithLauncherAttemptLimit(attemptLimit int) LauncherOption\n```\nWithLauncherAttemptLimit is a Launcher option that sets the number of times to attempt launching a plugin before giving up.\n\n```go\nfunc WithLauncherCheckRegisteredInterval(interval time.Duration) LauncherOption\n```\nWithLauncherCheckRegisteredInterval is a Launcher option that sets the interval to check if a plugin has registered with the host service.\n\n```go\nfunc WithLauncherFS(fs afero.Fs) LauncherOption\n```\nWithLauncherFS is a Launcher option that sets the file system to use when discovering plugins.\n\n```go\nfunc WithLauncherTransformerKeyType(keyType TransformerKeyType) LauncherOption\n```\nWithLauncherTransformerKeyType is a Launcher option that sets the key type to use for transformer plugins.\n\n```go\nfunc WithLauncherWaitTimeout(timeout time.Duration) LauncherOption\n```\nWithLauncherWaitTimeout is a Launcher option that sets the timeout to wait for a plugin to register with the host service.\n\n```go\ntype PluginExecutor interface {\n\t// Execute the plugin binary at the given path.\n\tExecute(pluginID string, pluginBinary string) (PluginProcess, error)\n}\n```\nPluginExecutor is an interface that represents the executor of a plugin. This interface is used to abstract the execution of a plugin from the plugin launcher.\n\n```go\nfunc NewOSCmdExecutor(\n\tlogFileRootDir string,\n\tenv map[string]string,\n) PluginExecutor\n```\nNewOSCmdExecutor creates a new PluginExecutor that uses an operating system command to execute the plugin binary. stdout and stderr for each plugin will be redirected to a log file for the plugin under the logFileRootDir directory. The log file will be located at: {logFileRootDir}/({pluginHost}/?)/{namespace}/{pluginName}/plugin.log\n\n```go\ntype PluginMaps struct {\n\tProviders    map[string]provider.Provider\n\tTransformers map[string]transform.SpecTransformer\n}\n```\nPluginMaps is a set of adaptors that can be used as maps of providers and transformers to be used to create a blueprint loader.\n\n```go\ntype PluginPathInfo struct {\n\t// The absolute path to the plugin executable.\n\tAbsolutePath string\n\t// The plugin type extracted from the path.\n\tPluginType string\n\t// The ID of the plugin extracted from the path.\n\t// This is essential to track the plugins that have\n\t// registered with the host service.\n\tID string\n\t// The version of the plugin extracted from the path.\n\tVersion string\n}\n```\nPluginPathInfo contains important metadata extracted from a plugin path.\n\n```go\nfunc DiscoverPlugins(pluginPath string, fs afero.Fs, logger bpcore.Logger) ([]*PluginPathInfo, error)\n```\nDiscoverPlugins handles the discovery of plugins in the current host environment. The provided plugin path is expected to be a list of root directories separated by os.PathListSeparator (colon on Unix, semicolon on Windows). This returns a list of discovered plugin paths with important plugin metadata extracted from the file paths.\n\n```go\ntype PluginProcess interface {\n\t// Kill the plugin process.\n\tKill() error\n}\n```\nPluginProcess is an interface that represents a running plugin process.\n\n```go\ntype ServePluginConfiguration struct {\n\t// The unique identifier for the plugin.\n\t// In addition to being unique, the ID should point to the location\n\t// where the plugin can be downloaded.\n\t// {hostname/}?{namespace}/{pluginName}\n\t//\n\t// For example:\n\t// registry.bluelink.dev/bluelink/aws\n\t// bluelink/aws\n\t//\n\t// For providers, the last portion of the ID is the unique name of the provider\n\t// that is expected to be used as the namespace for resources, data sources\n\t// and custom variable types used in blueprints.\n\t// For example, the namespace for AWS resources is \"aws\"\n\t// used in the resource type \"aws/lambda/function\".\n\t// For transformers, the last portion of the ID is the unique name of the transformer,\n\t// unlike providers, transformer elements are not namespaced so it is purely an ID\n\t// for the plugin.\n\tID string\n\n\t// ProtocolVersion is the protocol version that should be\n\t// used for the plugin.\n\t// Currently, the only supported protocol version is \"1.0\".\n\tProtocolVersion string\n\n\t// PluginMetadata is the metadata for the plugin.\n\t// This is used to provide information about the plugin\n\t// to the host service.\n\tPluginMetadata *pluginservicev1.PluginMetadata\n\n\t// Debug runs the plugin in a mode compatible with\n\t// debugging processes such as delve.\n\tDebug bool\n\n\t// UnixSocketPath is the path to the Unix socket that the\n\t// plugin should listen on.\n\t// If this is set, the TCPPort should be empty.\n\tUnixSocketPath string\n\n\t// TCPPort is the port that the plugin should listen on.\n\t// If this is set, the UnixSocketPath should be empty.\n\t// If this is not set and UnixSocketPath is not set, the\n\t// plugin will listen on the next available port.\n\tTCPPort int\n\n\t// Listener is the listener that the plugin server should use.\n\t// If this is provided, TCPPort and UnixSocketPath will be ignored.\n\tListener net.Listener\n}\n```\nServePluginConfiguration contains configuration for serving a plugin.\n\n```go\ntype TransformerKeyType int32\n```\nTransformerKeyType defines the type of key to be used to identify a transformer in the plugin map produced by the plugin launcher. Transformer plugins can either be keyed by the plugin name (namespace) or the transform string name used in the transform section of a blueprint.\n\n```go\nconst (\n\t// TransformerKeyTypePluginName indicates that the plugin should be keyed\n\t// by the plugin name (namespace).\n\tTransformerKeyTypePluginName TransformerKeyType = iota\n\t// TransformerKeyTypeTransformName indicates that the plugin should be keyed\n\t// by the transform string name used in the transform section of a blueprint.\n\t// This is the default value when one isn't provided to the plugin launcher.\n\tTransformerKeyTypeTransformName\n)\n```\n\n","path":"github.com/newstack-cloud/bluelink/libs/plugin-framework/plugin","name":"plugin","synopsis":"","isRedistributable":true}
