dns

package
v2.7.11 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 7 Imported by: 205

Documentation

Overview

Package dns contains definitions for NS1 zones/records/answers/etc.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	Rdata []interface{} `json:"answer"`
	*AliasAnswer
}

Alias is used as an alias for an answer so that the custom marshaler isn't used.

type AliasAnswer

type AliasAnswer Answer

AliasAnswer is a duplicate of Answer.

type Answer

type Answer struct {
	ID string `json:"id,omitempty"`

	Meta *data.Meta `json:"meta,omitempty"`

	// Answer response data. eg:
	// Av4: ["1.1.1.1"]
	// Av6: ["2001:db8:85a3::8a2e:370:7334"]
	// MX:  [10, "2.2.2.2"]
	Rdata []string `json:"answer"`

	// Region(grouping) that answer belongs to.
	RegionName string `json:"region,omitempty"`
}

Answer wraps the values of a Record's "filters" attribute

func NewALIASAnswer

func NewALIASAnswer(host string) *Answer

NewALIASAnswer creates an Answer for ALIAS record.

func NewAnswer

func NewAnswer(rdata []string) *Answer

NewAnswer creates a generic Answer with given rdata.

func NewAv4Answer

func NewAv4Answer(host string) *Answer

NewAv4Answer creates an Answer for A record.

func NewAv6Answer

func NewAv6Answer(host string) *Answer

NewAv6Answer creates an Answer for AAAA record.

func NewCAAAnswer

func NewCAAAnswer(flag int, tag, value string) *Answer

NewCAAAnswer creates an Answer for a CAA record.

func NewCNAMEAnswer

func NewCNAMEAnswer(name string) *Answer

NewCNAMEAnswer creates an Answer for CNAME record.

func NewDSAnswer

func NewDSAnswer(key string, algorithm string, t string, digest string) *Answer

NewDSAnswer creates an Answer for DS record.

func NewMXAnswer

func NewMXAnswer(pri int, host string) *Answer

NewMXAnswer creates an Answer for MX record.

func NewSRVAnswer

func NewSRVAnswer(priority, weight, port int, target string) *Answer

NewSRVAnswer creates an Answer for SRV record.

func NewTXTAnswer

func NewTXTAnswer(text string) *Answer

NewTXTAnswer creates an Answer for TXT record.

func NewURLFWDAnswer

func NewURLFWDAnswer(from, to string, redirectType, pathForwardingMode, queryForwarding int) *Answer

NewURLFWDAnswer creates an Answer for URLFWD record.

func (*Answer) SetRegion

func (a *Answer) SetRegion(name string)

SetRegion associates a region with this answer.

func (Answer) String

func (a Answer) String() string

func (*Answer) UnmarshalJSON

func (a *Answer) UnmarshalJSON(data []byte) error

UnmarshalJSON parses responses to Answer and attempts to convert Rdata elements to string.

type Delegation

type Delegation struct {
	DNSKey []*Key `json:"dnskey,omitempty"`
	DS     []*Key `json:"ds,omitempty"`
	TTL    int    `json:"ttl,omitempty"`
}

Delegation holds a list of DNS Keys, a list of DS Keys, and a TTL

type Key

type Key struct {
	Flags     string
	Protocol  string
	Algorithm string
	PublicKey string
}

Key holds a DNS key

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(buf []byte) error

UnmarshalJSON parses a Key from a list into a struct

type Keys

type Keys struct {
	DNSKey []*Key `json:"dnskey,omitempty"`
	TTL    int    `json:"ttl,omitempty"`
}

Keys holds a list of DNS Keys and a TTL

type Network added in v2.7.4

type Network struct {
	Label     string `json:"label"`
	Name      string `json:"name"`
	NetworkID int    `json:"network_id"`
}

Network wraps an NS1 networks/ resource

type Record

type Record struct {
	Meta *data.Meta `json:"meta,omitempty"`

	ID                     string `json:"id,omitempty"`
	Zone                   string `json:"zone"`
	Domain                 string `json:"domain"`
	Type                   string `json:"type"`
	Link                   string `json:"link,omitempty"`
	TTL                    int    `json:"ttl,omitempty"`
	OverrideTTL            *bool  `json:"override_ttl,omitempty"`
	OverrideAddressRecords *bool  `json:"override_address_records,omitempty"`
	UseClientSubnet        *bool  `json:"use_client_subnet,omitempty"`

	// Answers must all be of the same type as the record.
	Answers []*Answer `json:"answers"`
	// The records' filter chain.
	Filters []*filter.Filter `json:"filters"`
	// The records' regions.
	Regions data.Regions `json:"regions,omitempty"`

	// Contains the key/value tag information associated to the record
	Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI

	// List of tag key names that should not inherit from the parent zone
	BlockedTags []string `json:"blocked_tags,omitempty"` //Only relevant for DDI

	// Read-only fields
	LocalTags []string `json:"local_tags,omitempty"` // Only relevant for DDI
}

