agent

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	AgentVersion  string
	AgentPlatform string
)

AgentVersion store the version to be embed inside the binary. This is injected using `-ldflags` build option (e.g: `go build -ldflags "-X main.AgentVersion=1.2.3"`).

If set to `latest`, the auto-updating mechanism is disabled. This is intended to be used during development only.

Functions

func NewSFTPServer

func NewSFTPServer()

NewSFTPServer creates a new SFTP server when a new session is created between the agent and the server.

Types

type Agent

type Agent struct {
	Identity *models.DeviceIdentity
	Info     *models.DeviceInfo
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(address string, tenantID string, privateKey string) (*Agent, error)

NewAgent creates a new agent instance.

Example
ag, err := NewAgent("http://localhost:80", "00000000-0000-4000-0000-000000000000", "./shellhub.key")
if err != nil {
	panic(err)
}

// Initializes agent, generating device identity, loading device information, generating private key,
// reading public key, probing server information and authorizing device on ShellHub server.
if err := ag.Initialize(); err != nil {
	panic(err)
}

listing := make(chan bool)
go func() {
	<-listing

	log.Println("listing")
}()

ag.Listen(listing) //nolint:errcheck
Output:

func NewAgentWithConfig

func NewAgentWithConfig(config *Config) (*Agent, error)

NewAgentWithConfig creates a new agent instance with a custom configuration.

Example
// Creates the agent configuration with the minimum required fields.
cfg := Config{
	ServerAddress: "http://localhost:80",
	TenantID:      "00000000-0000-4000-0000-000000000000",
	PrivateKey:    "./shellhub.key",
}

ag, err := NewAgentWithConfig(&cfg)
if err != nil {
	panic(err)
}

// Initializes agent, generating device identity, loading device information, generating private key,
// reading public key, probing server information and authorizing device on ShellHub server.
if err := ag.Initialize(); err != nil {
	panic(err)
}

listing := make(chan bool)
go func() {
	<-listing

	log.Println("listing")
}()

ag.Listen(listing) //nolint:errcheck
Output:

func (*Agent) CheckUpdate

func (a *Agent) CheckUpdate() (*semver.Version, error)

CheckUpdate check for agent updates.

func (*Agent) GetInfo

func (a *Agent) GetInfo() (*models.Info, error)

func (*Agent) Initialize

func (a *Agent) Initialize() error

Initialize initializes agent, generating device identity, loading device information, generating private key, reading public key, probing server information and authorizing device on ShellHub server.

func (*Agent) Listen

func (a *Agent) Listen(listining chan bool) error

Listen creates a new SSH server, tunnel to ShellHub and listen for incoming connections.

It's possible to pass a channel to be notified when the agent is listing for connections.

func (*Agent) NewReverseListener

func (a *Agent) NewReverseListener() (*revdial.Listener, error)

func (*Agent) Ping

func (a *Agent) Ping(ticker *time.Ticker, ping chan Ping)

Ping sends an authtorization request to the server every ticker interval.

If the ticker is nil, it will be set to 10 minutes. It's possible to pass a channel to be notified when the ping is sent.

type Config

type Config struct {
	// Set the ShellHub Cloud server address the agent will use to connect.
	// This is required.
	ServerAddress string `envconfig:"server_address" required:"true"`

	// Specify the path to the device private key.
	// If not provided, the agent will generate a new one.
	// This is required.
	PrivateKey string `envconfig:"private_key" required:"true"`

	// Sets the account tenant id used during communication to associate the
	// device to a specific tenant.
	// This is required.
	TenantID string `envconfig:"tenant_id" required:"true"`

	// 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 `envconfig:"keepalive_interval" default:"30"`

	// Set the device preferred hostname. This provides a hint to the server to
	// use this as hostname if it is available.
	PreferredHostname string `envconfig:"preferred_hostname"`

	// Set the device preferred identity. This provides a hint to the server to
	// use this identity if it is available.
	PreferredIdentity string `envconfig:"preferred_identity" default:""`

	// Set password for single-user mode (without root privileges). If not provided,
	// multi-user mode (with root privileges) is enabled by default.
	// NOTE: The password hash could be generated by “`openssl passwd“`.
	SingleUserPassword string `envconfig:"simple_user_password"`
}

Config provides the configuration for the agent service.

type Ping

type Ping struct {
	Timestamp time.Time
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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