Documentation ¶
Overview ¶
Package dns contains definitions for NS1 zones/records/answers/etc.
Index ¶
- type Alias
- type AliasAnswer
- type Answer
- func NewALIASAnswer(host string) *Answer
- func NewAnswer(rdata []string) *Answer
- func NewAv4Answer(host string) *Answer
- func NewAv6Answer(host string) *Answer
- func NewCAAAnswer(flag int, tag, value string) *Answer
- func NewCNAMEAnswer(name string) *Answer
- func NewDSAnswer(key string, algorithm string, t string, digest string) *Answer
- func NewMXAnswer(pri int, host string) *Answer
- func NewSRVAnswer(priority, weight, port int, target string) *Answer
- func NewTXTAnswer(text string) *Answer
- func NewURLFWDAnswer(from, to string, redirectType, pathForwardingMode, queryForwarding int) *Answer
- type Delegation
- type Key
- type Keys
- type Network
- type Record
- type SearchResult
- type TSIG
- type TSIGKey
- type Version
- type View
- type Zone
- type ZoneDNSSEC
- type ZonePrimary
- type ZoneRecord
- type ZoneSecondary
- type ZoneSecondaryServer
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 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 ¶
NewALIASAnswer creates an Answer for ALIAS record.
func NewAv4Answer ¶
NewAv4Answer creates an Answer for A record.
func NewAv6Answer ¶
NewAv6Answer creates an Answer for AAAA record.
func NewCAAAnswer ¶
NewCAAAnswer creates an Answer for a CAA record.
func NewCNAMEAnswer ¶
NewCNAMEAnswer creates an Answer for CNAME record.
func NewDSAnswer ¶
NewDSAnswer creates an Answer for DS record.
func NewMXAnswer ¶
NewMXAnswer creates an Answer for MX record.
func NewSRVAnswer ¶
NewSRVAnswer creates an Answer for SRV record.
func NewTXTAnswer ¶
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) UnmarshalJSON ¶
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 ¶
Key holds a DNS key
func (*Key) UnmarshalJSON ¶
UnmarshalJSON parses a Key from a list into a struct
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 ¶
NewRecord takes a zone, domain and record type t and creates a *Record with UseClientSubnet: true & empty Answers.
func (*Record) AddFilter ¶
AddFilter adds a filter to the records' filter chain(ordering of filters matters).
func (*Record) LinkTo ¶
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 ¶
MarshalJSON attempts to convert any Rdata elements that cannot be passed as strings to the API to their correct type.
type SearchResult ¶ added in v2.7.7
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
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
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 (*Zone) LinkTo ¶
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 ¶
MakeSecondary enables Secondary, disables Primary, and sets secondary's Primary_ip to provided ip. Sets secondary's primary_port to default of 53.
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