Record wraps an NS1 /zone/{zone}/{domain}/{type} resource

Example
package main

import (
	"fmt"

	"gopkg.in/ns1/ns1-go.v2/rest/model/data"
	"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
	"gopkg.in/ns1/ns1-go.v2/rest/model/filter"
)

func main() {
	// Construct the A record
	record := dns.NewRecord("test.com", "a", "A")
	record.TTL = 300

	// Construct primary answer(higher priority)
	pAns := dns.NewAv4Answer("1.1.1.1")
	pAns.Meta.Priority = 1
	pAns.Meta.Up = data.FeedPtr{FeedID: "feed1_id"}

	// Construct secondary answer(lower priority)
	sAns := dns.NewAv4Answer("2.2.2.2")
	sAns.Meta.Priority = 2
	sAns.Meta.Up = data.FeedPtr{FeedID: "feed2_id"}

	// Add both answers to record
	record.AddAnswer(pAns)
	record.AddAnswer(sAns)

	// Construct and add both filters to the record(ORDER MATTERS)
	record.AddFilter(filter.NewUp())
	record.AddFilter(filter.NewSelFirstN(1))

	// Add region 'test' to record(set as down)
	record.Regions["test"] = data.Region{Meta: data.Meta{Up: false}}

	fmt.Println(record)
	fmt.Println(record.TTL)

	fmt.Println("Primary answer:")
	fmt.Println(record.Answers[0])
	fmt.Println(record.Answers[0].Meta.Priority)
	fmt.Println(record.Answers[0].Meta.Up)

	fmt.Println("Secondary answer:")
	fmt.Println(record.Answers[1])
	fmt.Println(record.Answers[1].Meta.Priority)
	fmt.Println(record.Answers[1].Meta.Up)

	fmt.Println("First Filter in Chain:")
	fmt.Println(record.Filters[0].Type)
	fmt.Println(record.Filters[0].Config)

	fmt.Println("Second Filter in Chain:")
	fmt.Println(record.Filters[1].Type)
	fmt.Println(record.Filters[1].Config)

	fmt.Println("Regions:")
	fmt.Println(record.Regions["test"].Meta.Up)

}
Output:

a.test.com A
300
Primary answer:
1.1.1.1
1
{feed1_id}
Secondary answer:
2.2.2.2
2
{feed2_id}
First Filter in Chain:
up
map[]
Second Filter in Chain:
select_first_n
map[N:1]
Regions:
false

func NewRecord

func NewRecord(zone string, domain string, t string) *Record

NewRecord takes a zone, domain and record type t and creates a *Record with UseClientSubnet: true & empty Answers.

func (*Record) AddAnswer

func (r *Record) AddAnswer(ans *Answer)

AddAnswer adds an answer to the record.

func (*Record) AddFilter

func (r *Record) AddFilter(fil *filter.Filter)

AddFilter adds a filter to the records' filter chain(ordering of filters matters).

func (*Record) LinkTo

func (r *Record) LinkTo(to string)

LinkTo sets a Record Link to an FQDN. to is the FQDN of the target record whose config should be used. Does not have to be in the same zone.

Example
package main

import (
	"fmt"

	"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
)

func main() {
	// Construct the src record
	srcRecord := dns.NewRecord("test.com", "a", "A")
	srcRecord.TTL = 300
	srcRecord.Meta.Priority = 2

	linkedRecord := dns.NewRecord("test.com", "l", "A")
	linkedRecord.LinkTo(srcRecord.Domain)
	fmt.Println(linkedRecord)
	fmt.Println(linkedRecord.Meta)
	fmt.Println(linkedRecord.Answers)
}
Output:

l.test.com A
<nil>
[]

func (*Record) MarshalJSON

func (r *Record) MarshalJSON() ([]byte, error)

MarshalJSON attempts to convert any Rdata elements that cannot be passed as strings to the API to their correct type.

