Documentation
¶
Index ¶
- Variables
- func APIRequest() *resty.Request
- func CheckStatus(response *resty.Response) error
- func DateConversion(data string) (string, error)
- func GetHostname() (string, error)
- func GetMachineId() (string, error)
- func NeedsRestarting() (bool, string)
- func OSRelease() (map[string]string, error)
- func PackageBinary() string
- func SetAuthentication(request *resty.Request)
- func SplitPackageName(packageName string) (name, version, release, epoch, arch string)
Constants ¶
This section is empty.
Variables ¶
var Path = "/etc/os-release"
Path contains the default path to the os-release file
Functions ¶
func APIRequest ¶ added in v1.20.0
APIRequest returns a request against the txlog server, with the JSON content type and authentication already configured. Paths passed to it are relative to server.url.
func CheckStatus ¶ added in v1.20.0
CheckStatus turns a non-200 response into an error describing it.
func DateConversion ¶
DateConversion takes a date string input and converts it to RFC3339 format. It attempts to parse the input date string using multiple common date formats and returns the formatted date as a string.
Parameters:
- data: A string representing a date in any common format
Returns:
- string: The date formatted in RFC3339 format (2006-01-02T15:04:05Z07:00)
- error: An error if the date parsing fails, nil otherwise
func GetHostname ¶
GetHostname returns the system hostname as reported by the kernel. Returns an error if the hostname cannot be determined.
func GetMachineId ¶
GetMachineId retrieves the unique machine identifier from the '/etc/machine-id' file. This identifier is typically used to distinguish the host machine in a network.
Returns:
- string: The machine ID as a trimmed string
- error: An error if reading the machine-id file fails
func NeedsRestarting ¶ added in v1.5.0
NeedsRestarting checks if the system needs to be restarted by executing the '/usr/bin/needs-restarting' command. This command is typically available on Red Hat-based systems to determine if any running processes are using files that have been updated/deleted.
Returns:
- bool: true if system needs restarting, false otherwise
- string: the complete output message from needs-restarting command
The function parses the command output looking for the specific phrase "Reboot should not be necessary". If this phrase is found, it indicates no restart is needed.
func OSRelease ¶ added in v1.2.0
OSRelease parses the os-release file pointed to by Path and returns its fields, with surrounding quotes stripped from the values. Empty lines and comments are ignored, as are lines without a '='.
func PackageBinary ¶
func PackageBinary() string
PackageBinary determines and verifies the appropriate package manager binary (yum or dnf) based on the Linux distribution version. It reads /etc/os-release to check if the system is running RHEL/CentOS 8 or 9, in which case it selects 'dnf' instead of the default 'yum'.
The function also verifies if the selected package manager is installed in the system. If the binary is not found, it exits with an error message.
Returns:
- string: The name of the package manager binary ("yum" or "dnf")
The function will exit with status code 1 if the required package manager is not installed.
func SetAuthentication ¶ added in v1.7.0
SetAuthentication configures authentication for an API request. It prioritizes API key authentication over basic authentication. If an API key is configured in the server.api_key setting, it sets the X-API-Key header. Otherwise, if username and password are configured, it uses basic authentication.
Parameters:
- request: A resty.Request instance to configure with authentication headers
func SplitPackageName ¶
SplitPackageName splits a RPM package name into its components. It takes a package name string as input and returns the following components:
- name: The name of the package
- version: The version number
- release: The release number
- epoch: The epoch number (empty string if not present)
- arch: The architecture
The function expects package names in the following format: [name]-[version]-[release].[arch].rpm or [name]-[epoch]:[version]-[release].[arch].rpm
The .rpm suffix is optional and will be trimmed if present. If epoch is not present in the package name, an empty string is returned for that component.
Types ¶
This section is empty.