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

CHORE: linting (#2176)

This commit is contained in:
Tom Limoncelli
2023-03-15 18:35:34 -04:00
committed by GitHub
parent fb6a79ab6f
commit 81054e72c5
3 changed files with 23 additions and 14 deletions

View File

@ -34,19 +34,18 @@ var delimiterRegex = regexp.MustCompile(`(?m)^---\n`)
func parseFrontMatter(content string) (map[string]interface{}, string, error) { func parseFrontMatter(content string) (map[string]interface{}, string, error) {
delimiterIndices := delimiterRegex.FindAllStringIndex(content, 2) delimiterIndices := delimiterRegex.FindAllStringIndex(content, 2)
if len(delimiterIndices) > 0 { if len(delimiterIndices) < 1 {
startIndex := delimiterIndices[0][0] return nil, "", fmt.Errorf("failed to parse file. Remove it and try again")
endIndex := delimiterIndices[1][0]
yamlString := content[startIndex+4 : endIndex]
var frontMatter map[string]interface{}
err := yaml.Unmarshal([]byte(yamlString), &frontMatter)
if err != nil {
return nil, "", err
}
return frontMatter, content[endIndex+4:], nil
} else {
return nil, "", fmt.Errorf("Failed to parse file. Remove it and try again.")
} }
startIndex := delimiterIndices[0][0]
endIndex := delimiterIndices[1][0]
yamlString := content[startIndex+4 : endIndex]
var frontMatter map[string]interface{}
err := yaml.Unmarshal([]byte(yamlString), &frontMatter)
if err != nil {
return nil, "", err
}
return frontMatter, content[endIndex+4:], nil
} }
var returnTypes = map[string]string{ var returnTypes = map[string]string{

View File

@ -43,8 +43,11 @@ differencing engine, such as maps of which labels and RecordKeys
exist. exist.
*/ */
// ComparableFunc is a signature for functions used to generate a comparable
// blob for custom records and records with metadata.
type ComparableFunc func(*models.RecordConfig) string type ComparableFunc func(*models.RecordConfig) string
// CompareConfig stores a zone's records in a structure that makes comparing two zones convenient.
type CompareConfig struct { type CompareConfig struct {
// The primary data. Each record stored once, grouped by label then // The primary data. Each record stored once, grouped by label then
// by rType: // by rType:
@ -88,6 +91,7 @@ type targetConfig struct {
rec *models.RecordConfig // The RecordConfig itself. rec *models.RecordConfig // The RecordConfig itself.
} }
// NewCompareConfig creates a CompareConfig from a set of records and other data.
func NewCompareConfig(origin string, existing, desired models.Records, compFn ComparableFunc) *CompareConfig { func NewCompareConfig(origin string, existing, desired models.Records, compFn ComparableFunc) *CompareConfig {
cc := &CompareConfig{ cc := &CompareConfig{
existing: existing, existing: existing,
@ -101,14 +105,15 @@ func NewCompareConfig(origin string, existing, desired models.Records, compFn Co
} }
cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order. cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order.
cc.addRecords(desired, false) cc.addRecords(desired, false)
cc.VerifyCNAMEAssertions() cc.verifyCNAMEAssertions()
sort.Slice(cc.ldata, func(i, j int) bool { sort.Slice(cc.ldata, func(i, j int) bool {
return prettyzone.LabelLess(cc.ldata[i].label, cc.ldata[j].label) return prettyzone.LabelLess(cc.ldata[i].label, cc.ldata[j].label)
}) })
return cc return cc
} }
func (cc *CompareConfig) VerifyCNAMEAssertions() { // verifyCNAMEAssertions verifies assertions about CNAME updates ordering.
func (cc *CompareConfig) verifyCNAMEAssertions() {
// According to the RFCs if a label has a CNAME, it can not have any other // According to the RFCs if a label has a CNAME, it can not have any other
// records at that label... even other CNAMEs. Therefore, we need to be // records at that label... even other CNAMEs. Therefore, we need to be

View File

@ -13,8 +13,10 @@ import (
"github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/models"
) )
// Verb indicates the Change's type (create, delete, etc.)
type Verb int type Verb int
// CREATE and other verbs.
const ( const (
_ Verb = iota // Skip the first value of 0 _ Verb = iota // Skip the first value of 0
CREATE // Create a record/recordset/label where none existed before. CREATE // Create a record/recordset/label where none existed before.
@ -23,8 +25,11 @@ const (
REPORT // No change, but I have something to say! REPORT // No change, but I have something to say!
) )
// ChangeList is a list of Change
type ChangeList []Change type ChangeList []Change
// Change is an instruction to the provider. Generally if one properly executes
// all the changes, an "existing" zone will turn into the "desired" zone.
type Change struct { type Change struct {
Type Verb // Add, Change, Delete Type Verb // Add, Change, Delete