plugins

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Handshake is re-exported from pkg/plugin
	Handshake = p5plugin.Handshake
	// PluginMap is re-exported from pkg/plugin
	PluginMap = p5plugin.PluginMap
)

Re-export shared types from pkg/plugin for internal use. This ensures a single source of truth for these definitions.

View Source
var (
	ImportSuggestionsNotSupported = p5plugin.ImportSuggestionsNotSupported
	ImportSuggestionsSuccess      = p5plugin.ImportSuggestionsSuccess
	ImportSuggestionsError        = p5plugin.ImportSuggestionsError
	NewImportSuggestion           = p5plugin.NewImportSuggestion
)

Re-export import suggestion helper functions from pkg/plugin for internal use.

View Source
var ErrorResponse = p5plugin.ErrorResponse

ErrorResponse is re-exported from pkg/plugin for internal use.

View Source
var SuccessResponse = p5plugin.SuccessResponse

SuccessResponse is re-exported from pkg/plugin for internal use.

Functions

func IsBuiltin

func IsBuiltin(name string) bool

IsBuiltin returns true if a plugin name refers to a builtin plugin

func ListBuiltins

func ListBuiltins() []string

ListBuiltins returns all registered builtin plugin names

func LoadStackPluginConfig

func LoadStackPluginConfig(workDir, stackName, pluginName string) (map[string]any, error)

LoadStackPluginConfig loads stack-level plugin configuration from Pulumi.{stack}.yaml

func RegisterBuiltin

func RegisterBuiltin(plugin BuiltinPlugin)

RegisterBuiltin registers a builtin plugin by name

Types

type AggregatedImportSuggestion

type AggregatedImportSuggestion struct {
	PluginName string
	Suggestion *ImportSuggestion
}

AggregatedImportSuggestion includes the source plugin name

type AuthContext

type AuthContext struct {
	WorkDir     string
	StackName   string
	ProgramName string
	// ConfigHashes stores hash of (program + stack) config per plugin for change detection
	ConfigHashes map[string]string
}

AuthContext holds the current authentication context for change detection

type AuthPlugin

type AuthPlugin = p5plugin.AuthPlugin

AuthPlugin is the interface that plugins must implement. This is re-exported from pkg/plugin for internal use.

type AuthPluginGRPC

type AuthPluginGRPC = p5plugin.AuthPluginGRPC

AuthPluginGRPC is the implementation of goplugin.GRPCPlugin for AuthPlugin

type AuthProvider

type AuthProvider interface {
	// GetMergedAuthEnv returns combined auth environment variables from all plugins.
	GetMergedAuthEnv() map[string]string

	// GetAllEnv returns all environment variables from all valid credentials.
	GetAllEnv() map[string]string

	// ApplyEnvToProcess sets all credential env vars in the current process environment.
	ApplyEnvToProcess()

	// GetCredentialsSummary returns a summary of all credentials for UI display.
	GetCredentialsSummary() []CredentialsSummary

	// InvalidateCredentials marks credentials for a specific plugin as expired.
	InvalidateCredentials(pluginName string)

	// InvalidateAllCredentials clears all cached credentials.
	InvalidateAllCredentials()
}

AuthProvider handles authentication credentials from plugins.

type AuthenticateAllCall

type AuthenticateAllCall struct {
	ProgramName string
	StackName   string
	P5Config    *P5Config
	WorkDir     string
}

type AuthenticateResult

type AuthenticateResult struct {
	PluginName  string
	Credentials *Credentials
	Error       error
}

AuthenticateResult holds the result of an authentication attempt

type BuiltinImportHelperPlugin

type BuiltinImportHelperPlugin interface {
	BuiltinPlugin
	ImportHelperPlugin
}

BuiltinImportHelperPlugin is for builtin plugins that also provide import suggestions

type BuiltinPlugin

type BuiltinPlugin interface {
	AuthPlugin
	// Name returns the plugin's registered name (e.g., "env")
	Name() string
}

BuiltinPlugin is an AuthPlugin that runs in-process (no subprocess/gRPC)

func GetBuiltin

func GetBuiltin(name string) BuiltinPlugin

GetBuiltin returns a builtin plugin by name, or nil if not found

type BuiltinPluginBase

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

BuiltinPluginBase provides common functionality for builtin plugins

func NewBuiltinPluginBase

func NewBuiltinPluginBase(name string) BuiltinPluginBase

