service

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 45 Imported by: ? 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

Index

Constants

This section is empty.

Variables

View Source
var ErrConnect = errors.New("failed to connect to service")

ErrConnect wraps a failure to reach the service at all, as while it is still starting; a request it received and refused is never one.

View Source
var UserArtifactsDir = func(dataDir string) string {
	return filepath.Join(dataDir, "user-artifacts")
}

UserArtifactsDir is where the service stages user-placement archives: user-artifacts inside the data directory (${ProgramData}\<Name>\Data by default). Administrators write it and users read it: it is the one entry of the data directory whose ACL lets Users in. It is not a placement and is not checked against the write roots, which refuse the data directory. Tests point it at a temporary directory.

Functions

func InstalledLaunchdPlist added in v1.11.0

func InstalledLaunchdPlist() []byte

InstalledLaunchdPlist is the plist for the installed layout: the CLI in identity.CLIPath and the default macOS config and data paths.

func IsErrorCode

func IsErrorCode(err error, appCode string) bool

IsErrorCode reports whether err is a service error with data.code appCode.

func IsTerminalOperationState

func IsTerminalOperationState(state string) bool

func LaunchdPlist added in v1.11.0

func LaunchdPlist(cli, configPath, dataDir string) []byte

LaunchdPlist is the macOS daemon's property list: launchd starts cli with the service arguments at boot and restarts it whenever it exits, as root, logging stdout and stderr to launchd.log in dataDir. `-serviceinstall` writes it and `just pkg` ships the same bytes (`<cli> -print-launchd-plist`), so there is one definition.

func RunAction

func RunAction(_ config.Configuration, _ string) error

func SaveUserPlan added in v1.11.0

func SaveUserPlan(appDataPath string, plan UserPlacements) error

SaveUserPlan stores plan at UserPlanPath through a temporary file, so a concurrent listUserPlacements reads either the old plan or the new one.

func ServiceStatus

func ServiceStatus(_ config.Configuration) (string, error)

func StageUserArtifacts added in v1.11.0

func StageUserArtifacts(ctx context.Context, zip *installer.ZipInstaller, plan []UserPlacement, dir string)

StageUserArtifacts makes dir hold exactly the archives plan references: each non-held entry's archive is downloaded and verified through zip (its cache and repository) and copied in when missing or different, and files no entry references are removed. A failure is logged and skips only its entry; the service never writes the user placements themselves.

func UserPlanPath added in v1.11.0

func UserPlanPath(appDataPath string) string

UserPlanPath is where a run stores the plan listUserPlacements serves.

Types

type AcceptedOperation

type AcceptedOperation struct {
	OperationID string `json:"operationId,omitempty"`
	Accepted    bool   `json:"accepted"`
	QueuedAtUTC string `json:"queuedAtUtc"`
	// RequestedBy is the user who called, as the service resolved it from the
	// connection: DOMAIN\user on Windows, "" when unresolved.
	RequestedBy string `json:"requestedBy"`
}

type Client

type Client struct {
	PipeName        string
	ConnectTimeout  time.Duration
	ResponseTimeout time.Duration
}

Client is the typed SofCat service client shared by command-line and UI callers. Timeouts default to five seconds for connecting and 30 seconds for ordinary responses and stream acknowledgements.

func NewClient

func NewClient(pipeName string) *Client

func (*Client) CancelOperation

func (c *Client) CancelOperation(ctx context.Context, operationID string) error

CancelOperation asks the service to cancel operationID. The service refuses with operation_not_cancelable once the item's install or removal has started, the operation has finished, or the operation is unknown.

func (*Client) GetBranding

func (c *Client) GetBranding(ctx context.Context) (branding.Branding, error)

GetBranding returns the organisation branding the service resolved from policy and config. Unset fields are empty strings.

func (*Client) GetServiceInfo

func (c *Client) GetServiceInfo(ctx context.Context) (ServiceInfo, error)

GetServiceInfo returns the service's version, protocol and capabilities, and whether a managed run is under way.

func (*Client) InstallItem

func (c *Client) InstallItem(ctx context.Context, itemName string) (AcceptedOperation, error)

func (*Client) ListOptionalInstalls

func (c *Client) ListOptionalInstalls(ctx context.Context) ([]OptionalInstallItem, error)

