dns

package
v1.0.67 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDNSTimeout = 10 * time.Second

DefaultDNSTimeout is the default timeout for a DNS action which is 10 seconds

Variables

View Source
var DefaultDNS = New()
View Source
var DefaultDNSServers = []string{
	"ns0.agentuity.com:53",
	"ns1.agentuity.com:53",
	"ns2.agentuity.com:53",
}
View Source
var ErrClosed = errors.New("closed")
View Source
var ErrInvalidIP = fmt.Errorf("invalid ip address resolved for hostname")
View Source
var ErrTimeout = errors.New("timeout")
View Source
var ErrTransportRequired = errors.New("transport is required")

Functions

func ActionFromChannel added in v1.0.49

func ActionFromChannel(channel string) (string, error)

ActionFromChannel returns the action from the channel string

func FetchTLSCert added in v1.0.63

func FetchTLSCert(ctx context.Context, client *redis.Client, name string) (*tls.Certificate, time.Time, error)

FetchTLSCert fetches a TLS certificate from aether

func SendDNSAction added in v1.0.48

func SendDNSAction[R any, T TypedDNSAction[R]](ctx context.Context, action T, opts ...optionHandler) (*R, error)

SendDNSAction sends a DNS action to the DNS server with a timeout. If the timeout is 0, the default timeout will be used.

func WithRedis added in v1.0.48

func WithRedis(redis *redis.Client) optionHandler

WithRedis uses a redis client as the transport for the DNS action

func WithReply added in v1.0.48

func WithReply(reply bool) optionHandler

WithReply sets whether the DNS action should wait for a reply from the DNS server

func WithTimeout added in v1.0.48

func WithTimeout(timeout time.Duration) optionHandler

WithTimeout sets a custom timeout for the DNS action

func WithTransport added in v1.0.48

func WithTransport(transport Transport) optionHandler

WithTransport sets a custom transport for the DNS action

Types

type Answer

type Answer struct {
	Name string     `json:"name"`
	Type RecordType `json:"type"`
	TTL  uint       `json:"ttl"`
	Data string     `json:"data"`
}

type DNS

type DNS interface {
	// Lookup performs a DNS lookup for the given hostname and returns a valid IP address for the A record.
	Lookup(ctx context.Context, hostname string) (bool, *net.IP, error)
}

type DNSAction added in v1.0.48

type DNSAction interface {
	// GetID returns the unique ID of the DNS action
	GetID() string
	// GetReply returns the reply of the DNS action
	GetReply() string
	// SetReply sets the reply of the DNS action
	SetReply(string)
	// GetAction returns the action of the DNS action
	GetAction() string
}

DNSAction is an interface for a DNS action

type DNSAddAction added in v1.0.48

type DNSAddAction struct {
	DNSBaseAction
	Name  string `json:"name"`
	Type  string `json:"type,omitempty"`
	Value string `json:"value,omitempty"`
	// TTL is the DNS TTL for the record
	TTL time.Duration `json:"ttl,omitempty"`
	// Expires is the expiration time of the DNS record
	// if not provided the record will never expire
	Expires time.Duration `json:"expires,omitempty"`

	// Priority is the priority of the DNS record
	// only used for MX and SRV records
	Priority int `json:"priority,omitempty"`
	// Weight is the weight of the DNS record
	// only used for SRV records
	Weight int `json:"weight,omitempty"`
	// Port is the port of the DNS record
	// only used for SRV records
	Port int `json:"port,omitempty"`
}

func AddDNSAction added in v1.0.48

func AddDNSAction(name string, recordType DNSRecordType, value string, ttl time.Duration, expires time.Duration) *DNSAddAction

AddDNSAction adds a DNS action to the DNS server

func NewAddAction added in v1.0.65

func NewAddAction(name string, recordType DNSRecordType, value string) *DNSAddAction

NewAddDNSAction creates a new DNS add action

func (*DNSAddAction) WithExpires added in v1.0.65

func (a *DNSAddAction) WithExpires(expires time.Duration) *DNSAddAction

WithExpires sets the expiration if not provided the record will never expire

func (*DNSAddAction) WithPort added in v1.0.65

func (a *DNSAddAction) WithPort(port int) *DNSAddAction

WithPort sets the port of the DNS action only used for SRV records

func (*DNSAddAction) WithPriority added in v1.0.65

func (a *DNSAddAction) WithPriority(priority int) *DNSAddAction

WithPriority sets the priority of the DNS action only used for MX and SRV records

func (*DNSAddAction) WithTTL added in v1.0.65

func (a *DNSAddAction) WithTTL(ttl time.Duration) *DNSAddAction

func (*DNSAddAction) WithWeight added in v1.0.65

func (a *DNSAddAction) WithWeight(weight int) *DNSAddAction

WithWeight sets the weight of the DNS action only used for SRV records

type DNSBaseAction added in v1.0.48

type DNSBaseAction struct {
	MsgID  string `json:"msg_id"`
	Action string `json:"action"`
	Reply  string `json:"reply,omitempty"`
}

