retire

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package retire tells the backend that this device is going away.

It backs `uninstall --retire` (and config.json retire_on_uninstall): the agent's last act before removing its scheduler job is a best-effort POST to the agent-facing retire endpoint, so an ephemeral machine — a virtual desktop torn down by its host pool — leaves the dashboard and the license count instead of lingering as an inactive seat. Everything here is advisory: a failure is logged and the uninstall proceeds, and a retired device that reports again is restored by the backend automatically.

Index

Constants

View Source
const (

	// TotalBudget caps collecting the identities, and is the floor of the
	// budget for retiring them (BudgetFor).
	TotalBudget = 10 * time.Second

	// MaxBudget caps BudgetFor so a host with many cached ids still
	// uninstalls promptly; rows the budget leaves behind are covered by the
	// dashboard's auto-retire.
	MaxBudget = 60 * time.Second
	// MaxIdentities caps how many ids CollectIdentities returns.
	MaxIdentities = 100
)
View Source
const (
	// StatusRetired: the row is retired (or was already).
	StatusRetired = "retired"
	// StatusUnknownDevice: no row for the id; the backend created none.
	StatusUnknownDevice = "unknown_device"
	// StatusOutOfScope: the tenant's retirement scope (Settings, Device
	// activity) does not select this device; the row stays as it is.
	StatusOutOfScope = "out_of_scope"
)

Statuses the backend answers with on a 2xx retire response.

View Source
const (
	// ReasonUninstall: `uninstall --retire` / retire_on_uninstall.
	ReasonUninstall = "agent_uninstall"
)

Reasons the agent sends as retired_reason. The management API and the inactivity sweep use their own values.

View Source
const ScanHoldBudget = 30 * time.Second

ScanHoldBudget bounds how long an uninstall waits for running scans to finish before it gives up on retiring. An MSI uninstall action and an MDM script both tolerate it; a scan normally reports within seconds of its upload.

Variables

View Source
var ErrNotSupported = errors.New("retire: endpoint not available on this backend (404)")

ErrNotSupported is returned for a 404: the backend predates the retire endpoint. Callers treat it as a warning, not a failure.

Functions

func BudgetFor

func BudgetFor(n int) time.Duration

BudgetFor is the time budget for retiring n identities: TotalBudget plus perIdentityBudget for every identity beyond the first, capped at MaxBudget.

func CollectIdentities

func CollectIdentities(ctx context.Context, exec executor.Executor, log *progress.Logger) []string

CollectIdentities returns every device id this installation may have registered under: the identity resolved right now (when complete), plus the run-gate cache of every state file under the install dir — last-run.json at the top level and users/*/last-run.json for the per-session state. A session's record normally names the machine identity too, and the per-user ids an older build wrote go with it, so an MSI uninstall running as SYSTEM leaves no row behind. Deduplicated, ordered, capped at MaxIdentities.

func HoldScans

func HoldScans(ctx context.Context, log *progress.Logger) (release func(), idle bool)

HoldScans waits, within ctx, until no scan runs under any identity on this host (the machine-wide instance lock and every per-session lock can be taken) and returns a release func that keeps them held while the caller retires, so no scan starts in between. idle is false when a scan still ran at the deadline; the caller must then leave the device registered, because a scan that reports after the retire restores it. Uninstall removes the scheduler first, but a stop that failed or a scan already mid-flight survive that. A lock that cannot be taken for any other reason proves nothing about the rest (the acquisition stops at the first failure, so a scan may hold a later one), so that is not idle either; it is retried until the deadline in case the failure was transient.

func Post

func Post(ctx context.Context, endpoint, apiKey, customerID, deviceID, agentVersion, platform, reason string) (string, error)

Post retires deviceID under customerID: POST {endpoint}/v1/{customer}/developer-mdm-agent/devices/{device_id}/retire with the telemetry key as Bearer and the given reason (Reason*). A 2xx is success and yields the backend's status (Status*; "" when the body carries none), including an unknown device, which the backend answers without creating a row. 5xx and transport errors retry once; any other 4xx is terminal. Errors are redacted (the URL embeds the customer id, the header the tenant key).

Types

This section is empty.

Jump to

Keyboard shortcuts

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