connector

package
v0.18.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnectorVersion string

ConnectorVersion stores the version of the ShellHub Instane that is running the connector. It is used in the ShellHub Agents initialized by the connector when a container is started.

Functions

This section is empty.

Types

type Config added in v0.16.0

type Config struct {
	// Set the ShellHub server address the agent will use to connect.
	// This is required.
	ServerAddress string `env:"SERVER_ADDRESS,required"`

	// Specify the path to store the devices/containers private keys.
	// If not provided, the agent will generate a new one.
	// This is required.
	PrivateKeys string `env:"PRIVATE_KEYS,required"`

	// Sets the account tenant id used during communication to associate the
	// devices to a specific tenant.
	// This is required.
	TenantID string `env:"TENANT_ID,required"`

	// Determine the interval to send the keep alive message to the server. This
	// has a direct impact of the bandwidth used by the device when in idle
	// state. Default is 30 seconds.
	KeepAliveInterval int `env:"KEEPALIVE_INTERVAL,overwrite,default=30"`
}

Config provides the configuration for the agent connector service.

func LoadConfigFromEnv added in v0.16.0

func LoadConfigFromEnv() (*Config, map[string]interface{}, error)

type Connector

type Connector interface {
	// List lists all containers running on the host.
	List(ctx context.Context) ([]Container, error)
	// Start starts the agent for the container with the given ID.
	Start(ctx context.Context, id string, name string)
	// Stop stops the agent for the container with the given ID.
	Stop(ctx context.Context, id string)
	// Listen listens for events and starts or stops the agent for the container that was created or removed.
	Listen(ctx context.Context) error
}

Connector is an interface that defines the methods that a connector must implement.

func NewDockerConnector

func NewDockerConnector(server string, tenant string, privateKey string) (Connector, error)

NewDockerConnector creates a new Connector that uses Docker as the container runtime.

func NewDockerConnectorWithClient added in v0.17.0

func NewDockerConnectorWithClient(cli *dockerclient.Client, server string, tenant string, privateKey string) (Connector, error)

type Container

type Container struct {
	// ID is the container ID.
	ID string
	// Name is the container name.
	Name string
	// ServerAddress is the ShellHub address of the server that the agent will connect to.
	ServerAddress string
	// Tenant is the tenant ID of the namespace that the agent belongs to.
	Tenant string
	// PrivateKey is the private key of the device. Specify the path to store the container private key. If not
	// provided, the agent will generate a new one. This is required.
	PrivateKey string
	// Cancel is a function that is used to stop the goroutine that is running the agent for this container.
	Cancel context.CancelFunc
}

Container is a struct that represents a container that will be managed by the connector.

type DockerConnector

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

DockerConnector is a struct that represents a connector that uses Docker as the container runtime.

func (*DockerConnector) List

func (d *DockerConnector) List(ctx context.Context) ([]Container, error)

func (*DockerConnector) Listen

func (d *DockerConnector) Listen(ctx context.Context) error

Listen listens for events and starts or stops the agent for the containers.

func (*DockerConnector) Start

func (d *DockerConnector) Start(ctx context.Context, id string, name string)

Start starts the agent for the container with the given ID.

func (*DockerConnector) Stop

func (d *DockerConnector) Stop(_ context.Context, id string)

Stop stops the agent for the container with the given ID.

Jump to

Keyboard shortcuts

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