1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Tom Limoncelli
2020-03-10 16:53:17 -04:00
committed by GitHub
parent 24484f1e0c
commit 14e48b9b07
14 changed files with 30 additions and 21 deletions

View File

@ -137,7 +137,7 @@ func GetCerts(args GetCertsArgs) error {
if err != nil {
return err
}
errs := normalize.NormalizeAndValidateConfig(cfg)
errs := normalize.ValidateAndNormalizeConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors")
}

View File

@ -99,7 +99,7 @@ func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error {
if err != nil {
return err
}
errs := normalize.NormalizeAndValidateConfig(cfg)
errs := normalize.ValidateAndNormalizeConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors")
}

View File

@ -70,7 +70,7 @@ func PrintIR(args PrintIRArgs) error {
return err
}
if !args.Raw {
errs := normalize.NormalizeAndValidateConfig(cfg)
errs := normalize.ValidateAndNormalizeConfig(cfg)
if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors")
}

View File

@ -222,7 +222,7 @@ func runTests(t *testing.T, prv providers.DNSServiceProvider, domainName string,
for gIdx, group := range testGroups {
// Abide by -start -end flags
curGroup += 1
curGroup++
if curGroup < firstGroup || curGroup > lastGroup {
continue
}

View File

@ -4,6 +4,7 @@ import "fmt"
var dotwarned = map[string]bool{}
// WarnNameserverDot prints a warning about issue 491 never more than once.
func WarnNameserverDot(p, w string) {
if dotwarned[p] {
return

View File

@ -23,6 +23,7 @@ import (
acmelog "github.com/go-acme/lego/log"
)
// CertConfig describes a certificate's configuration.
type CertConfig struct {
CertName string `json:"cert_name"`
Names []string `json:"names"`
@ -30,6 +31,7 @@ type CertConfig struct {
MustStaple bool `json:"must_staple"`
}
// Client is an interface for systems that issue or renew certs.
type Client interface {
IssueOrRenewCert(config *CertConfig, renewUnder int, verbose bool) (bool, error)
}
@ -51,10 +53,13 @@ type certManager struct {
}
const (
// LetsEncryptLive is the endpoint for updates (production).
LetsEncryptLive = "https://acme-v02.api.letsencrypt.org/directory"
// LetsEncryptStage is the endpoint for the staging area.
LetsEncryptStage = "https://acme-staging-v02.api.letsencrypt.org/directory"
)
// New is a factory for acme clients.
func New(cfg *models.DNSConfig, directory string, email string, server string, notify notifications.Notifier) (Client, error) {
return commonNew(cfg, directoryStorage(directory), email, server, notify)
}
@ -82,6 +87,7 @@ func commonNew(cfg *models.DNSConfig, storage Storage, email string, server stri
return c, nil
}
// NewVault is a factory for new vaunt clients.
func NewVault(cfg *models.DNSConfig, vaultPath string, email string, server string, notify notifications.Notifier) (Client, error) {
storage, err := makeVaultStorage(vaultPath)
if err != nil {

View File

@ -29,7 +29,7 @@ func DetermineNameservers(dc *models.DomainConfig) ([]*models.Nameserver, error)
// Clean up the nameservers due to
// https://github.com/StackExchange/dnscontrol/issues/491
// In the far future, this warning will become a fatal error.
for i, _ := range nss {
for i := range nss {
if strings.HasSuffix(nss[i].Name, ".") {
models.WarnNameserverDot(dnsProvider.Name, fmt.Sprintf("DetermineNameservers (%s) (%s)", dc.Name, nss[i].Name))
nss[i].Name = strings.TrimSuffix(nss[i].Name, ".")

View File

@ -33,7 +33,7 @@ func TestImportTransform(t *testing.T) {
cfg := &models.DNSConfig{
Domains: []*models.DomainConfig{src, dst},
}
if errs := NormalizeAndValidateConfig(cfg); len(errs) != 0 {
if errs := ValidateAndNormalizeConfig(cfg); len(errs) != 0 {
for _, err := range errs {
t.Error(err)
}

View File

@ -268,8 +268,8 @@ type Warning struct {
error
}
// NormalizeAndValidateConfig performs and normalization and/or validation of the IR.
func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR.
func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
for _, domain := range config.Domains {
pTypes := []string{}
txtMultiDissenters := []string{}

View File

@ -210,7 +210,7 @@ func TestCAAValidation(t *testing.T) {
},
},
}
errs := NormalizeAndValidateConfig(config)
errs := ValidateAndNormalizeConfig(config)
if len(errs) != 1 {
t.Error("Expect error on invalid CAA but got none")
}
@ -277,7 +277,7 @@ func TestTLSAValidation(t *testing.T) {
},
},
}
errs := NormalizeAndValidateConfig(config)
errs := ValidateAndNormalizeConfig(config)
if len(errs) != 1 {
t.Error("Expect error on invalid TLSA but got none")
}

View File

@ -70,11 +70,12 @@ func WriteZoneFileRC(w io.Writer, records models.Records, origin string, default
return z.generateZoneFileHelper(w)
}
func PrettySort(records models.Records, origin string, defaultTTL uint32, comments []string) *zoneGenData {
// PrettySort sorts the records in a pretty order.
func PrettySort(records models.Records, origin string, defaultTTL uint32, comments []string) *ZoneGenData {
if defaultTTL == 0 {
defaultTTL = MostCommonTTL(records)
}
z := &zoneGenData{
z := &ZoneGenData{
Origin: origin + ".",
DefaultTTL: defaultTTL,
Comments: comments,
@ -90,7 +91,7 @@ func PrettySort(records models.Records, origin string, defaultTTL uint32, commen
}
// generateZoneFileHelper creates a pretty zonefile.
func (z *zoneGenData) generateZoneFileHelper(w io.Writer) error {
func (z *ZoneGenData) generateZoneFileHelper(w io.Writer) error {
nameShortPrevious := ""

View File

@ -12,16 +12,17 @@ import (
"github.com/StackExchange/dnscontrol/v2/models"
)
type zoneGenData struct {
// ZoneGenData is the configuration description for the zone generator.
type ZoneGenData struct {
Origin string
DefaultTTL uint32
Records models.Records
Comments []string
}
func (z *zoneGenData) Len() int { return len(z.Records) }
func (z *zoneGenData) Swap(i, j int) { z.Records[i], z.Records[j] = z.Records[j], z.Records[i] }
func (z *zoneGenData) Less(i, j int) bool {
func (z *ZoneGenData) Len() int { return len(z.Records) }
func (z *ZoneGenData) Swap(i, j int) { z.Records[i], z.Records[j] = z.Records[j], z.Records[i] }
func (z *ZoneGenData) Less(i, j int) bool {
a, b := z.Records[i], z.Records[j]
// Sort by name.

View File

@ -56,7 +56,7 @@ const (
// CanUseRoute53Alias indicates the provider support the specific R53_ALIAS records that only the Route53 provider supports
CanUseRoute53Alias
// CanGetZoe indicates the provider supports the get-zones subcommand.
// CanGetZones indicates the provider supports the get-zones subcommand.
CanGetZones
// CanUseAzureAlias indicates the provider support the specific Azure_ALIAS records that only the Azure provider supports

View File

@ -24,7 +24,7 @@ type DomainCreator interface {
EnsureDomainExists(domain string) error
}
// DomainLister should be implemented by providers that have the
// ZoneLister should be implemented by providers that have the
// ability to list the zones they manage. This facilitates using the
// "get-zones" command for "all" zones.
type ZoneLister interface {
@ -93,7 +93,7 @@ func (n None) GetNameservers(string) ([]*models.Nameserver, error) {
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (client None) GetZoneRecords(domain string) (models.Records, error) {
func (n None) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented")
// This enables the get-zones subcommand.
// Implement this by extracting the code from GetDomainCorrections into