mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-09-20 06:46:19 +08:00
CHORE: linting (#2098)
This commit is contained in:
parent
4eab96226c
commit
169d7c8062
|
@ -2,6 +2,8 @@ package models
|
|||
|
||||
// Functions that make it easier to deal with a group of records.
|
||||
|
||||
// RecordDB is a container of many RecordConfig, queryable by various methods.
|
||||
// The first to be implemented is as a hash with label:type as the index.
|
||||
type RecordDB struct {
|
||||
labelAndTypeMap map[RecordKey]struct{}
|
||||
}
|
||||
|
@ -10,10 +12,8 @@ type RecordDB struct {
|
|||
func NewRecordDBFromRecords(recs Records, zone string) *RecordDB {
|
||||
result := &RecordDB{}
|
||||
|
||||
//fmt.Printf("DEBUG: BUILDING RecordDB: zone=%v\n", zone)
|
||||
result.labelAndTypeMap = make(map[RecordKey]struct{}, len(recs))
|
||||
for _, rec := range recs {
|
||||
//fmt.Printf(" DEBUG: Adding %+v\n", rec.Key())
|
||||
result.labelAndTypeMap[rec.Key()] = struct{}{}
|
||||
}
|
||||
//fmt.Printf("DEBUG: BUILDING RecordDB: DONE!\n")
|
||||
|
@ -25,6 +25,5 @@ func NewRecordDBFromRecords(recs Records, zone string) *RecordDB {
|
|||
// on the record's label and type (i.e. the RecordKey)
|
||||
func (recdb *RecordDB) ContainsLT(rec *RecordConfig) bool {
|
||||
_, ok := recdb.labelAndTypeMap[rec.Key()]
|
||||
//fmt.Printf("DEBUG: ContainsLT(%q) = %v (%v)\n", rec.Key(), ok, recdb)
|
||||
return ok
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ func ExecuteJavascript(file string, devMode bool, variables map[string]string) (
|
|||
return ExecuteJavascriptString(script, devMode, variables)
|
||||
}
|
||||
|
||||
// ExecuteJavascriptString accepts a string containing javascript and runs it, returning the resulting dnsConfig.
|
||||
func ExecuteJavascriptString(script []byte, devMode bool, variables map[string]string) (*models.DNSConfig, error) {
|
||||
|
||||
vm := otto.New()
|
||||
|
|
|
@ -548,7 +548,7 @@ func processSplitHorizonDomains(config *models.DNSConfig) error {
|
|||
|
||||
func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) {
|
||||
if dc.AutoDNSSEC == "on" {
|
||||
for providerName, _ := range dc.DNSProviderNames {
|
||||
for providerName := range dc.DNSProviderNames {
|
||||
if dc.RegistrarName != providerName {
|
||||
errs = append(errs, fmt.Errorf("AutoDNSSEC is enabled, but DNS provider %s does not match registrar %s", providerName, dc.RegistrarName))
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import "github.com/StackExchange/dnscontrol/v3/models"
|
|||
// a group of records.
|
||||
//
|
||||
|
||||
// RecordDB is a container of many model.RecordConfig
|
||||
type RecordDB = struct {
|
||||
labelAndTypeMap map[models.RecordKey]struct{}
|
||||
}
|
||||
|
||||
// NewFromRecords creates a RecordDB from a list of model.RecordConfig.
|
||||
func NewFromRecords(recs models.Records) *RecordDB {
|
||||
result := &RecordDB{}
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@ package soautil
|
|||
|
||||
import "strings"
|
||||
|
||||
// RFC5322MailToBind converts a user@host email address to BIND format.
|
||||
func RFC5322MailToBind(rfc5322Mail string) string {
|
||||
res := strings.SplitN(rfc5322Mail, "@", 2)
|
||||
user_part, domain_part := res[0], res[1]
|
||||
user, domain := res[0], res[1]
|
||||
// RFC-1035 [Section-8]
|
||||
user_part = strings.ReplaceAll(user_part, ".", "\\.")
|
||||
return user_part + "." + domain_part
|
||||
user = strings.ReplaceAll(user, ".", "\\.")
|
||||
return user + "." + domain
|
||||
}
|
||||
|
|
|
@ -181,6 +181,7 @@ func (c *bindProvider) GetZoneRecords(domain string) (models.Records, error) {
|
|||
return ParseZoneContents(string(content), domain, zonefileName)
|
||||
}
|
||||
|
||||
// ParseZoneContents parses a string as a BIND zone and returns the records.
|
||||
func ParseZoneContents(content string, zoneName string, zonefileName string) (models.Records, error) {
|
||||
zp := dns.NewZoneParser(strings.NewReader(content), zoneName, zonefileName)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ type gcoreRRSetExtended struct {
|
|||
Filters []dnssdk.RecordFilter `json:"filters"`
|
||||
}
|
||||
|
||||
func dnssdkDo(c *dnssdk.Client, apiKey string, ctx context.Context, method, uri string, bodyParams interface{}, dest interface{}) error {
|
||||
func dnssdkDo(ctx context.Context, c *dnssdk.Client, apiKey string, method, uri string, bodyParams interface{}, dest interface{}) error {
|
||||
// Adapted from https://github.com/G-Core/gcore-dns-sdk-go/blob/main/client.go#L289
|
||||
// No way to reflect a private method in Golang
|
||||
|
||||
|
@ -96,7 +96,7 @@ func (c *gcoreProvider) dnssdkRRSets(domain string) (gcoreRRSets, error) {
|
|||
var result gcoreRRSets
|
||||
url := fmt.Sprintf("/v2/zones/%s/rrsets?all=true", domain)
|
||||
|
||||
err := dnssdkDo(c.provider, c.apiKey, c.ctx, http.MethodGet, url, nil, &result)
|
||||
err := dnssdkDo(c.ctx, c.provider, c.apiKey, http.MethodGet, url, nil, &result)
|
||||
if err != nil {
|
||||
return gcoreRRSets{}, err
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const endpoint = "%s/api/%s/v1/json/%s"
|
|||
type hostingdeProvider struct {
|
||||
authToken string
|
||||
ownerAccountID string
|
||||
filterAccountId string
|
||||
filterAccountID string
|
||||
baseURL string
|
||||
nameservers []string
|
||||
defaultSoa soaValues
|
||||
|
@ -127,7 +127,7 @@ func (hp *hostingdeProvider) updateNameservers(nss []string, domain string) func
|
|||
}
|
||||
}
|
||||
|
||||
func (hp *hostingdeProvider) updateZone(zc *zoneConfig, DnsSecOptions *dnsSecOptions, create, del, mod diff.Changeset) error {
|
||||
func (hp *hostingdeProvider) updateZone(zc *zoneConfig, options *dnsSecOptions, create, del, mod diff.Changeset) error {
|
||||
toAdd := []*record{}
|
||||
for _, c := range create {
|
||||
r := recordToNative(c.Desired)
|
||||
|
@ -153,7 +153,7 @@ func (hp *hostingdeProvider) updateZone(zc *zoneConfig, DnsSecOptions *dnsSecOpt
|
|||
RecordsToAdd: toAdd,
|
||||
RecordsToDelete: toDelete,
|
||||
RecordsToModify: toModify,
|
||||
DNSSECOptions: DnsSecOptions,
|
||||
DNSSECOptions: options,
|
||||
}
|
||||
|
||||
_, err := hp.get("dns", "zoneUpdate", params)
|
||||
|
@ -223,11 +223,11 @@ func (hp *hostingdeProvider) getZoneConfig(domain string) (*zoneConfig, error) {
|
|||
return zc[0], nil
|
||||
}
|
||||
|
||||
func (hp *hostingdeProvider) getDNSSECOptions(zoneConfigId string) (*dnsSecOptions, error) {
|
||||
func (hp *hostingdeProvider) getDNSSECOptions(zoneConfigID string) (*dnsSecOptions, error) {
|
||||
params := request{
|
||||
Filter: &filter{
|
||||
Field: "zoneConfigId",
|
||||
Value: zoneConfigId,
|
||||
Value: zoneConfigID,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -301,10 +301,10 @@ func (hp *hostingdeProvider) getAllZoneConfigs() ([]*zoneConfig, error) {
|
|||
params := request{
|
||||
Limit: 10000,
|
||||
}
|
||||
if hp.filterAccountId != "" {
|
||||
if hp.filterAccountID != "" {
|
||||
params.Filter = &filter{
|
||||
Field: "accountId",
|
||||
Value: hp.filterAccountId,
|
||||
Value: hp.filterAccountID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ type providerMeta struct {
|
|||
}
|
||||
|
||||
func newHostingde(m map[string]string, providermeta json.RawMessage) (*hostingdeProvider, error) {
|
||||
authToken, ownerAccountID, filterAccountId, baseURL := m["authToken"], m["ownerAccountId"], m["filterAccountId"], m["baseURL"]
|
||||
authToken, ownerAccountID, filterAccountID, baseURL := m["authToken"], m["ownerAccountId"], m["filterAccountId"], m["baseURL"]
|
||||
|
||||
if authToken == "" {
|
||||
return nil, fmt.Errorf("hosting.de: authtoken must be provided")
|
||||
|
@ -61,7 +61,7 @@ func newHostingde(m map[string]string, providermeta json.RawMessage) (*hostingde
|
|||
hp := &hostingdeProvider{
|
||||
authToken: authToken,
|
||||
ownerAccountID: ownerAccountID,
|
||||
filterAccountId: filterAccountId,
|
||||
filterAccountID: filterAccountID,
|
||||
baseURL: baseURL,
|
||||
nameservers: defaultNameservers,
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ func (hp *hostingdeProvider) GetZoneRecords(domain string) (models.Records, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return hp.ApiRecordsToStandardRecordsModel(domain, zone.Records), nil
|
||||
return hp.APIRecordsToStandardRecordsModel(domain, zone.Records), nil
|
||||
}
|
||||
|
||||
func (hp *hostingdeProvider) ApiRecordsToStandardRecordsModel(domain string, src []record) models.Records {
|
||||
func (hp *hostingdeProvider) APIRecordsToStandardRecordsModel(domain string, src []record) models.Records {
|
||||
records := []*models.RecordConfig{}
|
||||
for _, r := range src {
|
||||
if r.Type == "SOA" {
|
||||
|
@ -138,7 +138,7 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
return nil, err
|
||||
}
|
||||
|
||||
records := hp.ApiRecordsToStandardRecordsModel(dc.Name, zone.Records)
|
||||
records := hp.APIRecordsToStandardRecordsModel(dc.Name, zone.Records)
|
||||
|
||||
var create, del, mod diff.Changeset
|
||||
if !diff2.EnableDiff2 {
|
||||
|
@ -203,7 +203,7 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
}
|
||||
|
||||
if desiredSoa.SoaMbox != "" {
|
||||
var desiredMail string = ""
|
||||
desiredMail := ""
|
||||
if desiredSoa.SoaMbox[len(desiredSoa.SoaMbox)-1] != '.' {
|
||||
desiredMail = desiredSoa.SoaMbox + "@" + dc.Name
|
||||
}
|
||||
|
@ -217,33 +217,33 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
existingAutoDNSSecEnabled := zone.ZoneConfig.DNSSECMode == "automatic"
|
||||
desiredAutoDNSSecEnabled := dc.AutoDNSSEC == "on"
|
||||
|
||||
var DnsSecOptions *dnsSecOptions
|
||||
var DNSSecOptions *dnsSecOptions
|
||||
var removeDNSSecEntries []dnsSecEntry
|
||||
|
||||
// ensure that publishKsk is set for domains with AutoDNSSec
|
||||
if existingAutoDNSSecEnabled && desiredAutoDNSSecEnabled {
|
||||
CurrentDnsSecOptions, err := hp.getDNSSECOptions(zone.ZoneConfig.ID)
|
||||
currentDNSSecOptions, err := hp.getDNSSECOptions(zone.ZoneConfig.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !CurrentDnsSecOptions.PublishKSK {
|
||||
if !currentDNSSecOptions.PublishKSK {
|
||||
msg = append(msg, "Enabling publishKsk for AutoDNSSec")
|
||||
DnsSecOptions = CurrentDnsSecOptions
|
||||
DnsSecOptions.PublishKSK = true
|
||||
DNSSecOptions = currentDNSSecOptions
|
||||
DNSSecOptions.PublishKSK = true
|
||||
zoneChanged = true
|
||||
}
|
||||
}
|
||||
|
||||
if !existingAutoDNSSecEnabled && desiredAutoDNSSecEnabled {
|
||||
msg = append(msg, "Enable AutoDNSSEC")
|
||||
DnsSecOptions = &dnsSecOptions{
|
||||
DNSSecOptions = &dnsSecOptions{
|
||||
NSECMode: "nsec3",
|
||||
PublishKSK: true,
|
||||
}
|
||||
zone.ZoneConfig.DNSSECMode = "automatic"
|
||||
zoneChanged = true
|
||||
} else if existingAutoDNSSecEnabled && !desiredAutoDNSSecEnabled {
|
||||
CurrentDnsSecOptions, err := hp.getDNSSECOptions(zone.ZoneConfig.ID)
|
||||
currentDNSSecOptions, err := hp.getDNSSECOptions(zone.ZoneConfig.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
return nil, err
|
||||
}
|
||||
for _, entry := range DomainConfig.DNSSecEntries {
|
||||
for _, autoDNSKey := range CurrentDnsSecOptions.Keys {
|
||||
for _, autoDNSKey := range currentDNSSecOptions.Keys {
|
||||
if entry.KeyData.PublicKey == autoDNSKey.KeyData.PublicKey {
|
||||
removeDNSSecEntries = append(removeDNSSecEntries, entry)
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
|||
Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")),
|
||||
F: func() error {
|
||||
for i := 0; i < 10; i++ {
|
||||
err := hp.updateZone(&zone.ZoneConfig, DnsSecOptions, create, del, mod)
|
||||
err := hp.updateZone(&zone.ZoneConfig, DNSSecOptions, create, del, mod)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue