plugin

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownBoolValue is a sentinel indicating that a bool property's value is not known, because it depends on
	// a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownBoolValue = "1c4a061d-8072-4f0a-a4cb-0ff528b18fe7"
	// UnknownNumberValue is a sentinel indicating that a number property's value is not known, because it depends on
	// a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownNumberValue = "3eeb2bf0-c639-47a8-9e75-3b44932eb421"
	// UnknownStringValue is a sentinel indicating that a string property's value is not known, because it depends on
	// a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownStringValue = "04da6b54-80e4-46f7-96ec-b56ff0331ba9"
	// UnknownArrayValue is a sentinel indicating that an array property's value is not known, because it depends on
	// a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownArrayValue = "6a19a0b0-7e62-4c92-b797-7f8e31da9cc2"
	// UnknownAssetValue is a sentinel indicating that an asset property's value is not known, because it depends on
	// a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownAssetValue = "030794c1-ac77-496b-92df-f27374a8bd58"
	// UnknownArchiveValue is a sentinel indicating that an archive property's value is not known, because it depends
	// on a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownArchiveValue = "e48ece36-62e2-4504-bad9-02848725956a"
	// UnknownObjectValue is a sentinel indicating that an archive property's value is not known, because it depends
	// on a computation with values whose values themselves are not yet known (e.g., dependent upon an output property).
	UnknownObjectValue = "dd056dcd-154b-4c76-9bd3-c8f88648b5ff"
)

Variables

AllPlugins uses flags to ensure that all plugin kinds are loaded.

Functions

func MarshalArchive

func MarshalArchive(v *resource.Archive, opts MarshalOptions) (*structpb.Value, error)

MarshalArchive marshals an archive into its wire form for resource provider plugins.

func MarshalAsset

func MarshalAsset(v *resource.Asset, opts MarshalOptions) (*structpb.Value, error)

MarshalAsset marshals an asset into its wire form for resource provider plugins.

func MarshalNull

func MarshalNull(opts MarshalOptions) *structpb.Value

MarshalNull marshals a nil to its protobuf form.

func MarshalProperties

func MarshalProperties(props resource.PropertyMap, opts MarshalOptions) (*structpb.Struct, error)

MarshalProperties marshals a resource's property map as a "JSON-like" protobuf structure.

func MarshalPropertyValue

func MarshalPropertyValue(v resource.PropertyValue, opts MarshalOptions) (*structpb.Value, error)

MarshalPropertyValue marshals a single resource property value into its "JSON-like" value representation.

func MarshalString

func MarshalString(s string, opts MarshalOptions) *structpb.Value

MarshalString marshals a string to its protobuf form.

func MarshalStruct

func MarshalStruct(obj *structpb.Struct, opts MarshalOptions) *structpb.Value

MarshalStruct marshals a struct for use in a protobuf field where a value is expected.

func NewCheckResponse

func NewCheckResponse(err error) *lumirpc.CheckResponse

NewCheckResponse produces a response with property validation failures from the given array of mapper failures.

func NewMissingError

func NewMissingError(info workspace.PluginInfo) error

NewMissingError allocates a new error indicating the given plugin info was not found.

func UnmarshalProperties

func UnmarshalProperties(props *structpb.Struct, opts MarshalOptions) (resource.PropertyMap, error)

UnmarshalProperties unmarshals a "JSON-like" protobuf structure into a new resource property map.

func UnmarshalPropertyValue

func UnmarshalPropertyValue(v *structpb.Value, opts MarshalOptions) (*resource.PropertyValue, error)

UnmarshalPropertyValue unmarshals a single "JSON-like" value into a new property value.

Types

type AnalyzeFailure

type AnalyzeFailure struct {
	Property resource.PropertyKey // the property that failed the analysis.
	Reason   string               // the reason the property failed the analysis.
}

AnalyzeFailure indicates that resource analysis failed; it contains the property and reason for the failure.

type Analyzer

type Analyzer interface {
	// Closer closes any underlying OS resources associated with this provider (like processes, RPC channels, etc).
	io.Closer
	// Name fetches an analyzer's qualified name.
	Name() tokens.QName
	// Analyze analyzes a single resource object, and returns any errors that it finds.
	Analyze(t tokens.Type, props resource.PropertyMap) ([]AnalyzeFailure, error)
	// GetPluginInfo returns this plugin's information.
	GetPluginInfo() (workspace.PluginInfo, error)
}

Analyzer provides a pluggable interface for performing arbitrary analysis of entire projects/stacks/snapshots, and/or individual resources, for arbitrary issues. These might be style, policy, correctness, security, or performance related. This interface hides the messiness of the underlying machinery, since providers are behind an RPC boundary.

func NewAnalyzer

func NewAnalyzer(host Host, ctx *Context, name tokens.QName) (Analyzer, error)

NewAnalyzer binds to a given analyzer's plugin by name and creates a gRPC connection to it. If the associated plugin could not be found by name on the PATH, or an error occurs while creating the child process, an error is returned.

type CheckFailure

type CheckFailure struct {
	Property resource.PropertyKey // the property that failed checking.
	Reason   string               // the reason the property failed to check.
}

CheckFailure indicates that a call to check failed; it contains the property and reason for the failure.

type ConfigSource

type ConfigSource interface {
	// GetPackageConfig returns the set of configuration parameters for the indicated package, if any.
	GetPackageConfig(pkg tokens.Package) (map[config.Key]string, error)
}

ConfigSource is an interface that allows a plugin context to fetch configuration data for a plugin named by package.

type Context

type Context struct {
	Diag       diag.Sink // the diagnostics sink to use for messages.
	StatusDiag diag.Sink // the diagnostics sink to use for status messages.
	Host       Host      // the host that can be used to fetch providers.
	Pwd        string    // the working directory to spawn all plugins in.
	// contains filtered or unexported fields
}

Context is used to group related operations together so that associated OS resources can be cached, shared, and reclaimed as appropriate.

func NewContext

func NewContext(d, statusD diag.Sink, host Host, cfg ConfigSource, events Events,
	pwd string, runtimeOptions map[string]interface{}, parentSpan opentracing.Span) (*Context, error)

NewContext allocates a new context with a given sink and host. Note that the host is "owned" by this context from here forwards, such that when the context's resources are reclaimed, so too are the host's.

func (*Context) Close

func (ctx *Context) Close() error

Close reclaims all resources associated with this context.

func (*Context) Request

func (ctx *Context) Request() context.Context

Request allocates a request sub-context.

type DiffChanges

type DiffChanges int

DiffChanges represents the kind of changes detected by a diff operation.

const (
	// DiffUnknown indicates the provider didn't offer information about the changes (legacy behavior).
	DiffUnknown DiffChanges = 0
	// DiffNone indicates the provider performed a diff and concluded that no update is needed.
	DiffNone DiffChanges = 1
	// DiffSome indicates the provider performed a diff and concluded that an update or replacement is needed.
	DiffSome DiffChanges = 2
)

type DiffResult

type DiffResult struct {
	Changes             DiffChanges            // true if this diff represents a changed resource.
	ReplaceKeys         []resource.PropertyKey // an optional list of replacement keys.
	StableKeys          []resource.PropertyKey // an optional list of property keys that are stable.
	DeleteBeforeReplace bool                   // if true, this resource must be deleted before recreating it.
}

DiffResult indicates whether an operation should replace or update an existing resource.

func (DiffResult) Replace

func (r DiffResult) Replace() bool

Replace returns true if this diff represents a replacement.

type Events

type Events interface {
	// OnPluginLoad is fired by the plugin host whenever a new plugin is successfully loaded.
	// newPlugin is the plugin that was loaded.
	OnPluginLoad(newPlugin workspace.PluginInfo) error
}

Events provides higher-level consumers of the plugin model to attach callbacks on plugin load events.

type Flags

type Flags int

Flags can be used to filter out plugins during loading that aren't necessary.

const (
	// AnalyzerPlugins is used to only load analyzers.
	AnalyzerPlugins Flags = 1 << iota
	// LanguagePlugins is used to only load language plugins.
	LanguagePlugins
	// ResourcePlugins is used to only load resource provider plugins.
	ResourcePlugins
)

type Host

