diff2

package
v4.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisableOrdering bool

DisableOrdering can be set to true to disable the reordering of the changes

Functions

func ByZone

func ByZone(existing models.Records, dc *models.DomainConfig, compFunc ComparableFunc) ([]string, bool, error)

ByZone takes two lists of records (existing and desired) and returns text to output to users describing the change, a bool indicating if there were any changes, and a possible err value.

Use this with DNS providers whose API updates the entire zone at a time. That is, to make any change (even just 1 record) the entire DNS zone is uploaded.

The user should see a list of changes as if individual records were updated.

Example usage:

msgs, changes, err := diff2.ByZone(foundRecords, dc, nil)
if err != nil {
  return nil, err
}
if changes {
	// Generate a "correction" that uploads the entire zone.
	// (dc.Records are the new records for the zone).
}

Example providers include: BIND, AUTODNS

Types

type Change

type Change struct {
	Type Verb // Add, Change, Delete

	Key        models.RecordKey // .Key.Type is "" unless using ByRecordSet
	Old        models.Records
	New        models.Records                // any changed or added records at Key.
	Msgs       []string                      // Human-friendly explanation of what changed
	MsgsJoined string                        // strings.Join(Msgs, "\n")
	MsgsByKey  map[models.RecordKey][]string // Messages for a given key

	// HintOnlyTTL is true only if (.Type == diff2.CHANGE) && (there is
	// exactly 1 record being updated) && (the only change is the TTL)
	HintOnlyTTL bool

	// HintRecordSetLen1 is true only if (.Type == diff2.CHANGE) &&
	// (there is exactly 1 record at this RecordSet).
	// For example, MSDNS can use a more efficient command if it knows
	// that `Get-DnsServerResourceRecord -Name FOO -RRType A` will
	// return exactly one record.
	HintRecordSetLen1 bool
}

Change is an instruction to the provider. Generally if one properly executes all the changes, an "existing" zone will turn into the "desired" zone.

func (*Change) CreateCorrection

func (c *Change) CreateCorrection(correctionFunction func() error) *models.Correction

CreateCorrection creates a new Correction based on the given function and prefills it with the Msg of the current Change

func (*Change) CreateCorrectionWithMessage

func (c *Change) CreateCorrectionWithMessage(msg string, correctionFunction func() error) *models.Correction

CreateCorrectionWithMessage creates a new Correction based on the given function and prefixes given function with the Msg of the current change

func (*Change) CreateMessage

func (c *Change) CreateMessage() *models.Correction

CreateMessage creates a new correction with only the message. Used for diff2.Report corrections

func (Change) GetDependencies added in v4.3.0

func (c Change) GetDependencies() []dnsgraph.Dependency

GetDependencies returns the depenencies of a change.

func (Change) GetName added in v4.3.0

func (c Change) GetName() string

GetName returns the FQDN of the host being changed.

func (Change) GetType added in v4.3.0

func (c Change) GetType() dnsgraph.NodeType

GetType returns the type of a change.

type ChangeList

type ChangeList []Change

ChangeList is a list of Change

func ByLabel

func ByLabel(existing models.Records, dc *models.DomainConfig, compFunc ComparableFunc) (ChangeList, error)

ByLabel takes two lists of records (existing and desired) and returns instructions for turning existing into desired.

Use this with DNS providers whose API updates one label at a time. That is, updates are done by sending a list of DNS records to be served at a particular label, or the label itself is deleted.

Examples include: GANDI_V5

func ByRecord

func ByRecord(existing models.Records, dc *models.DomainConfig, compFunc ComparableFunc) (ChangeList, error)

ByRecord takes two lists of records (existing and desired) and returns instructions for turning existing into desired.

Use this with DNS providers whose API updates one record at a time.

Note: The .Old and .New field are lists ([]models.RecordConfig) but when using ByRecord() they will never have more than one entry. A create always has exactly 1 new: .New[0] A change always has exactly 1 old and 1 new: .Old[0] and .New[0] A delete always has exactly 1 old: .Old[0]

Examples include: CLOUDFLAREAPI, HEDNS, INWX, MSDNS, OVH, PORKBUN, VULTR

func ByRecordSet

func ByRecordSet(existing models.Records, dc *models.DomainConfig, compFunc ComparableFunc) (ChangeList, error)

ByRecordSet takes two lists of records (existing and desired) and returns instructions for turning existing into desired.

Use this with DNS providers whose API updates one recordset at a time. A recordset is all the records of a particular type at a label. For example, if www.example.com has 3 A records and a TXT record, if A records are added, changed, or removed, the API takes www.example.com, A, and a list of all the desired IP addresses.

Examples include: AZURE_DNS, GCORE, NS1, ROUTE53

type ComparableFunc

type ComparableFunc func(*models.RecordConfig) string

ComparableFunc is a signature for functions used to generate a comparable blob for custom records and records with metadata.

type CompareConfig

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

CompareConfig stores a zone's records in a structure that makes comparing two zones convenient.

func NewCompareConfig

func NewCompareConfig(origin string, existing, desired models.Records, compFn ComparableFunc) *CompareConfig

NewCompareConfig creates a CompareConfig from a set of records and other data.

type Verb

type Verb int

Verb indicates the Change's type (create, delete, etc.)

const (
	CREATE Verb // Create a record/recordset/label where none existed before.
	CHANGE      // Change existing record/recordset/label
	DELETE      // Delete existing record/recordset/label
	REPORT      // No change, but I have something to say!
)

CREATE and other verbs.

func (Verb) String

func (i Verb) String() string

Jump to

Keyboard shortcuts

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