system

package
v0.0.0-...-7db3de3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package system contains utils to get system information relevant to the Agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Path(p ...string) string
	Hostname() (string, error)
	GetenvWslDistroName() string
	LookupGroup(string) (*user.Group, error)

	ProExecutable(ctx context.Context, args ...string) *exec.Cmd
	LandscapeConfigExecutable(ctx context.Context, args ...string) *exec.Cmd
	WslpathExecutable(ctx context.Context, args ...string) *exec.Cmd
	WslinfoExecutable(ctx context.Context, args ...string) *exec.Cmd

	CmdExe(ctx context.Context, path string, args ...string) *exec.Cmd
}

Backend is the engine behind the System object, and defines the interactions it can perform with the operating system.

type Option

type Option = func(*options)

Option is an optional argument for New.

func WithTestBackend

func WithTestBackend(b Backend) Option

WithTestBackend is an optional argument for New that injects a backend into the system. For testing purposes only.

type System

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

System is an object with an easily pluggable back-end that allows accessing the filesystem, a few key executables, and some information about the system.

Do not replace the backend after construction, and use one of the provided constructors.

func New

func New(args ...Option) *System

New instantiates a stateless object that mediates interactions with the filesystem as well as a few key executables.

func (System) Info

func (s System) Info(ctx context.Context) (*agentapi.DistroInfo, error)

Info returns the current information about the system relevant to the GRPC connection to the agent.

func (*System) LandscapeDisable

func (s *System) LandscapeDisable(ctx context.Context) (err error)

LandscapeDisable unregisters the current distro from Landscape.

func (*System) LandscapeEnable

func (s *System) LandscapeEnable(ctx context.Context, landscapeConfig string, hostagentUID string) (err error)

LandscapeEnable registers the current distro to Landscape with the specified config.

func (System) Path

func (s System) Path(path ...string) string

Path converts an absolute path into one inside the mocked filesystem.

func (*System) ProAttach

func (s *System) ProAttach(ctx context.Context, token string) (err error)

ProAttach attaches the current distro to Ubuntu Pro.

func (*System) ProDetach

func (s *System) ProDetach(ctx context.Context) (err error)

ProDetach detaches the current distro from Ubuntu Pro. If the distro was already detached, nothing is done.

func (System) ProStatus

func (s System) ProStatus(ctx context.Context) (attached bool, err error)

ProStatus returns whether this distro is pro-attached.

func (*System) UserProfileDir

func (s *System) UserProfileDir(ctx context.Context) (wslPath string, err error)

UserProfileDir provides the path to Windows' user profile directory from WSL, usually `/mnt/c/Users/JohnDoe/`.

func (*System) WindowsHostAddress

func (s *System) WindowsHostAddress(ctx context.Context) (ip net.IP, err error)

WindowsHostAddress returns the IP that maps to Windows' localhost.

func (*System) WslDistroName

func (s *System) WslDistroName(ctx context.Context) (name string, err error)

WslDistroName obtains the name of the current WSL distro from these sources 1. From environment variable WSL_DISTRO_NAME, as long as it is not empty 2. From the Windows path to the distro's root ("\\wsl.localhost\<DISTRO_NAME>\").

Jump to

Keyboard shortcuts

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