diff

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package diff computes semantic diffs between current Fleet state (from API) and proposed state (from parsed YAML). It produces structured DiffResult values showing what will be added, modified, or deleted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigChange

type ConfigChange struct {
	Section string // "org_settings", "agent_options", "controls"
	Key     string // dot-separated path, e.g. "server_settings.server_url"
	Old     string
	New     string
	Drift   bool // already differs between the base branch and Fleet; not from this MR
}

ConfigChange represents a change in a top-level config section.

type DiffOption

type DiffOption func(*diffOptions)

DiffOption configures optional Diff behavior.

func WithBaseline

func WithBaseline(b *parser.ParsedRepo) DiffOption

WithBaseline provides a parsed base-branch repo. When set, Diff flags (ResourceChange.Drift, ConfigChange.Drift) changes that already exist between the base branch and Fleet -- made outside gitops, or merged but not yet deployed -- so they can be told apart from the MR's own changes.

func WithIncludeGlobal

func WithIncludeGlobal(v bool) DiffOption

WithIncludeGlobal forces global config diffing even when team filters are set. Used in --git mode when both global and team files changed.

func WithProfileEnricher

func WithProfileEnricher(e ProfileEnricher) DiffOption

WithProfileEnricher enables content-level diffing of MDM profiles. Without it, profiles are matched by name only and content changes are inferred from the changed-file list.

func WithScriptEnricher

func WithScriptEnricher(e ScriptEnricher) DiffOption

WithScriptEnricher enables script-level diffing for fleet-maintained apps.

func WithVerbose

func WithVerbose(v bool) DiffOption

WithVerbose enables detailed stderr logging of baseline drift marking.

type DiffResult

type DiffResult struct {
	Team                  string // "(global)" for default.yml scope
	Policies              ResourceDiff
	Queries               ResourceDiff
	Software              ResourceDiff
	Profiles              ResourceDiff
	Scripts               ResourceDiff
	Labels                LabelValidation
	LabelChanges          ResourceDiff   // label definitions (global scope only)
	Config                []ConfigChange // org_settings, agent_options, controls diffs
	Errors                []string
	SkippedConfigSections []string // config sections absent from API (e.g. "agent_options")
}

DiffResult holds the diff for a single team (or global scope).

func Diff

func Diff(current *api.FleetState, proposed *parser.ParsedRepo, teamFilters []string, changedFiles []string, opts ...DiffOption) []DiffResult

Diff computes the diff between current Fleet state and proposed YAML for all teams. If teamFilters is non-empty, only matching teams are diffed. If changedFiles is non-empty, only resources whose SourceFile matches are included in the output (MR-scoped filtering). Global config from default.yml is diffed when proposed.Global is non-nil.

type FieldDiff

type FieldDiff struct {
	Old      string
	New      string
	OldSlice []string // non-nil for slice-typed fields (used by JSON renderer)
	NewSlice []string // non-nil for slice-typed fields (used by JSON renderer)
	IsSlice  bool     // true when OldSlice/NewSlice should be used for JSON output
}

FieldDiff shows old vs new value for a single field.

type LabelRef

type LabelRef struct {
	Name         string
	HostCount    uint   // only for valid labels
	ReferencedBy string // which policy/query references it
}

LabelRef is a label name with metadata.

type LabelValidation

type LabelValidation struct {
	Valid   []LabelRef
	Missing []LabelRef
}

LabelValidation reports label cross-reference status.

type ProfileEnricher

type ProfileEnricher interface {
	EnrichProfileContents(ctx context.Context, profiles []api.Profile)
}

ProfileEnricher downloads the stored content of MDM profiles so their payload keys can be compared. Implementations populate Content on each profile that has a ProfileUUID; failures leave Content empty.

type ResourceChange

type ResourceChange struct {
	Name      string
	Fields    map[string]FieldDiff // field name -> old/new values
	HostCount uint                 // from API: affected hosts
	Warning   string               // e.g., "will delete compliance data"
	Drift     bool                 // already differs between the base branch and Fleet; not from this MR
}

ResourceChange describes a single resource change.

type ResourceDiff

type ResourceDiff struct {
	Added    []ResourceChange
	Modified []ResourceChange
	Deleted  []ResourceChange
}

ResourceDiff categorizes changes for one resource type.

func (ResourceDiff) IsEmpty

func (d ResourceDiff) IsEmpty() bool

IsEmpty returns true if there are no changes.

func (ResourceDiff) Total

func (d ResourceDiff) Total() int

Total returns the total number of changes.

type ScriptEnricher

type ScriptEnricher interface {
	EnrichFleetAppScripts(ctx context.Context, apps []api.TeamFleetApp)
}

ScriptEnricher fetches script content for inferred fleet-maintained apps. Implementations should populate InstallScript, UninstallScript, etc. on each TeamFleetApp that has a non-zero TitleID.

Jump to

Keyboard shortcuts

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