1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

gofmt -s -w

This commit is contained in:
Tom Limoncelli
2022-08-14 20:49:57 -04:00
parent ccb582b278
commit 1010138fb6
13 changed files with 135 additions and 112 deletions

View File

@ -526,7 +526,7 @@ func makeRec(name, target, typ string) *models.RecordConfig {
return r return r
} }
//func (r *models.RecordConfig) ttl(t uint32) *models.RecordConfig { // func (r *models.RecordConfig) ttl(t uint32) *models.RecordConfig {
func ttl(r *models.RecordConfig, t uint32) *models.RecordConfig { func ttl(r *models.RecordConfig, t uint32) *models.RecordConfig {
r.TTL = t r.TTL = t
return r return r

View File

@ -15,66 +15,74 @@ import (
// RecordConfig stores a DNS record. // RecordConfig stores a DNS record.
// Valid types: // Valid types:
// Official: (alphabetical) //
// A // Official: (alphabetical)
// AAAA // A
// ANAME // Technically not an official rtype yet. // AAAA
// CAA // ANAME // Technically not an official rtype yet.
// CNAME // CAA
// MX // CNAME
// NAPTR // MX
// NS // NAPTR
// PTR // NS
// SOA // PTR
// SRV // SOA
// SSHFP // SRV
// TLSA // SSHFP
// TXT // TLSA
// Pseudo-Types: (alphabetical) // TXT
// ALIAS // Pseudo-Types: (alphabetical)
// CF_REDIRECT // ALIAS
// CF_TEMP_REDIRECT // CF_REDIRECT
// CF_WORKER_ROUTE // CF_TEMP_REDIRECT
// CLOUDNS_WR // CF_WORKER_ROUTE
// FRAME // CLOUDNS_WR
// IMPORT_TRANSFORM // FRAME
// NAMESERVER // IMPORT_TRANSFORM
// NO_PURGE // NAMESERVER
// NS1_URLFWD // NO_PURGE
// PAGE_RULE // NS1_URLFWD
// PURGE // PAGE_RULE
// URL // PURGE
// URL301 // URL
// WORKER_ROUTE // URL301
// WORKER_ROUTE
// //
// Notes about the fields: // Notes about the fields:
// //
// Name: // Name:
// This is the shortname i.e. the NameFQDN without the origin suffix. //
// It should never have a trailing "." // This is the shortname i.e. the NameFQDN without the origin suffix.
// It should never be null. The apex (naked domain) is stored as "@". // It should never have a trailing "."
// If the origin is "foo.com." and Name is "foo.com", this literally means // It should never be null. The apex (naked domain) is stored as "@".
// the intended FQDN is "foo.com.foo.com." (which may look odd) // If the origin is "foo.com." and Name is "foo.com", this literally means
// the intended FQDN is "foo.com.foo.com." (which may look odd)
//
// NameFQDN: // NameFQDN:
// This is the FQDN version of Name. //
// It should never have a trailing ".". // This is the FQDN version of Name.
// NOTE: Eventually we will unexport Name/NameFQDN. Please start using // It should never have a trailing ".".
// the setters (SetLabel/SetLabelFromFQDN) and getters (GetLabel/GetLabelFQDN). // NOTE: Eventually we will unexport Name/NameFQDN. Please start using
// as they will always work. // the setters (SetLabel/SetLabelFromFQDN) and getters (GetLabel/GetLabelFQDN).
// as they will always work.
//
// target: // target:
// This is the host or IP address of the record, with //
// the other related parameters (weight, priority, etc.) stored in individual // This is the host or IP address of the record, with
// fields. // the other related parameters (weight, priority, etc.) stored in individual
// NOTE: Eventually we will unexport Target. Please start using the // fields.
// setters (SetTarget*) and getters (GetTarget*) as they will always work. // NOTE: Eventually we will unexport Target. Please start using the
// setters (SetTarget*) and getters (GetTarget*) as they will always work.
//
// SubDomain: // SubDomain:
// This is the subdomain path, if any, imported from the configuration. If //
// present at the time of canonicalization it is inserted between the // This is the subdomain path, if any, imported from the configuration. If
// Name and origin when constructing a canonical (FQDN) target. // present at the time of canonicalization it is inserted between the
// Name and origin when constructing a canonical (FQDN) target.
// //
// Idioms: // Idioms:
// rec.Label() == "@" // Is this record at the apex?
// //
// rec.Label() == "@" // Is this record at the apex?
type RecordConfig struct { type RecordConfig struct {
Type string `json:"type"` // All caps rtype name. Type string `json:"type"` // All caps rtype name.
Name string `json:"name"` // The short name. See above. Name string `json:"name"` // The short name. See above.
@ -214,10 +222,13 @@ func (rc *RecordConfig) Copy() (*RecordConfig, error) {
// SetLabel sets the .Name/.NameFQDN fields given a short name and origin. // SetLabel sets the .Name/.NameFQDN fields given a short name and origin.
// origin must not have a trailing dot: The entire code base // origin must not have a trailing dot: The entire code base
// maintains dc.Name without the trailig dot. Finding a dot here means //
// something is very wrong. // maintains dc.Name without the trailig dot. Finding a dot here means
// something is very wrong.
//
// short must not have a training dot: That would mean you have // short must not have a training dot: That would mean you have
// a FQDN, and shouldn't be using SetLabel(). Maybe SetLabelFromFQDN()? //
// a FQDN, and shouldn't be using SetLabel(). Maybe SetLabelFromFQDN()?
func (rc *RecordConfig) SetLabel(short, origin string) { func (rc *RecordConfig) SetLabel(short, origin string) {
// Assertions that make sure the function is being used correctly: // Assertions that make sure the function is being used correctly:
@ -277,7 +288,9 @@ func (rc *RecordConfig) SetLabelFromFQDN(fqdn, origin string) {
// GetLabel returns the shortname of the label associated with this RecordConfig. // GetLabel returns the shortname of the label associated with this RecordConfig.
// It will never end with "." // It will never end with "."
// It does not need further shortening (i.e. if it returns "foo.com" and the // It does not need further shortening (i.e. if it returns "foo.com" and the
// domain is "foo.com" then the FQDN is actually "foo.com.foo.com"). //
// domain is "foo.com" then the FQDN is actually "foo.com.foo.com").
//
// It will never be "" (the apex is returned as "@"). // It will never be "" (the apex is returned as "@").
func (rc *RecordConfig) GetLabel() string { func (rc *RecordConfig) GetLabel() string {
return rc.Name return rc.Name

View File

@ -14,24 +14,24 @@ import (
// //
// Recommended calling convention: Process the exceptions first, then use the // Recommended calling convention: Process the exceptions first, then use the
// function for everything else. // function for everything else.
// var err error
// switch rType {
// case "MX":
// // MX priority in a separate field.
// if err := rc.SetTargetMX(cr.Priority, target); err != nil {
// return nil, fmt.Errorf("unparsable MX record received from cloudflare: %w", err)
// }
// case "TXT":
// // TXT records are stored verbatim; no quoting/escaping to parse.
// err = rc.SetTargetTXT(target)
// // ProTip: Use rc.SetTargetTXTs(manystrings) if the API or parser returns a list of substrings.
// default:
// err = rec.PopulateFromString(rType, target, origin)
// }
// if err != nil {
// return nil, fmt.Errorf("unparsable record received from CHANGE_TO_PROVDER_NAME: %w", err)
// }
// //
// var err error
// switch rType {
// case "MX":
// // MX priority in a separate field.
// if err := rc.SetTargetMX(cr.Priority, target); err != nil {
// return nil, fmt.Errorf("unparsable MX record received from cloudflare: %w", err)
// }
// case "TXT":
// // TXT records are stored verbatim; no quoting/escaping to parse.
// err = rc.SetTargetTXT(target)
// // ProTip: Use rc.SetTargetTXTs(manystrings) if the API or parser returns a list of substrings.
// default:
// err = rec.PopulateFromString(rType, target, origin)
// }
// if err != nil {
// return nil, fmt.Errorf("unparsable record received from CHANGE_TO_PROVDER_NAME: %w", err)
// }
func (rc *RecordConfig) PopulateFromString(rtype, contents, origin string) error { func (rc *RecordConfig) PopulateFromString(rtype, contents, origin string) error {
if rc.Type != "" && rc.Type != rtype { if rc.Type != "" && rc.Type != rtype {
panic(fmt.Errorf("assertion failed: rtype already set (%s) (%s)", rtype, rc.Type)) panic(fmt.Errorf("assertion failed: rtype already set (%s) (%s)", rtype, rc.Type))

View File

@ -155,10 +155,11 @@ func (rc *RecordConfig) GetTargetTXTJoined() string {
// SetTargetTXTString is like SetTargetTXTs but accepts one big string, // SetTargetTXTString is like SetTargetTXTs but accepts one big string,
// which is parsed into individual strings. // which is parsed into individual strings.
// Ex: foo << 1 string // Ex: foo << 1 string
// foo bar << 1 string //
// "foo bar" << 1 string // foo bar << 1 string
// "foo" "bar" << 2 strings // "foo bar" << 1 string
// "f"oo" "bar" << 2 strings, one has a quote in it // "foo" "bar" << 2 strings
// "f"oo" "bar" << 2 strings, one has a quote in it
// //
// BUG: This function doesn't handle escaped quotes ("like \" this"). // BUG: This function doesn't handle escaped quotes ("like \" this").
// //
@ -182,9 +183,10 @@ func (rc *RecordConfig) SetTargetTXTString(s string) error {
// and sets .TxtStrings based on the result. // and sets .TxtStrings based on the result.
// Note: Most APIs do notThis is rarely used. Try using SetTargetTXT() first. // Note: Most APIs do notThis is rarely used. Try using SetTargetTXT() first.
// Ex: "foo" << 1 string // Ex: "foo" << 1 string
// "foo bar" << 1 string //
// "foo" "bar" << 2 strings // "foo bar" << 1 string
// foo << error. No quotes! Did you intend to use SetTargetTXT? // "foo" "bar" << 2 strings
// foo << error. No quotes! Did you intend to use SetTargetTXT?
func (rc *RecordConfig) SetTargetTXTfromRFC1035Quoted(s string) error { func (rc *RecordConfig) SetTargetTXTfromRFC1035Quoted(s string) error {
if s != "" && s[0] != '"' { if s != "" && s[0] != '"' {
// If you get this error, it is likely that you should use // If you get this error, it is likely that you should use

View File

@ -1,7 +1,8 @@
// Package credsfile provides functions for reading and parsing the provider credentials json file. // Package credsfile provides functions for reading and parsing the provider credentials json file.
// It cleans nonstandard json features (comments and trailing commas), as well as replaces environment variable placeholders with // It cleans nonstandard json features (comments and trailing commas), as well as replaces environment variable placeholders with
// their environment variable equivalents. To reference an environment variable in your json file, simply use values in this format: // their environment variable equivalents. To reference an environment variable in your json file, simply use values in this format:
// "key"="$ENV_VAR_NAME" //
// "key"="$ENV_VAR_NAME"
package credsfile package credsfile
import ( import (

View File

@ -210,7 +210,7 @@ func (c *cloudnsProvider) EnsureDomainExists(domain string) error {
return c.createDomain(domain) return c.createDomain(domain)
} }
//parses the ClouDNS format into our standard RecordConfig // parses the ClouDNS format into our standard RecordConfig
func toRc(domain string, r *domainRecord) *models.RecordConfig { func toRc(domain string, r *domainRecord) *models.RecordConfig {
ttl, _ := strconv.ParseUint(r.TTL, 10, 32) ttl, _ := strconv.ParseUint(r.TTL, 10, 32)
@ -269,7 +269,7 @@ func toRc(domain string, r *domainRecord) *models.RecordConfig {
return rc return rc
} }
//toReq takes a RecordConfig and turns it into the native format used by the API. // toReq takes a RecordConfig and turns it into the native format used by the API.
func toReq(rc *models.RecordConfig) (requestParams, error) { func toReq(rc *models.RecordConfig) (requestParams, error) {
req := requestParams{ req := requestParams{
"record-type": rc.Type, "record-type": rc.Type,

View File

@ -121,7 +121,7 @@ func (c *desecProvider) initializeDomainIndex() error {
return err return err
} }
//buildIndexFromResponse takes the bodyString from initializeDomainIndex and builds the domainIndex // buildIndexFromResponse takes the bodyString from initializeDomainIndex and builds the domainIndex
func (c *desecProvider) buildIndexFromResponse(bodyString []byte) error { func (c *desecProvider) buildIndexFromResponse(bodyString []byte) error {
if c.domainIndex == nil { if c.domainIndex == nil {
c.domainIndex = map[string]uint32{} c.domainIndex = map[string]uint32{}
@ -139,7 +139,7 @@ func (c *desecProvider) buildIndexFromResponse(bodyString []byte) error {
return nil return nil
} }
//Parses the Link Header into a map (https://github.com/desec-io/desec-tools/blob/master/fetch_zone.py#L13) // Parses the Link Header into a map (https://github.com/desec-io/desec-tools/blob/master/fetch_zone.py#L13)
func (c *desecProvider) convertLinks(links string) map[string]string { func (c *desecProvider) convertLinks(links string) map[string]string {
mapping := make(map[string]string) mapping := make(map[string]string)
printer.Debugf("Header: %s\n", links) printer.Debugf("Header: %s\n", links)
@ -204,7 +204,7 @@ func (c *desecProvider) getRecords(domain string) ([]resourceRecord, error) {
return rrsNew, nil return rrsNew, nil
} }
//generateRRSETfromResponse takes the response rrset api calls and returns []resourceRecord // generateRRSETfromResponse takes the response rrset api calls and returns []resourceRecord
func generateRRSETfromResponse(bodyString []byte) ([]resourceRecord, error) { func generateRRSETfromResponse(bodyString []byte) ([]resourceRecord, error) {
var rrs []rrResponse var rrs []rrResponse
var rrsNew []resourceRecord var rrsNew []resourceRecord
@ -245,7 +245,7 @@ func (c *desecProvider) createDomain(domain string) error {
return nil return nil
} }
//upsertRR will create or override the RRSet with the provided resource record. // upsertRR will create or override the RRSet with the provided resource record.
func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error { func (c *desecProvider) upsertRR(rr []resourceRecord, domain string) error {
endpoint := fmt.Sprintf("/domains/%s/rrsets/", domain) endpoint := fmt.Sprintf("/domains/%s/rrsets/", domain)
byt, _ := json.Marshal(rr) byt, _ := json.Marshal(rr)

View File

@ -75,8 +75,9 @@ type domainResponse struct {
} }
// The Actual fields are the values in the right format according to what is needed for RecordConfig. // The Actual fields are the values in the right format according to what is needed for RecordConfig.
// While the values without Actual are the values directly as received from the DomainNameShop API. //
// This is done to make it easier to use the values at later points. // While the values without Actual are the values directly as received from the DomainNameShop API.
// This is done to make it easier to use the values at later points.
type domainNameShopRecord struct { type domainNameShopRecord struct {
ID int `json:"id"` ID int `json:"id"`
Host string `json:"host"` Host string `json:"host"`

View File

@ -2,7 +2,7 @@ package hexonet
import "fmt" import "fmt"
//EnsureDomainExists returns an error // EnsureDomainExists returns an error
// * if access to dnszone is not allowed (not authorized) or // * if access to dnszone is not allowed (not authorized) or
// * if it doesn't exist and creating it fails // * if it doesn't exist and creating it fails
func (n *HXClient) EnsureDomainExists(domain string) error { func (n *HXClient) EnsureDomainExists(domain string) error {

View File

@ -34,7 +34,8 @@ var features = providers.DocumentationNotes{
} }
// Register with the dnscontrol system. // Register with the dnscontrol system.
// This establishes the name (all caps), and the function to call to initialize it. //
// This establishes the name (all caps), and the function to call to initialize it.
func init() { func init() {
fns := providers.DspFuncs{ fns := providers.DspFuncs{
Initializer: newDNS, Initializer: newDNS,

View File

@ -82,8 +82,10 @@ func splitDomain(domain string) (sld string, tld string) {
// namecheap has request limiting at unpublished limits // namecheap has request limiting at unpublished limits
// from support in SEP-2017: // from support in SEP-2017:
// "The limits for the API calls will be 20/Min, 700/Hour and 8000/Day for one user. //
// If you can limit the requests within these it should be fine." // "The limits for the API calls will be 20/Min, 700/Hour and 8000/Day for one user.
// If you can limit the requests within these it should be fine."
//
// this helper performs some api action, checks for rate limited response, and if so, enters a retry loop until it resolves // this helper performs some api action, checks for rate limited response, and if so, enters a retry loop until it resolves
// if you are consistently hitting this, you may have success asking their support to increase your account's limits. // if you are consistently hitting this, you may have success asking their support to increase your account's limits.
func doWithRetry(f func() error) { func doWithRetry(f func() error) {

View File

@ -98,9 +98,9 @@ func (n *nsone) GetZoneRecords(domain string) (models.Records, error) {
// GetZoneDNSSEC gets DNSSEC status for zone. Returns true for enabled, false for disabled // GetZoneDNSSEC gets DNSSEC status for zone. Returns true for enabled, false for disabled
// a domain in NS1 can be in 3 states: // a domain in NS1 can be in 3 states:
// 1) DNSSEC is enabled (returns true) // 1. DNSSEC is enabled (returns true)
// 2) DNSSEC is disabled (returns false) // 2. DNSSEC is disabled (returns false)
// 3) some error state (return false plus the error) // 3. some error state (return false plus the error)
func (n *nsone) GetZoneDNSSEC(domain string) (bool, error) { func (n *nsone) GetZoneDNSSEC(domain string) (bool, error) {
_, _, err := n.DNSSEC.Get(domain) _, _, err := n.DNSSEC.Get(domain)
@ -222,11 +222,11 @@ func (n *nsone) modify(recs models.Records, domain string) error {
// configureDNSSEC configures DNSSEC for a zone. Set 'enabled' to true to enable, false to disable. // configureDNSSEC configures DNSSEC for a zone. Set 'enabled' to true to enable, false to disable.
// There's a cornercase, in which DNSSEC is globally disabled for the account. // There's a cornercase, in which DNSSEC is globally disabled for the account.
// In that situation, enabling DNSSEC will always fail with: // In that situation, enabling DNSSEC will always fail with:
// #1: ENABLE DNSSEC //
// FAILURE! POST https://api.nsone.net/v1/zones/example.com: 400 DNSSEC support is not enabled for this account. Please contact support@ns1.com to enable it // #1: ENABLE DNSSEC
// FAILURE! POST https://api.nsone.net/v1/zones/example.com: 400 DNSSEC support is not enabled for this account. Please contact support@ns1.com to enable it
// //
// Unfortunately this is not detectable otherwise, so given that we have a nice error message, we just let this through. // Unfortunately this is not detectable otherwise, so given that we have a nice error message, we just let this through.
//
func (n *nsone) configureDNSSEC(domain string, enabled bool) error { func (n *nsone) configureDNSSEC(domain string, enabled bool) error {
z, _, err := n.Zones.Get(domain) z, _, err := n.Zones.Get(domain)
if err != nil { if err != nil {

View File

@ -73,9 +73,10 @@ func (z *genYamlData) genInterfaceList(w io.Writer) yaml.MapSlice {
// It may have a single (simple) or multiple (many) values. // It may have a single (simple) or multiple (many) values.
// Used to generate: // Used to generate:
// label: //
// type: A // label:
// value: 1.2.3.4 // type: A
// value: 1.2.3.4
type simple struct { type simple struct {
TTL uint32 `yaml:"ttl,omitempty"` TTL uint32 `yaml:"ttl,omitempty"`
Type string `yaml:"type"` Type string `yaml:"type"`
@ -83,11 +84,12 @@ type simple struct {
} }
// Used to generate: // Used to generate:
// label: //
// type: A // label:
// values: // type: A
// - 1.2.3.4 // values:
// - 2.3.4.5 // - 1.2.3.4
// - 2.3.4.5
type many struct { type many struct {
TTL uint32 `yaml:"ttl,omitempty"` TTL uint32 `yaml:"ttl,omitempty"`
Type string `yaml:"type"` Type string `yaml:"type"`
@ -102,17 +104,18 @@ type complexItems []interface{}
// 'thing': >> complexVals // 'thing': >> complexVals
// - type: CNAME // - type: CNAME
// value: newplace.example.com. << value // value: newplace.example.com. << value
//
// 'www': // 'www':
// - type: A // - type: A
// values: // values:
// - 1.2.3.4 << values // - 1.2.3.4 << values
// - 1.2.3.5 << values // - 1.2.3.5 << values
// - type: MX // - type: MX
// values: // values:
// - priority: 10 << fields // - priority: 10 << fields
// value: mx1.example.com. << fields // value: mx1.example.com. << fields
// - priority: 10 << fields // - priority: 10 << fields
// value: mx2.example.com. << fields // value: mx2.example.com. << fields
type complexVals struct { type complexVals struct {
TTL uint32 `yaml:"ttl,omitempty"` TTL uint32 `yaml:"ttl,omitempty"`
Type string `yaml:"type"` Type string `yaml:"type"`