services

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartingGroupMapCapacity    = 10
	StartingResourceMapCapacity = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

type ConnectionManager[ClientT any] interface {
	rt.ResourceConnectionProvider

	// InjectConnection injects the connection by id into the plugin context
	InjectConnection(ctx *types.PluginContext, id string) error

	// CheckConnection checks the status of a connection
	CheckConnection(
		ctx *types.PluginContext,
		conn *types.Connection,
		client *ClientT,
	) (types.ConnectionStatus, error)

	// GetConnectionClient returns the necessary client for the given auth
	// This method should be used by resourcers to get the client for the given
	// auth.
	GetConnectionClient(ctx *types.PluginContext, id string) (*ClientT, error)

	// RefreshConnectionClient performs any actions necessary to refresh a client for the given auth.
	// This may include refreshing credentials, or re-initializing the client if it has been
	// invalidated.
	RefreshConnectionClient(ctx *types.PluginContext, id string) error

	// GetCurrentConnectionClient returns the current client for the given auth
	GetCurrentConnectionClient(ctx *types.PluginContext) (*ClientT, error)

	// RefreshCurrentConnectionClient performs any actions necessary to refresh the current client for the given auth.
	RefreshCurrentConnectionClient(ctx *types.PluginContext) error

	// GetConnectionNamespaces returns the namespaces for the given connection, if any. If the connection does not support
	// namespaces, it will return an empty slice.
	GetConnectionNamespaces(ctx *types.PluginContext, id string) ([]string, error)
}

ConnectionManager is an interface that resource managers must implement in order to manage the various authenticated targets that a resource plugin can talk to.

For example, a user may have multiple AWS accounts and roles they would like to incorporate into the IDE. However, each account (and role) has it's own authorizations, and must used different credentials to access. As such, the user would like to separate these backends into different connections, so that they can easily switch between them. For this example, a connection would consist of the account and role, and the resource auth manager would be responsible for setting up, switching between, and managing these authd clients.

func NewConnectionManager

func NewConnectionManager[ClientT any](
	createClient func(*types.PluginContext) (*ClientT, error),
	refreshClient func(*types.PluginContext, *ClientT) error,
	startClient func(*types.PluginContext, *ClientT) error,
	stopClient func(*types.PluginContext, *ClientT) error,
	loader func(*types.PluginContext) ([]types.Connection, error),
	watcher func(*types.PluginContext) (chan []types.Connection, error),
	checker func(*types.PluginContext, *types.Connection, *ClientT) (types.ConnectionStatus, error),
	namespaceLoader func(*types.PluginContext, *ClientT) ([]string, error),
) ConnectionManager[ClientT]

NewConnectionManager creates a new service to manage the various auth contexts for a plugin with an authenticated backend.

type DynamicResourceTypeManager

type DynamicResourceTypeManager struct {
	*StaticResourceTypeManager // embed this last for pointer receiver semantics
	// contains filtered or unexported fields
}

DynamicResourceTypeManager is a resource type manager that provides a dynamic set of resource types that can change with each connection. This is useful for resource backends that have a dynamic set of resource types that can change with each connection, for example, different Kubernetes Clusters running different versions.

This discovery manager is optional, and if none is provided, the resource manager will use all resource types provided by the resource type manager.

func (*DynamicResourceTypeManager) GetConnectionResourceTypes

func (r *DynamicResourceTypeManager) GetConnectionResourceTypes(
	connectionID string,
) ([]types.ResourceMeta, error)

func (*DynamicResourceTypeManager) GetGroups

func (r *DynamicResourceTypeManager) GetGroups(
	connID string,
) map[string]types.ResourceGroup

func (*DynamicResourceTypeManager) RemoveConnection

func (r *DynamicResourceTypeManager) RemoveConnection(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

func (*DynamicResourceTypeManager) SyncConnection

func (r *DynamicResourceTypeManager) SyncConnection(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

type InformerManager

type InformerManager[ClientT any] struct {
	// contains filtered or unexported fields
}

InformerManager manages informer handles for all connections. It tracks per-resource state, enforces sync policies, and fans in events to the controller's channels.

func NewInformerManager

func NewInformerManager[ClientT any](
	createFunc types.CreateInformerHandleFunc[ClientT],
	syncPolicies map[string]types.InformerSyncPolicy,
	addChan chan types.InformerAddPayload,
	updateChan chan types.InformerUpdatePayload,
	deleteChan chan types.InformerDeletePayload,
	stateChan chan types.InformerStateEvent,
) *InformerManager[ClientT]

func (*InformerManager[ClientT]) CreateConnectionInformer

func (i *InformerManager[ClientT]) CreateConnectionInformer(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
	client *ClientT,
) error

CreateConnectionInformer creates a new informer handle for a connection.

func (*InformerManager[ClientT]) EnsureResource

func (i *InformerManager[ClientT]) EnsureResource(
	connectionID string,
	resourceKey string,
) error

EnsureResource starts the informer for a specific resource if it has SyncOnFirstQuery policy and is still in Pending state.

func (*InformerManager[ClientT]) GetConnectionState

func (i *InformerManager[ClientT]) GetConnectionState(
	connectionID string,
) (*types.InformerConnectionSummary, error)

GetConnectionState returns a snapshot of all resource informer states for a connection.

func (*InformerManager[ClientT]) HasInformer

func (i *InformerManager[ClientT]) HasInformer(
	_ *pkgtypes.PluginContext,
	connectionID string,
) bool

HasInformer checks if there's an informer for the given connection.

func (*InformerManager[ClientT]) RegisterResource

func (i *InformerManager[ClientT]) RegisterResource(
	ctx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
	resource types.ResourceMeta,
	syncPolicy types.InformerSyncPolicy,
) error

RegisterResource registers a resource with the informer for a given connection.

func (*InformerManager[ClientT]) Run

func (i *InformerManager[ClientT]) Run(
	stopCh <-chan struct{},
	controllerAddChan chan types.InformerAddPayload,
	controllerUpdateChan chan types.InformerUpdatePayload,
	controllerDeleteChan chan types.InformerDeletePayload,
	controllerStateChan chan types.InformerStateEvent,
) error

Run starts the informer manager event loop. It fans in add/update/delete/state events from all connections to the controller's channels.

func (*InformerManager[ClientT]) StartConnection

func (i *InformerManager[ClientT]) StartConnection(
	_ *pkgtypes.PluginContext,
	connectionID string,
) error

StartConnection signals the informer to start for a given connection.

func (*InformerManager[ClientT]) StopConnection

func (i *InformerManager[ClientT]) StopConnection(
	_ *pkgtypes.PluginContext,
	connectionID string,
) error

StopConnection stops the informer for a given connection.

type LayoutManager

type LayoutManager interface {
	GetLayout(layoutID string) ([]types.LayoutItem, error)
	SetLayout(layoutID string, layout []types.LayoutItem) error
	GetDefaultLayout() ([]types.LayoutItem, error)
	GenerateLayoutFromMetas(metas []types.ResourceMeta)
}

func NewLayoutManager

func NewLayoutManager(opts *types.LayoutOpts) LayoutManager

type ResourceTypeManager

type ResourceTypeManager interface {
	// GetGroups returns the grouped tree of resources available.
	GetGroups(connectionID string) map[string]types.ResourceGroup

	// GetGroup returns the group information by it's string representation
	GetGroup(string) (types.ResourceGroup, error)

	// GetResourceTypes returns the all of the available resource types for the resource manager
	GetResourceTypes(connectionID string) map[string]types.ResourceMeta

	// GetResourceType returns the resource type information by it's string representation
	// For example, "core::v1::Pod" or "ec2::2012-12-01::EC2Instance"
	GetResourceType(string) (*types.ResourceMeta, error)

	// GetTableDefinition returns the resource table definition for the resource type
	GetResourceDefinition(string) (types.ResourceDefinition, error)

	// HasResourceType checks to see if the resource type exists
	HasResourceType(string) bool

	// GetConnectionResourceTypes returns the available resource types for the given connection
	GetConnectionResourceTypes(string) ([]types.ResourceMeta, error)

	// SyncResourceNamespace sets up a given connection with the manager, and syncs the available resource types
	// given a set of options
	SyncConnection(*pkgtypes.PluginContext, *pkgtypes.Connection) error

	// and stops the client for the namespace
	RemoveConnection(*pkgtypes.PluginContext, *pkgtypes.Connection) error
}

ResourceTypeManager is the interface for which resource type managers must implement.

If a resource backend has a dynamic set of resource types that can change with each connection (for example, different Kubernetes Clusters running different versions), it should instantiate a DynamicResourceTypeManager.

If a resource backend has a static set of resource types that does not change with each connection (for example, AWS, GCP, Azure, etc.), it should instantiate the StaticResourceTypeManager.

func NewDynamicResourceTypeManager

func NewDynamicResourceTypeManager(
	resourceTypes []types.ResourceMeta,
	resourceGroups []types.ResourceGroup,
	resourceDefinitions map[string]types.ResourceDefinition,
	defaultResourceDefinition types.ResourceDefinition,
	provider types.DiscoveryProvider,
) ResourceTypeManager

NewDynamicResourceTypeManager creates a new resource type discovery manager to be used with the resource backend, given a DiscoveryProvider.

func NewStaticResourceTypeManager

func NewStaticResourceTypeManager(
	resourceTypes []types.ResourceMeta,
	resourceGroups []types.ResourceGroup,
	resourceDefinitions map[string]types.ResourceDefinition,
	defaultResourceDefinition types.ResourceDefinition,
) ResourceTypeManager

NewStaticResourceTypeManager creates a new resource type manager with a static set of resource types that does not change with each connection For example, AWS, GCP, Azure, etc.

type ResourcerManager

type ResourcerManager[ClientT any] interface {
	// RegisterResourcer registers a new resourcer for the given resource type
	RegisterResourcer(resourceType string, resourcer types.Resourcer[ClientT]) error
	// RegisterResourcersFromMap registers a new resourcer for the given resource type given
	// a map of meta objects
	RegisterResourcersFromMap(resourcerMap map[types.ResourceMeta]types.Resourcer[ClientT]) error
	// RegisterPatternResourcer registers a resourcer that matches resource types by pattern
	RegisterPatternResourcer(pattern string, resourcer types.Resourcer[ClientT]) error
	// RegisterPatternResourcersFromMap registers pattern resourcers from a map of patterns
	RegisterPatternResourcersFromMap(resourcerMap map[string]types.Resourcer[ClientT]) error
	// DeregisterResourcer deregisters the resourcer for the given resource type
	DeregisterResourcer(resourceType string) error
	// GetResourcer returns the resourcer for the given resource type.
	// It first tries an exact match in the store, then falls back to pattern matching.
	GetResourcer(resourceType string) (types.Resourcer[ClientT], error)
	// GetResourcers returns all exact-match registered resourcers.
	GetResourcers() map[string]types.Resourcer[ClientT]
}

ResourcerManager manages all of the resourcers for a given resource type. It is responsible for registering, retreiving, and managing resourcers for a given resource type.

func NewResourcerManager

func NewResourcerManager[ClientT any]() ResourcerManager[ClientT]

type StaticResourceTypeManager

type StaticResourceTypeManager struct {
	sync.RWMutex // embed this last for pointer receiver semantics
	// contains filtered or unexported fields
}

StaticResourceTypeManager is a resource type manager that provides a static set of resource types that does not change with each connection. This is useful for resource backends that have a static set of resource types that does not change with each connection, for example, AWS, GCP, Azure, etc.

func (*StaticResourceTypeManager) GetConnectionResourceTypes

func (r *StaticResourceTypeManager) GetConnectionResourceTypes(
	connectionID string,
) ([]types.ResourceMeta, error)

func (*StaticResourceTypeManager) GetGroup

func (*StaticResourceTypeManager) GetGroups

func (*StaticResourceTypeManager) GetResourceDefinition

func (r *StaticResourceTypeManager) GetResourceDefinition(
	s string,
) (types.ResourceDefinition, error)

func (*StaticResourceTypeManager) GetResourceType

func (r *StaticResourceTypeManager) GetResourceType(
	s string,
) (*types.ResourceMeta, error)

func (*StaticResourceTypeManager) GetResourceTypes

func (r *StaticResourceTypeManager) GetResourceTypes(_ string) map[string]types.ResourceMeta

func (*StaticResourceTypeManager) HasResourceType

func (r *StaticResourceTypeManager) HasResourceType(s string) bool

func (*StaticResourceTypeManager) RemoveConnection

func (r *StaticResourceTypeManager) RemoveConnection(
	pluginCtx *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

func (*StaticResourceTypeManager) SyncConnection

func (r *StaticResourceTypeManager) SyncConnection(
	_ *pkgtypes.PluginContext,
	connection *pkgtypes.Connection,
) error

Jump to

Keyboard shortcuts

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