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,6 +15,7 @@ import (
// RecordConfig stores a DNS record. // RecordConfig stores a DNS record.
// Valid types: // Valid types:
//
// Official: (alphabetical) // Official: (alphabetical)
// A // A
// AAAA // AAAA
@ -50,31 +51,38 @@ import (
// Notes about the fields: // Notes about the fields:
// //
// Name: // Name:
//
// This is the shortname i.e. the NameFQDN without the origin suffix. // This is the shortname i.e. the NameFQDN without the origin suffix.
// It should never have a trailing "." // It should never have a trailing "."
// It should never be null. The apex (naked domain) is stored as "@". // It should never be null. The apex (naked domain) is stored as "@".
// If the origin is "foo.com." and Name is "foo.com", this literally means // 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) // the intended FQDN is "foo.com.foo.com." (which may look odd)
//
// NameFQDN: // NameFQDN:
//
// This is the FQDN version of Name. // This is the FQDN version of Name.
// It should never have a trailing ".". // It should never have a trailing ".".
// NOTE: Eventually we will unexport Name/NameFQDN. Please start using // NOTE: Eventually we will unexport Name/NameFQDN. Please start using
// the setters (SetLabel/SetLabelFromFQDN) and getters (GetLabel/GetLabelFQDN). // the setters (SetLabel/SetLabelFromFQDN) and getters (GetLabel/GetLabelFQDN).
// as they will always work. // as they will always work.
//
// target: // target:
//
// This is the host or IP address of the record, with // This is the host or IP address of the record, with
// the other related parameters (weight, priority, etc.) stored in individual // the other related parameters (weight, priority, etc.) stored in individual
// fields. // fields.
// NOTE: Eventually we will unexport Target. Please start using the // NOTE: Eventually we will unexport Target. Please start using the
// setters (SetTarget*) and getters (GetTarget*) as they will always work. // setters (SetTarget*) and getters (GetTarget*) as they will always work.
//
// SubDomain: // SubDomain:
//
// This is the subdomain path, if any, imported from the configuration. If // This is the subdomain path, if any, imported from the configuration. If
// present at the time of canonicalization it is inserted between the // present at the time of canonicalization it is inserted between the
// Name and origin when constructing a canonical (FQDN) target. // 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,9 +222,12 @@ 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 // maintains dc.Name without the trailig dot. Finding a dot here means
// something is very wrong. // 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) {
@ -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,6 +14,7 @@ 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 // var err error
// switch rType { // switch rType {
// case "MX": // case "MX":
@ -31,7 +32,6 @@ import (
// if err != nil { // if err != nil {
// return nil, fmt.Errorf("unparsable record received from CHANGE_TO_PROVDER_NAME: %w", err) // 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,6 +155,7 @@ 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" << 1 string
// "foo" "bar" << 2 strings // "foo" "bar" << 2 strings
@ -182,6 +183,7 @@ 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" << 1 string
// "foo" "bar" << 2 strings // "foo" "bar" << 2 strings
// foo << error. No quotes! Did you intend to use SetTargetTXT? // foo << error. No quotes! Did you intend to use SetTargetTXT?

View File

@ -1,6 +1,7 @@
// 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

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,6 +75,7 @@ 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. // 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. // This is done to make it easier to use the values at later points.
type domainNameShopRecord struct { type domainNameShopRecord struct {

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,6 +34,7 @@ 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{

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. // "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." // 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 // #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 // 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,6 +73,7 @@ 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: // label:
// type: A // type: A
// value: 1.2.3.4 // value: 1.2.3.4
@ -83,6 +84,7 @@ type simple struct {
} }
// Used to generate: // Used to generate:
//
// label: // label:
// type: A // type: A
// values: // values:
@ -102,6 +104,7 @@ 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: