Documentation ¶
Index ¶
- func CompareRecordSets(older []*Record, newer []*Record, zd *ZoneDelta)
- func FindConfig(basename string) (string, error)
- func GetNetboxIPAddresses(host, token string) (netbox.IPAddrs, error)
- func IncrementSerial(cz *ConfigZone, serial uint32) (uint32, error)
- func ReverseName(addr netip.Addr) string
- type ByLength
- type CloudDNS
- type Config
- type ConfigRoot
- type ConfigZone
- type DNSProvider
- type Record
- type Zone
- type ZoneDelta
- type ZoneFileDNS
- type Zones
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareRecordSets ¶
CompareRecordSets compares sets of records and updates a ZoneDelta with results.
func FindConfig ¶
FindConfig looks in several locations for a config file named "$basename.yml", "$basename.yaml", "$basename.json", or "$basename.cue".
func GetNetboxIPAddresses ¶
GetNetboxIPAddresses fetches a list of IP Addresses from a Netbox server.
func IncrementSerial ¶
func IncrementSerial(cz *ConfigZone, serial uint32) (uint32, error)
IncrementSerial increments the serial number on a DNS zone. This recognizes 2 basic serial number patterns:
1. Simple incrememnting integers (1 -> 2 -> 3, etc) 2. Date-based serial numbers (2022123004 -> 2022123005 -> 2022123100)
It assumes that any serial number greather than 2000010100 (the first date-based serial number in 2000 AD) is date-based and updates it accordingly. If the date portion of the serial matches todays date, then it increments the serial number by one. If the date-based portion does *not* match today's date, then the new serial number is today, with two trailing 0s.
Finally, there is a check that the new serial is greater than the old serial. This will break after 100 updates happen on a single day (2022123099 will get incremented to 2022123100, which is fine, but the following update will try to use 2022123000, which will fail). This is a fundimental problem with date-based serial formats, and will clear up on its own once the calendar rolls over to the next day.
func ReverseName ¶
ReverseName takes an IP address and returns the correct reverse DNS name for that IP. It maps IPv4 addresses into `in-addr.arpa` and IPv6 addresses into `ip6.arpa`.
Types ¶
type ByLength ¶
type ByLength []*Zone
ByLength is a wrapper for []string for sorting the string slice by length, from longest to shortest.
type CloudDNS ¶
type CloudDNS struct {
// contains filtered or unexported fields
}
CloudDNS implements talking to Google Cloud DNS, and provides methods for fetching existing DNS entries, adding new entries, or deleting old entries.
func NewCloudDNS ¶
func NewCloudDNS(ctx context.Context, cz *ConfigZone) (*CloudDNS, error)
NewCloudDNS creates a new CloudDNS.
func (*CloudDNS) ImportZone ¶
func (cd *CloudDNS) ImportZone(cfg *ConfigZone) (*Zone, error)
ImportZone imports all entries from the specified Google Cloud DNS zone.
func (*CloudDNS) RemoveRecord ¶
func (cd *CloudDNS) RemoveRecord(cz *ConfigZone, r *Record) error
RemoveRecord removes a DNS entry from Google Cloud DNS.
TODO: implement
func (*CloudDNS) Save ¶
func (cd *CloudDNS) Save(cz *ConfigZone) error
Save flushes changes to Cloud DNS. This is a no-op at the moment, but we'll eventually batch queries together for performance.
func (*CloudDNS) WriteRecord ¶
func (cd *CloudDNS) WriteRecord(cz *ConfigZone, r *Record) error
WriteRecord adds a record to Google Cloud DNS.
type Config ¶
type Config struct { Netbox struct { Host string `json:"host,omitempty"` Token string `json:"token,omitempty"` } `json:"netbox,omitempty"` Defaults struct { Zonetype string `json:"zonetype,omitempty"` TTL int64 `json:"ttl,omitempty"` Project string `json:"project,omitempty"` } `json:"defaults,omitempty"` ZoneMap map[string]*ConfigZone `json:"zonemap,omitempty"` Zones []*ConfigZone `json:"zones,omitempty"` }
Config matches the `config` item in the schema defined in `config.cue`. Each item must be marked as `notempty` and must have a JSON tag that matches the name in the CUE file.
func ParseConfig ¶
ParseConfig parses a config file and returns a Config object or an error. When used with FindConfig, it can hunt down a config file in several formats and then parse and validate it automatically.
type ConfigRoot ¶
type ConfigRoot struct {
Config Config `json:"config,omitempty"`
}
ConfigRoot matches the root of the schema defined in `config.cue`.
type ConfigZone ¶
type ConfigZone struct { ZoneType string `json:"zonetype,omitempty"` Name string `json:"name,omitempty"` ZoneName string `json:"zonename,omitempty"` Filename string `json:"filename,omitempty"` Project string `json:"project,omitempty"` TTL int64 `json:"ttl,omitempty"` DeleteEntries bool `json:"delete_entries,omitempty"` }
ConfigZone matches `Zone` in `config.cue`. This needs to be the union of all defined zone types. At the moment, this is only CloudDNSZone, but other types are possible. They're switched based on the `ZoneType` field. Then, code in `dns.go` uses that to dispatch to the correct back-end handler.
type DNSProvider ¶
type DNSProvider interface { ImportZone(cz *ConfigZone) (*Zone, error) WriteRecord(cz *ConfigZone, r *Record) error RemoveRecord(cz *ConfigZone, r *Record) error Save(cz *ConfigZone) error }
DNSProvider is an interface to a DNS provider backend, such a CloudDNS or ZoneFile.
func NewDNSProvider ¶
func NewDNSProvider(ctx context.Context, cz *ConfigZone) (DNSProvider, error)
NewDNSProvider creates a provider of the correct type for the described zone.
type Record ¶
Record describes a DNS record, like 'foo.example.com IN AAAA 1:2::3:4'.
func (*Record) RrdataNoDot ¶
RrdataNoDot returns the Rrdata for a record, with no trailing dor.
type Zone ¶
type Zone struct { Name string ZoneName string Project string Filename string DeleteEntries bool TTL int64 Records map[string][]*Record }
Zone represents a single DNS zone on a single provider (Google Cloud DNS, fixed zone files, etc).
func (*Zone) AddRecord ¶
AddRecord adds a single record to this zone. It does not check that this is the correct zone for the record.
func (*Zone) NewZoneDelta ¶
NewZoneDelta creates a new ZoneDelta. This is used to track changes between versions of a DNS zone.
type ZoneDelta ¶
type ZoneDelta struct { Name string ZoneName string Project string Filename string AddRecords map[string][]*Record RemoveRecords map[string][]*Record }
ZoneDelta describes the difference between two versions of the same zone. It shows added and removed records.
type ZoneFileDNS ¶
type ZoneFileDNS struct {
// contains filtered or unexported fields
}
ZoneFileDNS provides an implementation of DNS using traditional BIND-style zone files.
func NewZoneFileDNS ¶
func NewZoneFileDNS(ctx context.Context, cz *ConfigZone) (*ZoneFileDNS, error)
NewZoneFileDNS creates a new ZoneFileDNS object.
func (*ZoneFileDNS) ImportZone ¶
func (zfd *ZoneFileDNS) ImportZone(cz *ConfigZone) (*Zone, error)
ImportZone reads DNS entries from a zone file on disk (as specified as part of the zone config in the netbox2dns config file) and populates the ZoneFileDNS with them.
func (*ZoneFileDNS) RemoveRecord ¶
func (zfd *ZoneFileDNS) RemoveRecord(cz *ConfigZone, r *Record) error
RemoveRecord removes a Record from the zonefile behind the ZoneFileDNS. Note that this won't actually be written until 'Save()' is called.
func (*ZoneFileDNS) Save ¶
func (zfd *ZoneFileDNS) Save(cz *ConfigZone) error
Save flushes the current zonefile to disk. Without this, no changes will be written out.
func (*ZoneFileDNS) WriteRecord ¶
func (zfd *ZoneFileDNS) WriteRecord(cz *ConfigZone, r *Record) error
WriteRecord writes a Record to the zonefile behind the ZoneFileDNS. Note that this won't actually be written until 'Save()' is called.
type Zones ¶
Zones represents the set of all DNS zones known to netbox2dns.
func ImportZones ¶
ImportZones creates new DNS providers for each zone and imports all existing records for each zone.
func (*Zones) AddAddrs ¶
AddAddrs adds multiple addresses to a set of Zones. This creates both forward and reverse DNS entries.
func (*Zones) AddRecord ¶
AddRecord adds a record to the appropriate zone. It finds the longest suffix match among all known zones and adds the new record there. If no zones match, then an error is returned.
func (*Zones) Compare ¶
Compare compares two Zones structures and returns a slice of ZoneDeltas showing what has changed.
func (*Zones) NewZone ¶
func (z *Zones) NewZone(cz *ConfigZone)
NewZone creates a new Zone in Zones using the settings in the provided ConfigZone. The resulting Zone is added to Zones automatically.