networker

package
v0.0.0-...-6dcdff4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: AGPL-3.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PluginID = "networker"
)

Variables

This section is empty.

Functions

func FindFreeTCPPort

func FindFreeTCPPort() (int, error)

FindFreePort finds an available port by letting the OS pick a free port.

func IsPortUnavailable

func IsPortUnavailable(port int) bool

IsPortUnavailable checks if a port is unavailable (i.e., in use).

func RegisterPlugin

func RegisterPlugin(
	p *sdk.Plugin,
	opts PluginOpts,
) error

Types

type FindPortForwardSessionRequest

type FindPortForwardSessionRequest struct {
	ResourceID   string `json:"resource_id"`
	ConnectionID string `json:"connection_id"`
}

func (FindPortForwardSessionRequest) ToProto

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager manages the lifecycle of networker actions, such as port forwarding sessions.

func NewManager

func NewManager(
	settingsProvider settings.Provider,
	opts PluginOpts,
) *Manager

func (*Manager) ClosePortForwardSession

func (m *Manager) ClosePortForwardSession(
	_ *types.PluginContext,
	sessionID string,
) (*PortForwardSession, error)

func (*Manager) FindPortForwardSessions

func (m *Manager) FindPortForwardSessions(
	_ *types.PluginContext,
	req FindPortForwardSessionRequest,
) ([]*PortForwardSession, error)

func (*Manager) GetPortForwardSession

func (m *Manager) GetPortForwardSession(
	_ *types.PluginContext,
	sessionID string,
) (*PortForwardSession, error)

func (*Manager) GetSupportedPortForwardTargets

func (m *Manager) GetSupportedPortForwardTargets(_ *types.PluginContext) []string

func (*Manager) ListPortForwardSessions

func (m *Manager) ListPortForwardSessions(_ *types.PluginContext) ([]*PortForwardSession, error)

func (*Manager) StartPortForwardSession

func (m *Manager) StartPortForwardSession(
	ctx *types.PluginContext,
	opts PortForwardSessionOptions,
) (*PortForwardSession, error)

type Plugin

type Plugin struct {
	plugin.Plugin
	Impl Provider
}

func (*Plugin) GRPCClient

func (p *Plugin) GRPCClient(
	_ context.Context,
	_ *plugin.GRPCBroker,
	c *grpc.ClientConn,
) (interface{}, error)

func (*Plugin) GRPCServer

func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error

type PluginClient

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

func (*PluginClient) ClosePortForwardSession

func (p *PluginClient) ClosePortForwardSession(
	ctx *types.PluginContext,
	sessionID string,
) (*PortForwardSession, error)

func (*PluginClient) FindPortForwardSessions

func (p *PluginClient) FindPortForwardSessions(
	ctx *types.PluginContext,
	req FindPortForwardSessionRequest,
) ([]*PortForwardSession, error)

FindPortForwardSessions returns all of the port forward sessions that match the given request.

func (*PluginClient) GetPortForwardSession

func (p *PluginClient) GetPortForwardSession(
	ctx *types.PluginContext,
	sessionID string,
) (*PortForwardSession, error)

GetPortForwardSession returns a port forward session by ID.

func (*PluginClient) GetSupportedPortForwardTargets

func (p *PluginClient) GetSupportedPortForwardTargets(ctx *types.PluginContext) []string

GetSupportedPortForwardTargets returns the list of targets that are supported by this plugin for port forwarding.

func (*PluginClient) ListPortForwardSessions

func (p *PluginClient) ListPortForwardSessions(
	ctx *types.PluginContext,
) ([]*PortForwardSession, error)

ListPortForwardSessions returns all of the port forward sessions.

func (*PluginClient) StartPortForwardSession

func (p *PluginClient) StartPortForwardSession(
	ctx *types.PluginContext,
	opts PortForwardSessionOptions,
) (*PortForwardSession, error)

type PluginOpts

type PluginOpts struct {
	// ResourcePortForwarders is a map of resource type to the function that is called to forward a resource's port.
	ResourcePortForwarders map[string]ResourcePortForwarder
	// StaticPortForwarders is a map of resource type to the function that is called to forward a static target of some
	// kind addressable by standard network addresses.
	StaticPortForwarders map[string]StaticPortForwarder
}

type PluginServer

type PluginServer struct {
	Impl Provider
	// contains filtered or unexported fields
}

func (*PluginServer) GetSupportedPortForwardTargets

func (s *PluginServer) GetSupportedPortForwardTargets(
	ctx context.Context,
	_ *emptypb.Empty,
) (*proto.GetSupportedPortForwardTargetsResponse, error)

func (*PluginServer) ListPortForwardSessions

func (s *PluginServer) ListPortForwardSessions(
	ctx context.Context,
	_ *emptypb.Empty,
) (*proto.PortForwardSessionListResponse, error)

func (*PluginServer) StartPortForwardSession

type PortForwardConnectionType

type PortForwardConnectionType string
const (
	PortForwardConnectionTypeResource PortForwardConnectionType = "RESOURCE"
	PortForwardConnectionTypeStatic   PortForwardConnectionType = "STATIC"
)

type PortForwardProtocol

type PortForwardProtocol string
const (
	PortForwardProtocolTCP PortForwardProtocol = "TCP"
	PortForwardProtocolUDP PortForwardProtocol = "UDP"
)

func PortForwardProtocolFromProto

func PortForwardProtocolFromProto(
	p proto.PortForwardProtocol,
) PortForwardProtocol

func (PortForwardProtocol) String

func (p PortForwardProtocol) String() string

func (PortForwardProtocol) ToProto

type PortForwardProvider

type PortForwardProvider interface {
	GetSupportedPortForwardTargets(*types.PluginContext) []string
	GetPortForwardSession(*types.PluginContext, string) (*PortForwardSession, error)
	ListPortForwardSessions(*types.PluginContext) ([]*PortForwardSession, error)
	FindPortForwardSessions(
		*types.PluginContext,
		FindPortForwardSessionRequest,
	) ([]*PortForwardSession, error)
	StartPortForwardSession(
		*types.PluginContext,
		PortForwardSessionOptions,
	) (*PortForwardSession, error)
	ClosePortForwardSession(*types.PluginContext, string) (*PortForwardSession, error)
}

type PortForwardResourceConnection

type PortForwardResourceConnection struct {
	ResourceData map[string]interface{} `json:"resource_data"`
	ConnectionID string                 `json:"connection_id"`
	PluginID     string                 `json:"plugin_id"`
	ResourceID   string                 `json:"resource_id"`
	ResourceKey  string                 `json:"resource_key"`
}

PortForwardSessionConnectionOptions represents the options for a session connection.

func (*PortForwardResourceConnection) ToProto

func (*PortForwardResourceConnection) ToSessionOptionsProto

func (*PortForwardResourceConnection) ToSessionProto

type PortForwardSession

type PortForwardSession struct {
	CreatedAt       time.Time                    `json:"created_at"`
	UpdatedAt       time.Time                    `json:"updated_at"`
	Connection      interface{}                  `json:"connection"`
	Labels          map[string]string            `json:"labels"`
	ID              string                       `json:"id"`
	Protocol        PortForwardProtocol          `json:"protocol"`
	State           SessionState                 `json:"state"`
	ConnectionType  string                       `json:"connection_type"`
	Encryption      PortForwardSessionEncryption `json:"encryption"`
	SourcePort      int                          `json:"source_port"`
	DestinationPort int                          `json:"destination_port"`
}

PortForwardSession represents a session between a forwarding target and the host that initiated the session.

func NewPortForwardSessionFromProto

func NewPortForwardSessionFromProto(s *proto.PortForwardSession) *PortForwardSession

NewPortForwardSessionFromProto creates a PortForwardSession from a protobuf.

func (*PortForwardSession) ToProto

type PortForwardSessionEncryption

type PortForwardSessionEncryption struct {
	Algorithm string `json:"algorithm"`
	Key       string `json:"key"`
	Enabled   bool   `json:"enabled"`
}

PortForwardSessionEncryption represents the options for a session encryption configuration.

func (*PortForwardSessionEncryption) ToProto

type PortForwardSessionOptions

type PortForwardSessionOptions struct {
	Connection      interface{}                  `json:"connection"`
	Labels          map[string]string            `json:"labels"`
	Params          map[string]string            `json:"params"`
	Protocol        PortForwardProtocol          `json:"protocol"`
	ConnectionType  PortForwardConnectionType    `json:"connection_type"`
	Encryption      PortForwardSessionEncryption `json:"encryption"`
	SourcePort      int                          `json:"source_port"`
	DestinationPort int                          `json:"destination_port"`
}

PortForwardSessionOptions represents the options for creating a new forwarding session.

func (*PortForwardSessionOptions) ToProto

type PortForwardStaticConnection

type PortForwardStaticConnection struct {
	Address string `json:"address"`
}

func (*PortForwardStaticConnection) ToProto

func (*PortForwardStaticConnection) ToSessionOptionsProto

func (*PortForwardStaticConnection) ToSessionProto

type Provider

type Provider interface {
	PortForwardProvider
}

Provider is the interface satisfied by the plugin server and client to provide the networker functionality.

type ResourcePortForwardHandlerOpts

type ResourcePortForwardHandlerOpts struct {
	Resource PortForwardResourceConnection `json:"resource"`
	Options  PortForwardSessionOptions     `json:"options"`
}

type ResourcePortForwarder

type ResourcePortForwarder func(*types.PluginContext, ResourcePortForwardHandlerOpts) (string, error)

ResourcePortForwarder is responsible for initiating a port forwarding session given the options coming from the plugin describing a resource to start a port forwarding session for. It should return a UUID that uniquely identifies the session, or an error if any occurred.

The Context passed in via the plugin context will be canceled when the port forwarding session is meant to be terminated. This is the plugin's cue to stop the port forwarding session.

type SessionState

type SessionState string
const (
	SessionStateActive  SessionState = "ACTIVE"
	SessionStatePaused  SessionState = "PAUSED"
	SessionStateStopped SessionState = "STOPPED"
	SessionStateFailed  SessionState = "FAILED"
)

func (SessionState) String

func (s SessionState) String() string

func (SessionState) ToProto

type StaticPortForwardHandlerOpts

type StaticPortForwardHandlerOpts struct {
	Static  PortForwardStaticConnection `json:"static"`
	Options PortForwardSessionOptions   `json:"options"`
}

type StaticPortForwarder

type StaticPortForwarder func(*types.PluginContext, StaticPortForwardHandlerOpts) (string, error)

StaticPortForwarder is responsible for initiating a port forwarding session given the options coming from the plugin describing a static target to initiate a port forward for. It should return a UUID that uniquely identifies the session, or an error if any occurred.

The Context passed in via the plugin context will be canceled when the port forwarding session is meant to be terminated. This is the plugin's cue to stop the port forwarding session.

Jump to

Keyboard shortcuts

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