Documentation
¶
Index ¶
- Variables
- func AllChecksPassed() bool
- func CommitLastState() error
- func DisableCheck(checkUUID string) error
- func EnableCheck(checkUUID string) error
- func FormatMacOSVersion(version string) string
- func GetCache(key string) (string, bool)
- func GetDeviceUUID() string
- func GetLastStates() map[string]LastState
- func GetModifiedTime() time.Time
- func IsCheckDisabled(checkUUID string) bool
- func IsLinked() bool
- func IsNixOS() bool
- func IsRoot() bool
- func LoadConfig() error
- func PrintStates()
- func ReadFile(name string) ([]byte, error)
- func ResetConfig()
- func RunCommand(name string, arg ...string) (string, error)
- func Sanitize(s string) string
- func SanitizeWithSpaces(s string) string
- func SaveConfig() error
- func SelfExe() string
- func SetCache(key string, value string, ttlSeconds int)
- func SetModifiedTime(t time.Time)
- func SystemDevice() (string, error)
- func SystemSerial() (string, error)
- func TransformToModelSerialPattern(s string) string
- func TransformToOSVersionPattern(s string) string
- func TruncateString(s string, maxLength int) string
- func UpdateLastState(newState LastState)
- func UserAgent() string
- func UserHomeDir() (string, error)
- func ValidateAndPrepareDevice(device *ReportingDevice)
- func ValidateMacOSVersion(version string) bool
- func ValidateOSVersion(version string) bool
- type Broadcaster
- type LastState
- type LinkingDevice
- type ParetoConfig
- type ReportingDevice
- type RunCommandMock
Constants ¶
This section is empty.
Variables ¶
var ( //go:embed icon_white.png IconWhite []byte //go:embed icon_black.png IconBlack []byte )
var ( Version = "dev" Commit = "none" Date = "unknown" )
var CheckTimeout = 5 * time.Minute
CheckTimeout is the global timeout for check runs Can be overridden for testing
var ConfigPath string
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.
var RunCommandMocks []RunCommandMock
RunCommandMocks is a slice that stores mock command outputs.
var (
StatePath string
)
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 ¶
DisableCheck adds a check to the disabled checks list
func EnableCheck ¶
EnableCheck removes a check from the disabled checks list
func FormatMacOSVersion ¶
FormatMacOSVersion attempts to format a version string to match macOS pattern
func GetDeviceUUID ¶
func GetDeviceUUID() string
GetDeviceUUID returns the system UUID from the configuration
func GetLastStates ¶
func GetModifiedTime ¶
GetModifiedTime returns the last modified time of the state file.
func IsCheckDisabled ¶
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 ¶
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 RunCommand ¶
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 ¶
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 ¶
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 SetModifiedTime ¶
SetModifiedTime sets the last modified time of the state file.
func SystemDevice ¶
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 ¶
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 ¶
TransformToModelSerialPattern transforms a string to match the modelSerial pattern Pattern: ^[a-zA-Z0-9\.!\-'"_]+$
func TransformToOSVersionPattern ¶
TransformToOSVersionPattern transforms a string to match the OS version pattern Pattern: ^[a-zA-Z0-9\.!\-'" _]+$
func TruncateString ¶
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 UserHomeDir ¶
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 ¶
ValidateMacOSVersion checks if a macOS version string matches the required pattern
func ValidateOSVersion ¶
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 (*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.
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