func (*Record) String

func (r *Record) String() string

String returns the domain rtype in string format of record

type SearchResult added in v2.7.7

type SearchResult struct {
	Next         string    `json:"next"`
	Limit        int       `json:"limit"`
	TotalResults int       `json:"total_results"`
	Results      []*Record `json:"results"`
}

type TSIG

type TSIG struct {
	// Key is the encrypted TSIG key(read-only)
	Key string `json:"key,omitempty"`

	// Whether TSIG is enabled for a secondary zone.
	Enabled bool `json:"enabled,omitempty"`
	// Which hashing algorithm
	Hash string `json:"hash,omitempty"`
	// Name of the TSIG key
	Name string `json:"name,omitempty"`
}

TSIG is a zones transaction signature.

type TSIGKey

type TSIGKey struct {
	Name      string `json:"name,omitempty"`
	Algorithm string `json:"algorithm,omitempty"`
	Secret    string `json:"secret,omitempty"`
}

TSIGKey wraps an NS1 /tsig resource

func NewTsigKey

func NewTsigKey(name string, algorithm string, secret string) *TSIGKey

NewTsigKey takes a name, algorithm and secret and creates a new TSIG key.

type Version added in v2.7.7

type Version struct {
	Id          int    `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Active      bool   `json:"active,omitempty"`
	ActivatedAt int    `json:"activated_at,omitempty"`
	CreatedAt   int    `json:"created_at,omitempty"`
}

type View added in v2.7.6

type View struct {
	Name       string   `json:"name,omitempty"`
	CreatedAt  int      `json:"created_at,omitempty"`
	UpdatedAt  int      `json:"updated_at,omitempty"`
	ReadACLs   []string `json:"read_acls"`
	UpdateACLs []string `json:"update_acls"`
	Zones      []string `json:"zones"`
	Networks   []int    `json:"networks"`
	Preference int      `json:"preference,omitempty"`
}

View wraps an NS1 views/ resource

func NewView added in v2.7.6

func NewView(viewName string) *View

NewView takes a viewName and creates a *DNSView

type Zone

type Zone struct {
	// Zones have metadata tables, but no filters act on 'zone-level' meta.
	Meta *data.Meta `json:"meta,omitempty"`

	// Read-only fields
	DNSServers   []string `json:"dns_servers,omitempty"`
	NetworkPools []string `json:"network_pools,omitempty"`
	Pool         string   `json:"pool,omitempty"`       // Deprecated
	LocalTags    []string `json:"local_tags,omitempty"` // Only relevant for DDI

	ID   string `json:"id,omitempty"`
	Zone string `json:"zone,omitempty"`

	TTL           int    `json:"ttl,omitempty"`
	NxTTL         int    `json:"nx_ttl,omitempty"`
	Retry         int    `json:"retry,omitempty"`
	Serial        int    `json:"serial,omitempty"`
	Refresh       int    `json:"refresh,omitempty"`
	Expiry        int    `json:"expiry,omitempty"`
	Hostmaster    string `json:"hostmaster,omitempty"`
	PrimaryMaster string `json:"primary_master,omitempty"`

	// If this is a linked zone, Link points to an existing standard zone,
	// reusing its configuration and records. Link is a zones' domain name.
	Link *string `json:"link,omitempty"`

	// Networks contains the network ids the zone is available. Most zones
	// will be in the NSONE Global Network(which is id 0).
	NetworkIDs []int         `json:"networks,omitempty"`
	Records    []*ZoneRecord `json:"records,omitempty"`

	// Primary contains info to enable slaving of the zone by third party dns servers.
	Primary *ZonePrimary `json:"primary,omitempty"`
	// Secondary contains info for slaving the zone to a primary dns server.
	Secondary *ZoneSecondary `json:"secondary,omitempty"`

	// Whether or not DNSSEC is enabled on the zone. Note we use a pointer so
	// leaving this unset will not change a previous setting.
	DNSSEC *bool `json:"dnssec,omitempty"`

	// Contains the key/value tag information associated to the zone
	Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI
}

Zone wraps an NS1 /zone resource

Example
package main

import (
	"fmt"

	"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
)

func main() {
	z := dns.NewZone("example.com")

	fmt.Println(z)
}
Output:

example.com

func NewZone

func NewZone(zone string) *Zone

NewZone takes a zone domain name and creates a new zone.

func (*Zone) LinkTo

func (z *Zone) LinkTo(to string)

LinkTo sets Link to a target zone domain name and unsets all other configuration properties. No other zone configuration properties (such as refresh, retry, etc) may be specified, since they are all pulled from the target zone. Linked zones, once created, cannot be configured at all and cannot have records added to them. They may only be deleted, which does not affect the target zone at all.

func (*Zone) MakePrimary

func (z *Zone) MakePrimary(secondaries ...ZoneSecondaryServer)

MakePrimary enables Primary, disables Secondary, and sets primary's Secondaries to all provided ZoneSecondaryServers

Example

Example references https://ns1.com/articles/primary-dns-with-ns1

package main

import (
	"encoding/json"
	"fmt"

	"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
)

func main() {
	// Secondary/slave dns server info.
	secondary := dns.ZoneSecondaryServer{
		IP:     "1.2.3.4",
		Port:   53,
		Notify: true,
	}

	// Construct the primary/master zone.
	domain := "masterzone.example"

	masterZone := dns.NewZone(domain)
	masterZone.MakePrimary(secondary)

	b, _ := json.MarshalIndent(masterZone, "", "  ")

	fmt.Println(string(b))
}
Output:

{
  "zone": "masterzone.example",
  "primary": {
    "enabled": true,
    "secondaries": [
      {
        "ip": "1.2.3.4",
        "port": 53,
        "notify": true
      }
    ]
  }
}

func (*Zone) MakeSecondary

func (z *Zone) MakeSecondary(ip string)

MakeSecondary enables Secondary, disables Primary, and sets secondary's Primary_ip to provided ip. Sets secondary's primary_port to default of 53.

func (Zone) String

func (z Zone) String() string

type ZoneDNSSEC

type ZoneDNSSEC struct {
	Zone       string      `json:"zone,omitempty"`
	Keys       *Keys       `json:"keys,omitempty"`
	Delegation *Delegation `json:"delegation,omitempty"`
}

ZoneDNSSEC wraps an NS1 /zone/{zone}/dnssec resource

func (ZoneDNSSEC) String

func (d ZoneDNSSEC) String() string

type ZonePrimary

type ZonePrimary struct {
	// Enabled determines whether AXFR queries (and optionally NOTIFY messages)
	// will be enabled for the zone.
	Enabled     bool                  `json:"enabled"`
	Secondaries []ZoneSecondaryServer `json:"secondaries"`
}

ZonePrimary wraps a Zone's "primary" attribute

type ZoneRecord

type ZoneRecord struct {
	Domain   string      `json:"domain,omitempty"`
	ID       string      `json:"id,omitempty"`
	Link     string      `json:"link,omitempty"`
	ShortAns []string    `json:"short_answers,omitempty"`
	Tier     json.Number `json:"tier,omitempty"`
	TTL      int         `json:"ttl,omitempty"`
	Type     string      `json:"type,omitempty"`

	// Contains the key/value tag information associated to the zone
	Tags map[string]string `json:"tags,omitempty"` // Only relevant for DDI

	// Read-only fields
	LocalTags []string `json:"local_tags,omitempty"` // Only relevant for DDI
}

ZoneRecord wraps Zone's "records" attribute

type ZoneSecondary

type ZoneSecondary struct {
	// Read-Only fields
	Expired bool    `json:"expired,omitempty"`
	LastXfr int     `json:"last_xfr,omitempty"`
	Status  string  `json:"status,omitempty"`
	Error   *string `json:"error"`

	PrimaryIP   string `json:"primary_ip,omitempty"`
	PrimaryPort int    `json:"primary_port,omitempty"`
	Enabled     bool   `json:"enabled"`

	OtherIPs      []string `json:"other_ips,omitempty"`
	OtherPorts    []int    `json:"other_ports,omitempty"`
	OtherNetworks []int    `json:"other_networks,omitempty"`

	TSIG *TSIG `json:"tsig,omitempty"`
}

ZoneSecondary wraps a Zone's "secondary" attribute

type ZoneSecondaryServer

type ZoneSecondaryServer struct {
	// Read-Only
	NetworkIDs []int `json:"networks,omitempty"`

	IP     string `json:"ip"`
	Port   int    `json:"port,omitempty"`
	Notify bool   `json:"notify"`
}

ZoneSecondaryServer wraps elements of a Zone's "primary.secondary" attribute

Jump to

Keyboard shortcuts

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