Help us shape the future of Go! Take the 2026 Go Developer Survey

machineid

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package machineid resolves and stores a single machine identifier shared by every Snyk product on the same machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

Resolve returns a configuration.DefaultValueFunction for configuration.MACHINE_ID. A valid value supplied on MACHINE_ID itself (trailing whitespace trimmed) is returned. Otherwise the first lookup takes the first of: the hardware serial, the shared file, the Snyk Studio device-id file, or a newly generated id. A valid serial replaces a different id in the machine-wide shared file and in an existing per-user shared file, best effort. An existing install's machine id therefore changes once, on upgrade: the serial replaces the id stored in both shared files, and other products read the new id from there. A file written by a newer or unknown schema is left unchanged, and storing a hardware serial logs a warning about it. Later lookups through the same resolver return that id, together with an error for each file that exists but could not be read. If no id was found, it returns runtimeinfo.ErrNoMachineID joined with those errors and an error describing why a generated id could not be stored; the configuration caching does not hold it, so the next lookup tries the disk again. Machine.StudioID is the INTERNAL_SNYK_CLIENT_MACHINE_ID value when it is valid, otherwise the Snyk Studio device-id file. The CLI value never supplies the machine id.

Types

type ResolveOption

type ResolveOption func(*resolveOptions)

ResolveOption configures optional behavior of Resolve.

func WithHostname added in v0.35.0

func WithHostname(get func() (string, error)) ResolveOption

WithHostname replaces the hostname lookup. Used by tests to make resolution independent of the host.

func WithLogger

func WithLogger(logger *zerolog.Logger) ResolveOption

WithLogger sets the logger used to trace resolution decisions at Debug level, including errors that resolution otherwise swallows so a run can still produce a value. If unset, Resolve uses a no-op logger.

func WithRuntimeInfo

func WithRuntimeInfo(get func() runtimeinfo.RuntimeInfo) ResolveOption

WithRuntimeInfo identifies the consumer resolving the machine id, recorded as the writer field in the shared machine-id file so a machine carrying values written by several different products or versions is identifiable. get is called when the file is written rather than when Resolve is called, so runtime info set on the engine after it was created is still used. If unset, or if get returns nil, a generic framework identifier is recorded.

func WithSerialNumber added in v0.35.0

func WithSerialNumber(get func() (string, error)) ResolveOption

WithSerialNumber replaces the hardware serial lookup. Used by tests to make resolution independent of the host.

Directories

Path Synopsis
Package identity provides hostname and hardware serial lookups for machine identification.
Package identity provides hostname and hardware serial lookups for machine identification.

Jump to

Keyboard shortcuts

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