NewBuiltinPluginBase creates a new base for builtin plugins

func (*BuiltinPluginBase) Name

func (b *BuiltinPluginBase) Name() string

Name returns the plugin name

type BuiltinPluginInstance

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

BuiltinPluginInstance wraps a builtin plugin to satisfy the plugin instance interface

func NewBuiltinPluginInstance

func NewBuiltinPluginInstance(name string, plugin BuiltinPlugin) *BuiltinPluginInstance

NewBuiltinPluginInstance creates a new instance wrapper for a builtin plugin

func (*BuiltinPluginInstance) Authenticate

Authenticate delegates to the builtin plugin

type Credentials

type Credentials struct {
	PluginName string
	Env        map[string]string
	ExpiresAt  time.Time // Zero time means never expires (TTL = -1 means always refresh)
	AlwaysCall bool      // True if TTL was -1
}

Credentials holds the result of a plugin authentication

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

IsExpired returns true if the credentials have expired

type CredentialsSummary

type CredentialsSummary struct {
	PluginName string
	EnvVars    []string  // List of env var names (not values for security)
	ExpiresAt  time.Time // Zero if never expires
	AlwaysCall bool
	HasError   bool
	Error      string
}

CredentialsSummary returns a summary of current credentials for display

type FakePluginProvider

type FakePluginProvider struct {
	// AuthProvider methods
	GetMergedAuthEnvFunc         func() map[string]string
	GetAllEnvFunc                func() map[string]string
	ApplyEnvToProcessFunc        func()
	GetCredentialsSummaryFunc    func() []CredentialsSummary
	InvalidateCredentialsFunc    func(pluginName string)
	InvalidateAllCredentialsFunc func()

	// ImportHelper methods
	GetImportSuggestionsFunc func(ctx context.Context, req *ImportSuggestionsRequest) ([]*AggregatedImportSuggestion, error)
	HasImportHelpersFunc     func() bool

	// PluginProvider methods
	InitializeFunc                      func(ctx context.Context, workDir, programName, stackName string) ([]AuthenticateResult, error)
	CloseFunc                           func(ctx context.Context)
	GetMergedConfigFunc                 func() *P5Config
	ShouldRefreshCredentialsFunc        func(pluginName string, newWorkDir, newStackName, newProgramName string, newProgramConfig, newStackConfig map[string]any) bool
	InvalidateCredentialsForContextFunc func(workDir, stackName, programName string, p5Config *P5Config)
	AuthenticateAllFunc                 func(ctx context.Context, programName, stackName string, p5Config *P5Config, workDir string) ([]AuthenticateResult, error)

	// Default return values
	AuthEnv            map[string]string
	AllEnv             map[string]string
	CredentialsSummary []CredentialsSummary
	ImportSuggestions  []*AggregatedImportSuggestion
	HasImportHelper    bool
	AuthResults        []AuthenticateResult
	MergedConfig       *P5Config
	ShouldRefresh      bool

	// Calls tracks all method invocations.
	Calls struct {
		GetMergedAuthEnv                int
		GetAllEnv                       int
		ApplyEnvToProcess               int
		GetCredentialsSummary           int
		InvalidateCredentials           []string
		InvalidateAllCredentials        int
		GetImportSuggestions            []*ImportSuggestionsRequest
		HasImportHelpers                int
		Initialize                      []InitializeCall
		Close                           int
		GetMergedConfig                 int
		ShouldRefreshCredentials        []ShouldRefreshCredentialsCall
		InvalidateCredentialsForContext []InvalidateCredentialsForContextCall
		AuthenticateAll                 []AuthenticateAllCall
	}
}

FakePluginProvider implements PluginProvider for testing. Configure behavior via function fields and default return values.

func (*FakePluginProvider) ApplyEnvToProcess

func (f *FakePluginProvider) ApplyEnvToProcess()

func (*FakePluginProvider) AuthenticateAll

func (f *FakePluginProvider) AuthenticateAll(ctx context.Context, programName, stackName string, p5Config *P5Config, workDir string) ([]AuthenticateResult, error)

func (*FakePluginProvider) Close

func (f *FakePluginProvider) Close(ctx context.Context)

func (*FakePluginProvider) GetAllEnv

func (f *FakePluginProvider) GetAllEnv() map[string]string

func (*FakePluginProvider) GetCredentialsSummary

