shared

package
v0.0.0-...-4a87c2a Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: GPL-3.0 Imports: 21 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 CheckTimeout = 5 * time.Minute

CheckTimeout is the global timeout for check runs Can be overridden for testing

View Source
var ConfigPath string
View Source
var ReadFileMock func(name string) ([]byte, error)

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 []RunCommandMock

RunCommandMocks is a slice that stores mock command outputs.

View Source
var (
	StatePath string
)
View Source
var UserHomeDirMock func() (string, error)

Functions

func AllChecksPassed

func AllChecksPassed() bool

AllChecksPassed returns true if all checks have passed.

func CommitLastState

func CommitLastState() error

Commit writes the current state map to the TOML file.

func DisableCheck

func DisableCheck(checkUUID string) error

DisableCheck adds a check to the disabled checks list

func EnableCheck

func EnableCheck(checkUUID string) error

EnableCheck removes a check from the disabled checks list

func FormatMacOSVersion

func FormatMacOSVersion(version string) string

FormatMacOSVersion attempts to format a version string to match macOS pattern

func GetCache

func GetCache(key string) (string, bool)

func GetDeviceUUID

func GetDeviceUUID() string

GetDeviceUUID returns the system UUID from the configuration

func GetLastStates

func GetLastStates() map[string]LastState

func GetModifiedTime

func GetModifiedTime() time.Time

GetModifiedTime returns the last modified time of the state file.

func IsCheckDisabled

func IsCheckDisabled(checkUUID string) bool

IsCheckDisabled checks if a given check UUID is present in the list of disabled checks

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 IsNixOS

func IsNixOS() bool

IsNixOS checks if the current system is NixOS by attempting to run the `nixos-version` command. It returns true if the command executes without error, indicating that NixOS is likely the operating system.

func IsRoot

func IsRoot() bool

IsRoot returns true if the current process is running with root privileges. When running tests, it always returns true to avoid permission-related test failures. For normal execution, it checks if the effective user ID is 0 (root).

func LoadConfig

func LoadConfig() error

func PrintStates

func PrintStates()

PrintStates loads and prints all stored states with their UUIDs, state values, and details.

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 ResetConfig

func ResetConfig()

ResetConfig clears all configuration values to defaults

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 (., !, -, ', ", _) matching the API regex: ^[a-zA-Z0-9\.!\-'"_]+$

func SanitizeWithSpaces

func SanitizeWithSpaces(s string) string

SanitizeWithSpaces takes a string and returns a sanitized version containing only ASCII characters. Similar to Sanitize but preserves spaces. Used for OS version strings which need to be human-readable.

func SaveConfig

func SaveConfig() error

SaveConfig writes the current configuration to the config file

func SelfExe

func SelfExe() string

SelfExe returns the path to the current executable. If the executable path cannot be determined, it returns "paretosecurity" as a fallback. The function also removes any "-tray" suffix from the executable path, which is used for Windows standalone builds where the tray version has a different executable name.

func SetCache

func SetCache(key string, value string, ttlSeconds int)

func SetModifiedTime

func SetModifiedTime(t time.Time)

SetModifiedTime sets the last modified time of the state file.

func SystemDevice

func SystemDevice() (string, error)

SystemDevice retrieves the system's device name by reading the contents of "/sys/class/dmi/id/product_name" using the RunCommand function. It returns the device name as a string, or an error if the command fails.

func SystemSerial

func SystemSerial() (string, error)

SystemSerial retrieves the system's serial number by reading the contents of "/sys/class/dmi/id/product_serial" using the RunCommand helper function. It returns the serial number as a string, or an error if the command fails.

func TransformToModelSerialPattern

func TransformToModelSerialPattern(s string) string

TransformToModelSerialPattern transforms a string to match the modelSerial pattern Pattern: ^[a-zA-Z0-9\.!\-'"_]+$

func TransformToOSVersionPattern

func TransformToOSVersionPattern(s string) string

TransformToOSVersionPattern transforms a string to match the OS version pattern Pattern: ^[a-zA-Z0-9\.!\-'" _]+$

func TruncateString

func TruncateString(s string, maxLength int) string

TruncateString truncates a string to the specified maximum length It properly handles UTF-8 characters to avoid splitting multi-byte characters

func UpdateLastState

func UpdateLastState(newState LastState)

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

func UserAgent

func UserAgent() string

func UserHomeDir

func UserHomeDir() (string, error)

UserHomeDir returns the current user's home directory.

On Unix, including macOS, it returns the $HOME environment variable. On Windows, it returns %USERPROFILE%. On Plan 9, it returns the $home environment variable.

If the expected variable is not set in the environment, UserHomeDir returns either a platform-specific default value or a non-nil error.

func ValidateAndPrepareDevice

func ValidateAndPrepareDevice(device *ReportingDevice)

ValidateAndPrepareDevice validates and prepares device data according to OpenAPI spec

func ValidateMacOSVersion

func ValidateMacOSVersion(version string) bool

ValidateMacOSVersion checks if a macOS version string matches the required pattern

func ValidateOSVersion

func ValidateOSVersion(version string) bool

ValidateOSVersion checks if a Linux/Windows OS version string matches the required pattern

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 LastState

type LastState struct {
	Name     string `json:"name"`
	UUID     string `json:"uuid"`
	Passed   bool   `json:"state"`
	HasError bool   `json:"hasError"`
	Details  string `json:"details"`
}

func GetFailedChecks

func GetFailedChecks() []LastState

GetFailedChecks returns a slice of failed checks.

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
	TeamAPI       string
	SystemUUID    string
	DisableChecks []string
}
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

type RunCommandMock

type RunCommandMock struct {
	Command string
	Args    []string
	Out     string
	Err     error
}

RunCommandMock represents a mock command with its arguments, output, and error

Jump to

Keyboard shortcuts

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