type Host interface {
	// ServerAddr returns the address at which the host's RPC interface may be found.
	ServerAddr() string

	// Log logs a message, including errors and warnings.  Messages can have a resource URN
	// associated with them.  If no urn is provided, the message is global.
	Log(sev diag.Severity, urn resource.URN, msg string, streamID int32)

	// LogStatus logs a status message message, including errors and warnings. Status messages show
	// up in the `Info` column of the progress display, but not in the final output. Messages can
	// have a resource URN associated with them.  If no urn is provided, the message is global.
	LogStatus(sev diag.Severity, urn resource.URN, msg string, streamID int32)

	// Analyzer fetches the analyzer with a given name, possibly lazily allocating the plugins for it.  If an analyzer
	// could not be found, or an error occurred while creating it, a non-nil error is returned.
	Analyzer(nm tokens.QName) (Analyzer, error)
	// Provider loads a new copy of the provider for a given package.  If a provider for this package could not be
	// found, or an error occurs while creating it, a non-nil error is returned.
	Provider(pkg tokens.Package, version *semver.Version) (Provider, error)
	// CloseProvider closes the given provider plugin and deregisters it from this host.
	CloseProvider(provider Provider) error
	// LanguageRuntime fetches the language runtime plugin for a given language, lazily allocating if necessary.  If
	// an implementation of this language runtime wasn't found, on an error occurs, a non-nil error is returned.
	LanguageRuntime(runtime string) (LanguageRuntime, error)

	// ListPlugins lists all plugins that have been loaded, with version information.
	ListPlugins() []workspace.PluginInfo
	// EnsurePlugins ensures all plugins in the given array are loaded and ready to use.  If any plugins are missing,
	// and/or there are errors loading one or more plugins, a non-nil error is returned.
	EnsurePlugins(plugins []workspace.PluginInfo, kinds Flags) error
	// GetRequiredPlugins lists a full set of plugins that will be required by the given program.
	GetRequiredPlugins(info ProgInfo, kinds Flags) ([]workspace.PluginInfo, error)

	// SignalCancellation asks all resource providers to gracefully shut down and abort any ongoing
	// operations. Operation aborted in this way will return an error (e.g., `Update` and `Create`
	// will either a creation error or an initialization error. SignalCancellation is advisory and
	// non-blocking; it is up to the host to decide how long to wait after SignalCancellation is
	// called before (e.g.) hard-closing any gRPC connection.
	SignalCancellation() error

	// Close reclaims any resources associated with the host.
	Close() error
}

A Host hosts provider plugins and makes them easily accessible by package name.

func NewDefaultHost

func NewDefaultHost(ctx *Context, config ConfigSource, events Events,
	runtimeOptions map[string]interface{}) (Host, error)

NewDefaultHost implements the standard plugin logic, using the standard installation root to find them.

type InitError added in v0.15.0

type InitError struct {
	Reasons []string
}

InitError represents a failure to initialize a resource, i.e., the resource has been successfully created, but it has failed to initialize.

func (*InitError) Error added in v0.15.0

func (ie *InitError) Error() string

type LanguageRuntime

type LanguageRuntime interface {
	// Closer closes any underlying OS resources associated with this plugin (like processes, RPC channels, etc).
	io.Closer
	// GetRequiredPlugins computes the complete set of anticipated plugins required by a program.
	GetRequiredPlugins(info ProgInfo) ([]workspace.PluginInfo, error)
	// Run executes a program in the language runtime for planning or deployment purposes.  If info.DryRun is true,
	// the code must not assume that side-effects or final values resulting from resource deployments are actually
	// available.  If it is false, on the other hand, a real deployment is occurring and it may safely depend on these.
	Run(info RunInfo) (string, error)
	// GetPluginInfo returns this plugin's information.
	GetPluginInfo() (workspace.PluginInfo, error)
}

LanguageRuntime is a convenient interface for interacting with language runtime plugins. These tend to be dynamically loaded as plugins, although this interface hides this fact from the calling code.

func NewLanguageRuntime

func NewLanguageRuntime(host Host, ctx *Context, runtime string,
	options map[string]interface{}) (LanguageRuntime, error)

NewLanguageRuntime binds to a language's runtime plugin and then creates a gRPC connection to it. If the plugin could not be found, or an error occurs while creating the child process, an error is returned.

type MarshalOptions

type MarshalOptions struct {
	Label              string // an optional label for debugging.
	SkipNulls          bool   // true to skip nulls altogether in the resulting map.
	KeepUnknowns       bool   // true if we are keeping unknown values (otherwise we skip them).
	RejectUnknowns     bool   // true if we should return errors on unknown values. Takes precedence over KeepUnknowns.
	ElideAssetContents bool   // true if we are eliding the contents of assets.
	ComputeAssetHashes bool   // true if we are computing missing asset hashes on the fly.
}

MarshalOptions controls the marshaling of RPC structures.

type MissingError

type MissingError struct {
	// Info contains information about the plugin that was not found.
	Info workspace.PluginInfo
}

MissingError is returned if a plugin is missing.

func (*MissingError) Error

func (err *MissingError) Error() string

type ProgInfo