func (f *FakePluginProvider) GetCredentialsSummary() []CredentialsSummary

func (*FakePluginProvider) GetImportSuggestions

func (*FakePluginProvider) GetMergedAuthEnv

func (f *FakePluginProvider) GetMergedAuthEnv() map[string]string

func (*FakePluginProvider) GetMergedConfig

func (f *FakePluginProvider) GetMergedConfig() *P5Config

func (*FakePluginProvider) HasImportHelpers

func (f *FakePluginProvider) HasImportHelpers() bool

func (*FakePluginProvider) Initialize

func (f *FakePluginProvider) Initialize(ctx context.Context, workDir, programName, stackName string) ([]AuthenticateResult, error)

func (*FakePluginProvider) InvalidateAllCredentials

func (f *FakePluginProvider) InvalidateAllCredentials()

func (*FakePluginProvider) InvalidateCredentials

func (f *FakePluginProvider) InvalidateCredentials(pluginName string)

func (*FakePluginProvider) InvalidateCredentialsForContext

func (f *FakePluginProvider) InvalidateCredentialsForContext(workDir, stackName, programName string, p5Config *P5Config)

func (*FakePluginProvider) ShouldRefreshCredentials

func (f *FakePluginProvider) ShouldRefreshCredentials(pluginName string, newWorkDir, newStackName, newProgramName string, newProgramConfig, newStackConfig map[string]any) bool

type GRPCClient

type GRPCClient = p5plugin.GRPCClient

GRPCClient is the client-side implementation of AuthPlugin over gRPC

type GRPCServer

type GRPCServer = p5plugin.GRPCServer

GRPCServer is the server-side implementation that wraps the actual plugin

type GlobalConfig

type GlobalConfig struct {
	Plugins map[string]PluginConfig `toml:"plugins"`
}

GlobalConfig represents the p5.toml global configuration

func LoadGlobalConfig

func LoadGlobalConfig(launchDir string) (*GlobalConfig, string, error)

LoadGlobalConfig loads p5.toml from either git root or launch directory Priority: git root > launch directory

type ImportHelper

type ImportHelper interface {
	// GetImportSuggestions queries plugins for import ID suggestions.
	GetImportSuggestions(ctx context.Context, req *ImportSuggestionsRequest) ([]*AggregatedImportSuggestion, error)

	// HasImportHelpers returns true if any plugin provides import suggestions.
	HasImportHelpers() bool
}

ImportHelper provides import ID suggestions.

type ImportHelperGRPCClient

type ImportHelperGRPCClient = p5plugin.ImportHelperGRPCClient

ImportHelperGRPCClient is the client-side implementation of ImportHelperPlugin over gRPC

type ImportHelperGRPCServer

type ImportHelperGRPCServer = p5plugin.ImportHelperGRPCServer

ImportHelperGRPCServer is the server-side implementation that wraps the actual import helper plugin

type ImportHelperPlugin

type ImportHelperPlugin = p5plugin.ImportHelperPlugin

ImportHelperPlugin is an optional interface that plugins can implement to provide import ID suggestions for resources. This is re-exported from pkg/plugin for internal use.

type ImportHelperPluginGRPC

type ImportHelperPluginGRPC = p5plugin.ImportHelperPluginGRPC

ImportHelperPluginGRPC is the implementation of goplugin.GRPCPlugin for ImportHelperPlugin

type ImportSuggestion

type ImportSuggestion = p5plugin.ImportSuggestion

Re-export import suggestion types from pkg/plugin for internal use.

type ImportSuggestionsRequest

type ImportSuggestionsRequest = p5plugin.ImportSuggestionsRequest

Re-export import suggestion types from pkg/plugin for internal use.

type ImportSuggestionsResponse

type ImportSuggestionsResponse = p5plugin.ImportSuggestionsResponse

Re-export import suggestion types from pkg/plugin for internal use.

type InitializeCall

type InitializeCall struct {
	WorkDir     string
	ProgramName string
	StackName   string
}

type InvalidateCredentialsForContextCall

type InvalidateCredentialsForContextCall struct {
	WorkDir     string
	StackName   string
	ProgramName string
	P5Config    *P5Config
}

type Manager

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

Manager handles plugin lifecycle and credential management

func NewManager

func NewManager(launchDir string) (*Manager, error)

NewManager creates a new plugin manager launchDir is the directory p5 was launched from (used to find p5.toml)

