shared

package
v0.0.0-...-24472b9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed icon_white.png
	IconWhite []byte

	//go:embed icon_black.png
	IconBlack []byte
)
View Source
var (
	Version = "dev"
	Commit  = "none"
	Date    = "unknown"
)
View Source
var ReadFileMocks map[string]string

ReadFileMocks is a map that simulates file reading operations by mapping file paths (as keys) to their corresponding file contents (as values). This can be used for testing purposes to mock the behavior of reading files without actually accessing the file system.

View Source
var RunCommandMocks map[string]string

RunCommandMocks is a map that stores mock command outputs. The key is the command string, and the value is the corresponding mock output.

View Source
var SocketPath = "/var/run/pareto-linux.sock"

Functions

func CommitLastState

func CommitLastState() error

Commit writes the current state map to the TOML file.

func DeviceAuth

func DeviceAuth() string

DeviceAuth decodes a JWT token from the shared configuration's AuthToken, extracts the payload, and returns the token string from the payload. It returns an empty string if there is an error during decoding or unmarshalling.

func GetLastStates

func GetLastStates() map[string]LastState

func GetModifiedTime

func GetModifiedTime() time.Time

func HTTPTransport

func HTTPTransport() http.RoundTripper

SafeHTTPTransport is a custom HTTP transport with secure TLS settings and a custom User-Agent.

func IsLinked

func IsLinked() bool

IsLinked checks if the team is linked by verifying that both the TeamID and AuthToken in the shared configuration are not empty strings. It returns true if both values are present, indicating that the team is linked; otherwise, it returns false.

func IsRoot

func IsRoot() bool

func IsSocketServicePresent

func IsSocketServicePresent() bool

func LoadConfig

func LoadConfig() error

func ReadFile

func ReadFile(name string) ([]byte, error)

ReadFile reads the content of the file specified by the given name. If the code is running in a testing environment, it will return the content from the ReadFileMocks map instead of reading from the actual file system. If the file name is not found in the ReadFileMocks map, it returns an error. Otherwise, it reads the file content from the file system.

func RunCheckViaHelper

func RunCheckViaHelper(uuid string) (bool, error)

func RunCommand

func RunCommand(name string, arg ...string) (string, error)

RunCommand executes a command with the given name and arguments, and returns the combined standard output and standard error as a string. If testing is enabled, it returns a predefined fixture instead of executing the command.

func Sanitize

func Sanitize(s string) string

Sanitize takes a string and returns a sanitized version containing only ASCII characters. It converts non-ASCII characters to underscores and keeps only alphanumeric characters and select punctuation marks (., !, -, ', ", _, ,).

func SaveConfig

func SaveConfig() error

func SelfExe

func SelfExe() string

func SystemDevice

func SystemDevice() (string, error)

func SystemSerial

func SystemSerial() (string, error)

func SystemUUID

func SystemUUID() (string, error)

func UpdateLastState

func UpdateLastState(newState LastState)

UpdateState updates the LastState struct in the in-memory map and commits to the TOML file.

Types

type Broadcaster

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

Broadcaster structure

func NewBroadcaster

func NewBroadcaster() *Broadcaster

NewBroadcaster creates a new Broadcaster

func (*Broadcaster) Register

func (b *Broadcaster) Register() chan string

Register adds a new consumer channel

func (*Broadcaster) Send

func (b *Broadcaster) Send()

Send sends a message to the broadcaster's input channel

func (*Broadcaster) Unregister

func (b *Broadcaster) Unregister(ch chan string)

Unregister removes a consumer channel

type CheckStatus

type CheckStatus struct {
	UpdatedAt time.Time
	Passed    bool
	Disabled  bool
}

type LastState

type LastState struct {
	UUID    string `json:"uuid"`
	State   bool   `json:"state"`
	Details string `json:"details"`
}

func GetLastState

func GetLastState(uuid string) (LastState, bool, error)

GetState retrieves the LastState struct by UUID.

type LinkingDevice

type LinkingDevice struct {
	Hostname  string `json:"hostname"`
	OS        string `json:"os"`
	OSVersion string `json:"osVersion"`
	Kernel    string `json:"kernel"`
	UUID      string `json:"uuid"`
	Ticket    string `json:"ticket"`
	Version   string `json:"version"`
}

func NewLinkingDevice

func NewLinkingDevice() (*LinkingDevice, error)

NewLinkingDevice creates a new instance of LinkingDevice with system information. It retrieves the system UUID and device ticket, and populates the LinkingDevice struct with the hostname, OS name, OS version, kernel version, UUID, and ticket. Returns a pointer to the LinkingDevice and an error if any occurs during the process.

type ParetoConfig

type ParetoConfig struct {
	TeamID    string
	AuthToken string
	Checks    map[string]CheckStatus
}
var Config ParetoConfig

type ReportingDevice

type ReportingDevice struct {
	MachineUUID string `json:"machineUUID"` // e.g. 123e4567-e89b-12d3-a456-426614174000
	MachineName string `json:"machineName"` // e.g. MacBook-Pro.local
	Auth        string `json:"auth"`
	OSVersion   string `json:"linuxOSVersion"` // e.g. Ubuntu 20.04
	ModelName   string `json:"modelName"`      // e.g. MacBook Pro
	ModelSerial string `json:"modelSerial"`    // e.g. C02C1234
}

func CurrentReportingDevice

func CurrentReportingDevice() ReportingDevice

Jump to

Keyboard shortcuts

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