type ProgInfo struct {
	Proj    *workspace.Project // the program project/package.
	Pwd     string             // the program's working directory.
	Program string             // the path to the program to execute.
}

ProgInfo contains minimal information about the program to be run.

type Provider

type Provider interface {
	// Closer closes any underlying OS resources associated with this provider (like processes, RPC channels, etc).
	io.Closer
	// Pkg fetches this provider's package.
	Pkg() tokens.Package

	// CheckConfig validates the configuration for this resource provider.
	CheckConfig(olds, news resource.PropertyMap) (resource.PropertyMap, []CheckFailure, error)
	// DiffConfig checks what impacts a hypothetical change to this provider's configuration will have on the provider.
	DiffConfig(olds, news resource.PropertyMap) (DiffResult, error)
	// Configure configures the resource provider with "globals" that control its behavior.
	Configure(inputs resource.PropertyMap) error

	// Check validates that the given property bag is valid for a resource of the given type and returns the inputs
	// that should be passed to successive calls to Diff, Create, or Update for this resource.
	Check(urn resource.URN, olds, news resource.PropertyMap,
		allowUnknowns bool) (resource.PropertyMap, []CheckFailure, error)
	// Diff checks what impacts a hypothetical update will have on the resource's properties.
	Diff(urn resource.URN, id resource.ID, olds resource.PropertyMap, news resource.PropertyMap,
		allowUnknowns bool) (DiffResult, error)
	// Create allocates a new instance of the provided resource and returns its unique resource.ID.
	Create(urn resource.URN, news resource.PropertyMap) (resource.ID, resource.PropertyMap, resource.Status, error)
	// Read the current live state associated with a resource.  Enough state must be include in the inputs to uniquely
	// identify the resource; this is typically just the resource ID, but may also include some properties.  If the
	// resource is missing (for instance, because it has been deleted), the resulting property map will be nil.
	Read(urn resource.URN, id resource.ID,
		props resource.PropertyMap) (resource.PropertyMap, resource.Status, error)
	// Update updates an existing resource with new values.
	Update(urn resource.URN, id resource.ID,
		olds resource.PropertyMap, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error)
	// Delete tears down an existing resource.
	Delete(urn resource.URN, id resource.ID, props resource.PropertyMap) (resource.Status, error)
	// Invoke dynamically executes a built-in function in the provider.
	Invoke(tok tokens.ModuleMember, args resource.PropertyMap) (resource.PropertyMap, []CheckFailure, error)
	// GetPluginInfo returns this plugin's information.
	GetPluginInfo() (workspace.PluginInfo, error)

	// SignalCancellation asks all resource providers to gracefully shut down and abort any ongoing
	// operations. Operation aborted in this way will return an error (e.g., `Update` and `Create`
	// will either a creation error or an initialization error. SignalCancellation is advisory and
	// non-blocking; it is up to the host to decide how long to wait after SignalCancellation is
	// called before (e.g.) hard-closing any gRPC connection.
	SignalCancellation() error
}

Provider presents a simple interface for orchestrating resource create, reead, update, and delete operations. Each provider understands how to handle all of the resource types within a single package.

This interface hides some of the messiness of the underlying machinery, since providers are behind an RPC boundary.

It is important to note that provider operations are not transactional. (Some providers might decide to offer transactional semantics, but such a provider is a rare treat.) As a result, failures in the operations below can range from benign to catastrophic (possibly leaving behind a corrupt resource). It is up to the provider to make a best effort to ensure catastrophes do not occur. The errors returned from mutating operations indicate both the underlying error condition in addition to a bit indicating whether the operation was successfully rolled back.

func NewProvider

func NewProvider(host Host, ctx *Context, pkg tokens.Package, version *semver.Version) (Provider, error)

NewProvider attempts to bind to a given package's resource plugin and then creates a gRPC connection to it. If the plugin could not be found, or an error occurs while creating the child process, an error is returned.

type RunInfo

type RunInfo struct {
	MonitorAddress string                // the RPC address to the host resource monitor.
	Project        string                // the project name housing the program being run.
	Stack          string                // the stack name being evaluated.
	Pwd            string                // the program's working directory.
	Program        string                // the path to the program to execute.
	Args           []string              // any arguments to pass to the program.
	Config         map[config.Key]string // the configuration variables to apply before running.
	DryRun         bool                  // true if we are performing a dry-run (preview).
	Parallel       int                   // the degree of parallelism for resource operations (<=1 for serial).
}

RunInfo contains all of the information required to perform a plan or deployment operation.

Jump to

Keyboard shortcuts

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