landscapemockservice

package
v0.0.0-...-155e9e4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package landscapemockservice implements a mock Landscape service DO NOT USE IN PRODUCTION

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HostInfo

type HostInfo struct {
	UID      string
	Hostname string
	Token    string

	AccountName     string
	RegistrationKey string

	Instances         []InstanceInfo
	DefaultInstanceID string
}

HostInfo is the same as landscapeapi.HostAgentInfo, but without the mutexes and all grpc implementation details (so it can be safely copied).

type InstanceInfo

type InstanceInfo struct {
	ID            string
	Name          string
	VersionID     string
	InstanceState landscapeapi.InstanceState
}

InstanceInfo is the same as landscapeapi.InstanceInfo, but without the mutexes and all grpc implementation details (so it can be safely copied).

type Option

type Option func(*opts)

Option is an optional argument for New.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger overrides the default logger for the Landscape mock service.

type Service

type Service struct {
	landscapeapi.UnimplementedLandscapeHostAgentServer
	// contains filtered or unexported fields
}

Service is a minimalistic server for the landscape API.

func New

func New(args ...Option) *Service

New constructs and initializes a mock Landscape service.

func (*Service) Connect

Connect implements the Connect API call. Upon first contact ever, a UID is randombly assigned to the host and sent to it. In subsequent contacts, this UID will be its unique identifier.

func (*Service) Disconnect

func (s *Service) Disconnect(uid string) error

Disconnect kills the connection with the host assigned to the specified UID.

func (*Service) Hosts

func (s *Service) Hosts() (hosts map[string]HostInfo)

Hosts returns a map of all hosts that have had a UID assigned in the past, and their most recently received data.

func (*Service) IsConnected

func (s *Service) IsConnected(uid string) bool

IsConnected checks if a client with the specified hostname has an active connection.

func (*Service) MessageLog

func (s *Service) MessageLog() (log []HostInfo)

MessageLog allows looking into the history of messages received by the server.

func (*Service) SendCommand

func (s *Service) SendCommand(ctx context.Context, uid string, command *landscapeapi.Command) error

SendCommand instructs the server to send a command to the target machine with matching hostname.

func (*Service) WaitDisconnection

func (s *Service) WaitDisconnection(uid string) <-chan struct{}

WaitDisconnection returns a channel that will be closed when the connection with the host assigned to the specified UID is terminated.

If the UID is not registered, the second return value will be false.

Jump to

Keyboard shortcuts

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