func (*Manager) ApplyEnvToProcess

func (m *Manager) ApplyEnvToProcess()

ApplyEnvToProcess sets all credential env vars in the current process environment This allows subsequent Pulumi operations (which use os.Environ) to inherit them

func (*Manager) AuthenticateAll

func (m *Manager) AuthenticateAll(ctx context.Context, programName, stackName string, p5Config *P5Config, workDir string) ([]AuthenticateResult, error)

AuthenticateAll runs authentication for all plugins in parallel

func (*Manager) Close

func (m *Manager) Close(ctx context.Context)

Close cleans up all plugin resources

func (*Manager) GetAllEnv

func (m *Manager) GetAllEnv() map[string]string

GetAllEnv returns all environment variables from all valid credentials

func (*Manager) GetCredentialsSummary

func (m *Manager) GetCredentialsSummary() []CredentialsSummary

GetCredentialsSummary returns a summary of all credentials for UI display

func (*Manager) GetGlobalConfigPath

func (m *Manager) GetGlobalConfigPath() string

GetGlobalConfigPath returns the path to the loaded global config file

func (*Manager) GetImportSuggestions

func (m *Manager) GetImportSuggestions(ctx context.Context, req *ImportSuggestionsRequest) ([]*AggregatedImportSuggestion, error)

GetImportSuggestions queries all enabled import helper plugins for suggestions

func (*Manager) GetMergedAuthEnv

func (m *Manager) GetMergedAuthEnv() map[string]string

GetMergedAuthEnv returns all auth environment variables from all plugins

func (*Manager) GetMergedConfig

func (m *Manager) GetMergedConfig() *P5Config

GetMergedConfig returns the current merged configuration

func (*Manager) HasImportHelpers

func (m *Manager) HasImportHelpers() bool

HasImportHelpers returns true if any plugin has import helper capability enabled

func (*Manager) Initialize

func (m *Manager) Initialize(ctx context.Context, workDir, programName, stackName string) ([]AuthenticateResult, error)

Initialize loads and authenticates plugins based on the current context. This is an alias for LoadAndAuthenticate to satisfy the PluginProvider interface.

func (*Manager) InvalidateAllCredentials

func (m *Manager) InvalidateAllCredentials()

InvalidateAllCredentials clears all cached credentials

func (*Manager) InvalidateCredentials

func (m *Manager) InvalidateCredentials(pluginName string)

InvalidateCredentials marks credentials for a specific plugin as expired

func (*Manager) InvalidateCredentialsForContext

func (m *Manager) InvalidateCredentialsForContext(workDir, stackName, programName string, p5Config *P5Config)

InvalidateCredentialsForContext invalidates credentials based on context change and plugin refresh trigger settings

func (*Manager) LoadAndAuthenticate

func (m *Manager) LoadAndAuthenticate(ctx context.Context, workDir, programName, stackName string) ([]AuthenticateResult, error)

LoadAndAuthenticate is a convenience method that loads plugins and authenticates

func (*Manager) LoadPlugins

func (m *Manager) LoadPlugins(ctx context.Context, p5Config *P5Config) error

LoadPlugins loads all plugins defined in the p5 config

func (*Manager) ShouldRefreshCredentials

func (m *Manager) ShouldRefreshCredentials(pluginName string, newWorkDir, newStackName, newProgramName string, newProgramConfig, newStackConfig map[string]any) bool

ShouldRefreshCredentials determines if credentials should be refreshed for a plugin based on context changes and refresh trigger settings

func (*Manager) UpdateContext

func (m *Manager) UpdateContext(workDir, stackName, programName string, configHashes map[string]string)

UpdateContext updates the current authentication context

type P5Config

type P5Config struct {
	Plugins map[string]PluginConfig `yaml:"plugins,omitempty"`
}

P5Config represents the p5 configuration section in Pulumi.yaml

func LoadP5Config

func LoadP5Config(pulumiYamlPath string) (*P5Config, error)

LoadP5Config loads p5 configuration from a Pulumi.yaml file

func MergeConfigs

func MergeConfigs(global *GlobalConfig, program *P5Config) *P5Config

MergeConfigs merges global config (p5.toml) with program config (Pulumi.yaml) Program config takes precedence over global config

type PluginConfig

