diff

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package diff provides configuration comparison functionality for OPNsense configurations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct{}

Analyzer performs structural comparison of configurations.

func NewAnalyzer

func NewAnalyzer() *Analyzer

NewAnalyzer creates a new structural analyzer.

func (*Analyzer) CompareDHCP

func (a *Analyzer) CompareDHCP(old, newCfg *schema.Dhcpd) []Change

CompareDHCP compares DHCP configuration between two configs. Focuses on persistent configuration (static reservations) not ephemeral state (leases).

func (*Analyzer) CompareFirewallRules

func (a *Analyzer) CompareFirewallRules(old, newCfg []schema.Rule) []Change

CompareFirewallRules compares firewall rules between two configs.

func (*Analyzer) CompareInterfaces

func (a *Analyzer) CompareInterfaces(old, newCfg *schema.Interfaces) []Change

CompareInterfaces compares interface configuration between two configs.

func (*Analyzer) CompareNAT

func (a *Analyzer) CompareNAT(old, newCfg *schema.Nat) []Change

CompareNAT compares NAT configuration between two configs.

func (*Analyzer) CompareRoutes

func (a *Analyzer) CompareRoutes(old, newCfg *schema.StaticRoutes) []Change

CompareRoutes compares static route configuration between two configs.

func (*Analyzer) CompareSystem

func (a *Analyzer) CompareSystem(old, newCfg *schema.System) []Change

CompareSystem compares system configuration between two configs.

func (*Analyzer) CompareUsers

func (a *Analyzer) CompareUsers(old, newCfg []schema.User) []Change

CompareUsers compares user configuration between two configs.

func (*Analyzer) CompareVLANs

func (a *Analyzer) CompareVLANs(old, newCfg *schema.VLANs) []Change

CompareVLANs compares VLAN configuration between two configs.

type Change

type Change struct {
	Type           ChangeType `json:"type"`
	Section        Section    `json:"section"`
	Path           string     `json:"path"`
	Description    string     `json:"description"`
	OldValue       string     `json:"old_value,omitempty"`
	NewValue       string     `json:"new_value,omitempty"`
	SecurityImpact string     `json:"security_impact,omitempty"`
}

Change represents a single configuration change.

type ChangeType

type ChangeType string

ChangeType represents the type of configuration change.

const (
	// ChangeAdded indicates a new element was added.
	ChangeAdded ChangeType = "added"
	// ChangeRemoved indicates an element was removed.
	ChangeRemoved ChangeType = "removed"
	// ChangeModified indicates an element was modified.
	ChangeModified ChangeType = "modified"
)

func (ChangeType) IsValid

func (c ChangeType) IsValid() bool

IsValid returns true if the change type is a valid value.

func (ChangeType) String

func (c ChangeType) String() string

String returns the string representation of the change type.

func (ChangeType) Symbol

func (c ChangeType) Symbol() string

Symbol returns a single-character symbol for the change type.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine orchestrates configuration comparison.

func NewEngine

func NewEngine(old, newCfg *model.OpnSenseDocument, opts Options, logger *log.Logger) *Engine

NewEngine creates a new diff engine.

func (*Engine) Compare

func (e *Engine) Compare(ctx context.Context) (*Result, error)

Compare performs the comparison and returns results.

type Metadata

type Metadata struct {
	OldFile     string    `json:"old_file"`
	NewFile     string    `json:"new_file"`
	OldVersion  string    `json:"old_version,omitempty"`
	NewVersion  string    `json:"new_version,omitempty"`
	ComparedAt  time.Time `json:"compared_at"`
	ToolVersion string    `json:"tool_version"`
}

Metadata contains comparison metadata.

type OpnSenseDocument

type OpnSenseDocument = model.OpnSenseDocument

OpnSenseDocument is a type alias for model.OpnSenseDocument for package convenience.

type Options

type Options struct {
	Sections     []string // Filter to specific sections (empty = all)
	SecurityOnly bool     // Show only security-relevant changes
	Format       string   // Output format (terminal, markdown, json)
}

Options configures diff behavior.

func (*Options) ShouldIncludeSection

func (o *Options) ShouldIncludeSection(section Section) bool

ShouldIncludeSection returns true if the section should be included.

type Result

type Result struct {
	Summary  Summary  `json:"summary"`
	Metadata Metadata `json:"metadata"`
	Changes  []Change `json:"changes"`
}

Result contains the complete diff result.

func NewResult

func NewResult() *Result

NewResult creates a new Result with initialized slices.

func (*Result) AddChange

func (r *Result) AddChange(change Change)

AddChange adds a change to the result and updates the summary.

func (*Result) ChangesBySection

func (r *Result) ChangesBySection() map[Section][]Change

ChangesBySection returns changes grouped by section.

func (*Result) HasChanges

func (r *Result) HasChanges() bool

HasChanges returns true if there are any changes.

type Section

type Section string

Section represents a configuration section.

const (
	// SectionSystem represents system configuration.
	SectionSystem Section = "system"
	// SectionFirewall represents firewall rules.
	SectionFirewall Section = "firewall"
	// SectionNAT represents NAT configuration.
	SectionNAT Section = "nat"
	// SectionInterfaces represents interface configuration.
	SectionInterfaces Section = "interfaces"
	// SectionVLANs represents VLAN configuration.
	SectionVLANs Section = "vlans"
	// SectionDHCP represents DHCP configuration.
	SectionDHCP Section = "dhcp"
	// SectionDNS represents DNS configuration.
	SectionDNS Section = "dns"
	// SectionVPN represents VPN configuration.
	SectionVPN Section = "vpn"
	// SectionUsers represents user configuration.
	SectionUsers Section = "users"
	// SectionRouting represents routing configuration.
	SectionRouting Section = "routing"
	// SectionCertificates represents certificate configuration.
	SectionCertificates Section = "certificates"
)

func AllSections

func AllSections() []Section

AllSections returns all available sections.

func ImplementedSections

func ImplementedSections() []Section

ImplementedSections returns sections that have comparison logic implemented.

func (Section) IsImplemented

func (s Section) IsImplemented() bool

IsImplemented returns true if the section has comparison logic implemented.

func (Section) IsValid

func (s Section) IsValid() bool

IsValid returns true if the section is a valid value.

func (Section) String

func (s Section) String() string

String returns the string representation of the section.

type SecurityImpact

type SecurityImpact string

SecurityImpact represents the security impact level of a change.

const (
	// SecurityImpactHigh indicates a high security impact (e.g., permissive any-any rules).
	SecurityImpactHigh SecurityImpact = "high"
	// SecurityImpactMedium indicates a medium security impact (e.g., user changes, NAT modifications).
	SecurityImpactMedium SecurityImpact = "medium"
	// SecurityImpactLow indicates a low security impact (e.g., minor configuration changes).
	SecurityImpactLow SecurityImpact = "low"
)

func (SecurityImpact) IsValid

func (s SecurityImpact) IsValid() bool

IsValid returns true if the security impact is a valid value.

func (SecurityImpact) String

func (s SecurityImpact) String() string

String returns the string representation of the security impact.

type Summary

type Summary struct {
	Added    int `json:"added"`
	Removed  int `json:"removed"`
	Modified int `json:"modified"`
	Total    int `json:"total"`
}

Summary contains aggregate statistics about the diff.

Directories

Path Synopsis
Package formatters provides output formatting for diff results.
Package formatters provides output formatting for diff results.

Jump to

Keyboard shortcuts

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