Documentation ¶
Index ¶
- Constants
- func GetIfaceMngTmpAddr(ifname string) (net.IP, error)
- func GetMngTmpAddr(addr net.IP, flags AddrFlags) (net.IP, error)
- func GetMngTmpAddrFromUpdate(update netlink.AddrUpdate) (net.IP, error)
- func IsIPv6(addr net.IP) bool
- func IsMngTmpAddr(flags AddrFlags) bool
- func MonitorUpdatesAndDispatch(ch <-chan netlink.AddrUpdate, done chan bool, updater DnsUpdater, ...)
- func NewDoClientWithEnvToken() (*godo.Client, context.Context, error)
- func UpdateDnsRecord(client *godo.Client, ctx context.Context, name, zone string, value net.IP, ...) error
- type AddrFlags
- type DnsRecord
- type DnsUpdater
- type DoDnsUpdater
- type FakeDnsUpdater
Constants ¶
const ( DefaultTTL int = 300 ErrNoCachedRecord string = "no record ID found for update" ErrMultipleRecords string = ">1 matching record exists; cannot update" ErrNoMatchingId string = "no matching record ID found" )
const ( Ifa_F_Secondary AddrFlags = 1 << iota Ifa_F_NoDad Ifa_F_Optimistic Ifa_F_DadFailed Ifa_F_HomeAddress Ifa_F_Deprecated Ifa_F_Tentative Ifa_F_Permanent Ifa_F_ManageTempAddr Ifa_F_NoPrefixRoute Ifa_F_McAutoJoin Ifa_F_StablePrivacy ErrNoMngTmpAddr string = "no MngTmpAddr found" ErrDeleteUpdate string = "update was delete not add" )
const (
ErrNoDoEnvToken string = "no DigitalOcean Token (DO_TOKEN) found in os env"
)
Variables ¶
This section is empty.
Functions ¶
func GetIfaceMngTmpAddr ¶ added in v0.2.0
GetIfaceMngTmpAddr retrieves the addresses from the interface of the provided name. If an address with the `IFA_F_MANAGETEMPADDR` ifa_flag is set (0x100), it returns that address and a nil error. If no address with the flag is found, it returns a ErrNoMngTmpAddr error. Any other netlink errors from retrieving the interface or its addresses are bubbled up.
func GetMngTmpAddr ¶
GetMngTmpAddr takes a net.IP and AddrFlags. If the flags have the `IFA_F_MANAGETEMPADDR` ifa_flag set (0x100), it returns that address as a net.IP. If not, it returns nil and an error.
func GetMngTmpAddrFromUpdate ¶ added in v0.3.0
func GetMngTmpAddrFromUpdate(update netlink.AddrUpdate) (net.IP, error)
GetMngTmpAddrFromUpdate takes a netlink.AddrUpdate and tests whether it: * is a new/added address * has the `IFA_F_MANAGETEMPADDR` ifa_flag set (0x100) If so, it returns the address as a net.IP with no error If it is a new address but does not have the `IFA_F_MANAGETEMPADDR` flag set, it returns nil and a ErrNoMngTmpAddr error If is not a new/added address (i.e. it is a deleted address), it returns nil and a ErrDeleteUpdate error.
func IsIPv6 ¶ added in v0.2.0
IsIPv6 determines if the provided `net.IP` is an IPv6 address. It returns a bool.
func IsMngTmpAddr ¶
IsMngTmpAddr responds with a bool whether the provided AddrFlags have the `IFA_F_MANAGETEMPADDR` ifa_flag set (0x100).
func MonitorUpdatesAndDispatch ¶ added in v0.3.0
func MonitorUpdatesAndDispatch(ch <-chan netlink.AddrUpdate, done chan bool, updater DnsUpdater, linkIndex int)
MonitorUpdatesAndDispatch monitors a channel for netlink.AddrUpdate messages. If the update indicates a new address and that address is a MngTmpAddr, it dispatches the address through the provided DnsUpdater in order to update the record in the DnsUpdater.
func NewDoClientWithEnvToken ¶ added in v0.3.0
NewClientWithEnvToken retrieves a DigitalOcean API token from the env var `DO_TOKEN` and returns a *godo.Client and context.Context to be used to communicate with the DigitalOcean API.
func UpdateDnsRecord ¶
func UpdateDnsRecord(client *godo.Client, ctx context.Context, name, zone string, value net.IP, force bool) error
UpdateDnsRecord uses the provided client & context to effectively perform an "upsert" of the provided name in the provided zone. It checks if an existing AAAA record exists for that name & zone. If not, it creates the record using *godo.Client.Domains.CreateRecord(). If a single matching record exists, it updates that record using *godo.Client.Domains.EditRecord(). If more than one matching record exists, it requires a `force` bool to be set to blindly overwrite the first matching result. It returns nothing except an error.
Types ¶
type DnsUpdater ¶ added in v0.3.0
type DnsUpdater interface { SetAddress(net.IP) RefreshRecords() error CreateRecord() error UpdateRecord(bool) error CreateOrUpdateRecord() error }
A DnsUpdater implements the needed RefreshRecords, CreateRecord, and UpdateRecord methods to be able to update an existing DNS AAAA record or create a new one.
type DoDnsUpdater ¶ added in v0.3.0
type DoDnsUpdater struct {
// contains filtered or unexported fields
}
A DoDnsUpdater can search and update DNS records through the DigitalOcean godo package.
func NewDoDnsUpdaterWithEnvToken ¶ added in v0.3.0
func NewDoDnsUpdaterWithEnvToken(name, zone string) (DoDnsUpdater, error)
NewDoDnsUpdaterWithEnvToken creates a ctx.Context and *godo.Client, retrieves a DigitalOcean API token from the DO_TOKEN env var, and returns a DoDnsUpdater for the provided `name` and `zone` populated with those values as well as a ttl of 300 for the DoDnsUpdater.
func (*DoDnsUpdater) CreateOrUpdateRecord ¶ added in v0.3.0
func (u *DoDnsUpdater) CreateOrUpdateRecord() error
CreateOrUpdateRecord will try to update a record; if that fails, meaning no record currently exists with the provider, then it will create a new record.
func (*DoDnsUpdater) CreateRecord ¶ added in v0.3.0
func (u *DoDnsUpdater) CreateRecord() error
CreateRecord creates a new DNS AAAA record using DoDnsUpdater. Its only return is an error, if encountered.
func (*DoDnsUpdater) RefreshRecords ¶ added in v0.3.0
func (u *DoDnsUpdater) RefreshRecords() error
SearchRecords will search for instances of an AAAA record matching the provided name and zone using DoDnsUpdater. It returns a list of matching records as a godo.DomainRecord slice, and any encountered errors.
func (*DoDnsUpdater) SetAddress ¶ added in v0.3.0
func (u *DoDnsUpdater) SetAddress(addr net.IP)
SetAddress sets the address that the DoDnsUpdater will use when performing DNS updates for the record.
func (*DoDnsUpdater) UpdateRecord ¶ added in v0.3.0
func (u *DoDnsUpdater) UpdateRecord(tryRefresh bool) error
UpdateRecord uses the provided client & context to effectively perform an "upsert" of the provided name in the provided zone. It checks if an existing AAAA record exists for that name & zone. If not, it creates the record using *godo.Client.Domains.CreateRecord(). If a single matching record exists, it updates that record using *godo.Client.Domains.EditRecord(). If more than one matching record exists, it requires a `force` bool to be set to blindly overwrite the first matching result. It returns nothing except an error.
type FakeDnsUpdater ¶ added in v0.3.0
type FakeDnsUpdater struct {
// contains filtered or unexported fields
}
func (*FakeDnsUpdater) CreateOrUpdateRecord ¶ added in v0.3.0
func (u *FakeDnsUpdater) CreateOrUpdateRecord() error
CreateOrUpdateRecord will try to update a record; if that fails, meaning no record currently exists with the provider, then it will create a new record.
func (*FakeDnsUpdater) CreateRecord ¶ added in v0.3.0
func (u *FakeDnsUpdater) CreateRecord() error
CreateRecord will create a new DNS AAAA record using the address set on the FakeDnsUpdater.
func (*FakeDnsUpdater) RefreshRecords ¶ added in v0.3.0
func (u *FakeDnsUpdater) RefreshRecords() error
RefreshRecords searches the u.recordStore for records that match u.recordName and stores them into u.records.
func (*FakeDnsUpdater) SetAddress ¶ added in v0.3.0
func (u *FakeDnsUpdater) SetAddress(addr net.IP)
SetAddress sets the address that the FakeDnsUpdater will use when performing DNS updates for the record.
func (*FakeDnsUpdater) UpdateRecord ¶ added in v0.3.0
func (u *FakeDnsUpdater) UpdateRecord(tryRefresh bool) error
UpdateRecord updates an existing dns record with the provider to the currently discovered u.address. If there is no existing local record cached, the updater doesn't know the ID of the record to update and it returns an error. If multiple matching records are found with the provider, the updater is unable to update the record and it returns an error. If the discovered address matches the current record value, the updater does nothing.