type PluginConfig struct {
	// Cmd is the command to run the plugin (path to executable)
	Cmd string `yaml:"cmd" toml:"cmd"`
	// Args are optional arguments to pass to the plugin command
	Args []string `yaml:"args,omitempty" toml:"args,omitempty"`
	// Config is the program-level configuration
	Config map[string]any `yaml:"config,omitempty" toml:"config,omitempty"`
	// Refresh controls when credentials should be refreshed
	Refresh *RefreshTrigger `yaml:"refresh,omitempty" toml:"refresh,omitempty"`

	// Import helper settings
	// ImportHelper enables the import helper capability for this plugin (default: false)
	ImportHelper bool `yaml:"import_helper,omitempty" toml:"import_helper,omitempty"`
	// UseAuthEnv passes merged auth environment variables to import helper requests (default: false)
	UseAuthEnv bool `yaml:"use_auth_env,omitempty" toml:"use_auth_env,omitempty"`
}

PluginConfig represents the configuration for a plugin from Pulumi.yaml or p5.toml

type PluginInstance

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

PluginInstance holds a running plugin client and its interface

func (*PluginInstance) Close

func (p *PluginInstance) Close()

Close shuts down the plugin

func (*PluginInstance) HasImportHelper

func (p *PluginInstance) HasImportHelper() bool

HasImportHelper returns true if this plugin provides import suggestions

type PluginProvider

type PluginProvider interface {
	AuthProvider
	ImportHelper

	// Initialize loads and authenticates plugins based on the current context.
	// This is a convenience method that loads plugins from config and authenticates.
	Initialize(ctx context.Context, workDir, programName, stackName string) ([]AuthenticateResult, error)

	// Close cleans up plugin resources.
	Close(ctx context.Context)

	// GetMergedConfig returns the merged plugin configuration.
	GetMergedConfig() *P5Config

	// ShouldRefreshCredentials determines if credentials should be refreshed for a plugin
	// based on context changes and refresh trigger settings.
	ShouldRefreshCredentials(pluginName string, newWorkDir, newStackName, newProgramName string, newProgramConfig, newStackConfig map[string]any) bool

	// InvalidateCredentialsForContext invalidates credentials based on context change
	// and plugin refresh trigger settings.
	InvalidateCredentialsForContext(workDir, stackName, programName string, p5Config *P5Config)

	// AuthenticateAll runs authentication for all loaded plugins.
	AuthenticateAll(ctx context.Context, programName, stackName string, p5Config *P5Config, workDir string) ([]AuthenticateResult, error)
}

PluginProvider combines all plugin capabilities needed by the application. This is the main interface used by the TUI to interact with the plugin system.

type RefreshTrigger

type RefreshTrigger struct {
	// OnWorkspaceChange triggers credential refresh when workspace changes
	// Default: true
	OnWorkspaceChange *bool `yaml:"onWorkspaceChange,omitempty" toml:"onWorkspaceChange,omitempty"`
	// OnStackChange triggers credential refresh when stack changes
	// Default: true
	OnStackChange *bool `yaml:"onStackChange,omitempty" toml:"onStackChange,omitempty"`
	// OnConfigChange triggers credential refresh only when plugin config changes
	// (both program and stack config are compared)
	// Default: false - when true, workspace/stack changes only refresh if config differs
	OnConfigChange *bool `yaml:"onConfigChange,omitempty" toml:"onConfigChange,omitempty"`
}

RefreshTrigger defines when credentials should be refreshed

func (*RefreshTrigger) ShouldRefreshOnConfigChange

func (r *RefreshTrigger) ShouldRefreshOnConfigChange() bool

ShouldRefreshOnConfigChange returns whether to only refresh when config changes

func (*RefreshTrigger) ShouldRefreshOnStackChange

func (r *RefreshTrigger) ShouldRefreshOnStackChange() bool

ShouldRefreshOnStackChange returns whether to refresh on stack change

func (*RefreshTrigger) ShouldRefreshOnWorkspaceChange

func (r *RefreshTrigger) ShouldRefreshOnWorkspaceChange() bool

ShouldRefreshOnWorkspaceChange returns whether to refresh on workspace change

type ShouldRefreshCredentialsCall

type ShouldRefreshCredentialsCall struct {
	PluginName       string
	NewWorkDir       string
	NewStackName     string
	NewProgramName   string
	NewProgramConfig map[string]any
	NewStackConfig   map[string]any
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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