func (*Client) ListUserPlacements added in v1.11.0

func (c *Client) ListUserPlacements(ctx context.Context) (UserPlacements, error)

ListUserPlacements returns the user-placement plan the per-user helper applies, with the facts it renders with: the same for every caller in v1.

func (*Client) RemoveItem

func (c *Client) RemoveItem(ctx context.Context, itemName string) (AcceptedOperation, error)

func (*Client) ReportUserPlacements added in v1.11.0

func (c *Client) ReportUserPlacements(ctx context.Context, results []UserPlacementResult) error

ReportUserPlacements sends the helper's results, which the service logs.

func (*Client) StreamOperationStatus

func (c *Client) StreamOperationStatus(ctx context.Context, operationID string, callback func(OperationStatus) error) error

StreamOperationStatus calls callback with each of operationID's status records, from the first, until the terminal one.

type Command

type Command struct {
	Action string   `json:"action"`
	Items  []string `json:"items,omitempty"`
	// contains filtered or unexported fields
}

type CommandResponse

type CommandResponse struct {
	Status        string                `json:"status"`
	Message       string                `json:"message,omitempty"`
	Items         []string              `json:"items,omitempty"`
	OptionalItems []OptionalInstallItem `json:"optionalItems,omitempty"`
	OperationID   string                `json:"operationId,omitempty"`
	RequestedBy   string                `json:"requestedBy,omitempty"`
	Branding      *branding.Branding    `json:"branding,omitempty"`

	// UserPlan is ListUserPlacements' plan.
	UserPlan *UserPlacements `json:"userPlan,omitempty"`
	// contains filtered or unexported fields
}

func SendCommand

func SendCommand(cfg config.Configuration, spec string) (CommandResponse, error)

type Error

type Error struct {
	Code    int       `json:"code"`
	Message string    `json:"message"`
	Data    ErrorData `json:"data"`
}

Error is a JSON-RPC error object from the service. Data.Code is the stable application code (operation_not_cancelable, server_busy, ...).

func (*Error) Error

func (e *Error) Error() string

Error reads "<data.code>: <message>", the form the CLI prints and the UI strips the code from.

type ErrorData

type ErrorData struct {
	Code        string `json:"code"`
	OperationID string `json:"operationId,omitempty"`
}

type OperationStatus

type OperationStatus struct {
	OperationID     string `json:"operationId"`
	Seq             int    `json:"seq"`
	TimestampUTC    string `json:"timestampUtc"`
	ItemName        string `json:"itemName"`
	DisplayName     string `json:"displayName"`
	State           string `json:"state"`
	ProgressPercent *int   `json:"progressPercent,omitempty"`
	Message         string `json:"message"`
	ErrorCode       string `json:"errorCode,omitempty"`
	ErrorMessage    string `json:"errorMessage,omitempty"`
	CanceledBy      string `json:"canceledBy,omitempty"`
	RequestedBy     string `json:"requestedBy"`
}

OperationStatus is one status record, the params of an operationStatus notification. Seq numbers an operation's records from 1 in the order the service recorded them, so a client can order records that arrive out of order. RequestedBy is the user whose request started the operation, "" when the service could not resolve it. ProgressPercent is scoped to ItemName and may reset when the item changes; it is not aggregate operation progress. It is omitted when nothing was measured (a download of unknown length, an install or removal), so a client never reads an unmeasured phase as 0%. Only Succeeded, Failed, Deferred, and Canceled end an operation.

type OptionalInstallItem

type OptionalInstallItem struct {
	ItemName           string `json:"itemName"`
	DisplayName        string `json:"displayName"`
	Version            string `json:"version"`
	Catalog            string `json:"catalog"`
	Description        string `json:"description,omitempty"`
	Category           string `json:"category,omitempty"`
	Section            string `json:"section,omitempty"`
	Developer          string `json:"developer,omitempty"`
	IconName           string `json:"iconName,omitempty"`
	RestartAction      string `json:"restartAction,omitempty"`
	IsManaged          bool   `json:"isManaged"`
	IsRequired         bool   `json:"isRequired"`
	IsInstalled        bool   `json:"isInstalled"`
	Status             string `json:"status"`
	StatusUpdatedAtUTC string `json:"statusUpdatedAtUtc"`
	LastOperationID    string `json:"lastOperationId,omitempty"`
	// ActionLabels holds the labels the item or its placements set, keyed
	// by catalog.ActionLabelKeys; the UI supplies the rest.
	ActionLabels map[string]string `json:"actionLabels,omitempty"`
	// WorksIn names the harnesses the item's placements reach.
	WorksIn []string `json:"worksIn,omitempty"`
}