func (DNSBaseAction) GetAction added in v1.0.49

func (a DNSBaseAction) GetAction() string

GetAction returns the action of the DNS action

func (DNSBaseAction) GetID added in v1.0.48

func (a DNSBaseAction) GetID() string

GetID returns the unique ID of the DNS action

func (DNSBaseAction) GetReply added in v1.0.48

func (a DNSBaseAction) GetReply() string

GetReply returns the reply of the DNS action

func (*DNSBaseAction) SetReply added in v1.0.48

func (a *DNSBaseAction) SetReply(reply string)

SetReply sets the reply of the DNS action

type DNSCert added in v1.0.48

type DNSCert struct {
	Certificate []byte    `json:"certificate"`
	PrivateKey  []byte    `json:"private_key"`
	Expires     time.Time `json:"expires"`
	// Domain is the name for which the certificate is valid, it may be different from the name requested
	Domain string `json:"domain"`
}

type DNSCertAction added in v1.0.48

type DNSCertAction struct {
	DNSBaseAction
	Name string `json:"name"`
}

func CertRequestDNSAction added in v1.0.48

func CertRequestDNSAction(name string) *DNSCertAction

CertRequestDNSAction requests a certificate from the DNS server

type DNSDeleteAction added in v1.0.48

type DNSDeleteAction struct {
	DNSBaseAction
	// Name is the name of the DNS record to delete.
	Name string `json:"name"`
	// IDs are the IDs of the DNS records to delete (within a name). This allows for clients to manage a specific record if they keep track of the ID.
	// If not provided, any name match will be deleted.
	IDs []string `json:"ids,omitempty"`
}

func DeleteDNSAction added in v1.0.48

func DeleteDNSAction(name string, ids ...string) *DNSDeleteAction

DeleteDNSAction deletes a DNS action from the DNS server

type DNSRecord added in v1.0.55

type DNSRecord struct {
	IDs []string `json:"ids"`
}

func (*DNSRecord) GetID added in v1.0.65

func (r *DNSRecord) GetID() string

type DNSRecordType added in v1.0.48

type DNSRecordType string
const (
	RecordTypeA     DNSRecordType = "A"
	RecordTypeAAAA  DNSRecordType = "AAAA"
	RecordTypeCNAME DNSRecordType = "CNAME"
	RecordTypeMX    DNSRecordType = "MX"
	RecordTypeNS    DNSRecordType = "NS"
	RecordTypeTXT   DNSRecordType = "TXT"
	RecordTypeSRV   DNSRecordType = "SRV"
)

type DNSResponse added in v1.0.48

type DNSResponse[T any] struct {
	MsgID   string `json:"msg_id"`
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
	Data    *T     `json:"data,omitempty"`
}

func NewDNSResponse added in v1.0.55

func NewDNSResponse[R any, T TypedDNSAction[R]](action T, data *R, err error) *DNSResponse[R]

type Dns

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

func New

func New(opts ...WithConfig) *Dns

New creates a new DNS caching resolver.

func (*Dns) Lookup

func (d *Dns) Lookup(ctx context.Context, hostname string) (bool, *net.IP, error)

Lookup performs a DNS lookup for the given hostname and returns a valid IP address for the A record.

type Message added in v1.0.48

type Message struct {
	Payload []byte
}

Message is a message from the transport layer

type RecordType

type RecordType uint8
const (
	A     RecordType = 1
	CNAME RecordType = 5
)

type Result

type Result struct {
	Status StatusType `json:"Status"`
	Answer []Answer   `json:"Answer"`
}

type StatusType

type StatusType uint8
const (
	NoError  StatusType = 0
	FormErr  StatusType = 1
	ServFail StatusType = 2
	NXDomain StatusType = 3
	Refused  StatusType = 5
	NotAuth  StatusType = 9
	NotZone  StatusType = 10
)

func (StatusType) String

func (s StatusType) String() string

type Subscriber added in v1.0.48

type Subscriber interface {
	// Close closes the subscriber
	Close() error
	// Channel returns a channel of messages
	Channel() <-chan *Message
}

Subscriber is an interface for a subscriber to the transport layer

type Transport added in v1.0.48

type Transport interface {
	Subscribe(ctx context.Context, channel string) Subscriber
	Publish(ctx context.Context, channel string, payload []byte) error
}

Transport is an interface for a transport layer for the DNS server

type TypedDNSAction added in v1.0.55

type TypedDNSAction[R any] interface {
	DNSAction
	// contains filtered or unexported methods
}

TypedDNSAction is an interface for a DNS action that also specifies its expected response data type.

type WithConfig

type WithConfig func(config *dnsConfig)

func WithCache added in v1.0.51

func WithCache(cache cache.Cache) WithConfig

WithCache will set the cache for the DNS resolver.

func WithFailIfLocal

func WithFailIfLocal() WithConfig

WithFailIfLocal will cause the DNS resolver to fail if the hostname is a local hostname.

Jump to

Keyboard shortcuts

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