OptionalInstallItem is one offered self-service item. IsRequired is whether an admin manifest also lists it in managed_installs: it is installed for everyone and cannot be removed through self-service.

type ServiceInfo

type ServiceInfo struct {
	Version         string   `json:"version"`
	ProtocolVersion string   `json:"protocolVersion"`
	APIVersion      int      `json:"apiVersion"`
	Capabilities    []string `json:"capabilities"`
	Busy            bool     `json:"busy"`
	UptimeSeconds   int64    `json:"uptimeSeconds"`
}

ServiceInfo is getServiceInfo's result. It skips the command queue, so it doubles as a cheap health check.

type UserPlacement added in v1.11.0

type UserPlacement struct {
	Item      string `json:"item"`
	Version   string `json:"version"`
	Placement string `json:"placement"`
	// Path is the placement root from harnesses.yaml, unexpanded: the helper
	// expands ${USERPROFILE} for its own user.
	Path string `json:"path"`
	// Archive is the absolute path of the staged copy under
	// UserArtifactsDir, named <hash>.zip. Hash is its sha256, TreeHash its
	// contents'.
	Archive  string `json:"archive"`
	Hash     string `json:"hash"`
	TreeHash string `json:"treeHash"`
	// Held is true for an item under a conditional_items block the service
	// could not decide: the helper neither installs nor removes it.
	Held bool `json:"held"`
	// Managed is true when a manifest lists the item in managed_installs:
	// the helper's receipt records it and the tree's templates read it as
	// .Item.Managed, so a flip is detected in user scope as in machine scope.
	Managed bool `json:"managed"`
	// contains filtered or unexported fields
}

UserPlacement is one entry of the user-placement plan, listUserPlacements' result: a zip item's variant for a placement whose scope on this OS is user. The service never writes these trees; the per-user helper (`<slug>-ui.exe --user-sync`) does, from the archive the service staged.

func UserPlan added in v1.11.0

func UserPlan(desired, held, managed map[string]bool, catalogs map[int]map[string]catalog.Item, table harness.Table, goos, dir string) []UserPlacement

UserPlan builds the user-placement plan from a run's desired set (the names it installs or updates, closed over dependencies and update_for riders) and its held set (names under conditional_items blocks it could not decide), so the plan never diverges from what the run acted on. In v1 every user gets the same plan: those items' zip variants whose placement scope on goos is user. Held names outside the desired set are listed with Held set; managed holds the names the manifests list in managed_installs. Entries are sorted by item, then placement in table order. Each archive is named <hash>.zip inside dir, so two variants share a file only when they are the same archive and a catalog location never shapes a path; a variant whose hash is not a sha256 is left out.

type UserPlacementResult added in v1.11.0

type UserPlacementResult struct {
	Item      string `json:"item"`
	Placement string `json:"placement"`
	Outcome   string `json:"outcome"`
	Error     string `json:"error,omitempty"`
}

UserPlacementResult is the helper's outcome for one placement, sent with reportUserPlacements. Outcome is an installer.Outcome.

type UserPlacements added in v1.11.0

type UserPlacements struct {
	Entries []UserPlacement  `json:"entries"`
	Facts   conditions.Facts `json:"facts"`
}

UserPlacements is the user-placement plan as listUserPlacements serves it and as a run stores it: the entries, and the facts that run collected, once, which the helper renders user-scope tree templates with. The helper runs no scripts; whatever an admin script prints reaches every logged-on user's helper (conditions guide, "Admin-provided facts").

func LoadUserPlan added in v1.11.0

func LoadUserPlan(appDataPath string) (UserPlacements, error)

LoadUserPlan reads the plan the last run stored; before the first run there is none, which is an empty plan. It reads no repository, so the helper gets its plan at logon even while the repository is unreachable.

Jump to

Keyboard shortcuts

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