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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 30 additions and 21 deletions

View file

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

View file

@ -70,7 +70,7 @@ func PrintIR(args PrintIRArgs) error {
return err return err
} }
if !args.Raw { if !args.Raw {
errs := normalize.NormalizeAndValidateConfig(cfg) errs := normalize.ValidateAndNormalizeConfig(cfg)
if PrintValidationErrors(errs) { if PrintValidationErrors(errs) {
return fmt.Errorf("Exiting due to validation errors") 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 { for gIdx, group := range testGroups {
// Abide by -start -end flags // Abide by -start -end flags
curGroup += 1 curGroup++
if curGroup < firstGroup || curGroup > lastGroup { if curGroup < firstGroup || curGroup > lastGroup {
continue continue
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -210,7 +210,7 @@ func TestCAAValidation(t *testing.T) {
}, },
}, },
} }
errs := NormalizeAndValidateConfig(config) errs := ValidateAndNormalizeConfig(config)
if len(errs) != 1 { if len(errs) != 1 {
t.Error("Expect error on invalid CAA but got none") 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 { if len(errs) != 1 {
t.Error("Expect error on invalid TLSA but got none") 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) 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 { if defaultTTL == 0 {
defaultTTL = MostCommonTTL(records) defaultTTL = MostCommonTTL(records)
} }
z := &zoneGenData{ z := &ZoneGenData{
Origin: origin + ".", Origin: origin + ".",
DefaultTTL: defaultTTL, DefaultTTL: defaultTTL,
Comments: comments, Comments: comments,
@ -90,7 +91,7 @@ func PrettySort(records models.Records, origin string, defaultTTL uint32, commen
} }
// generateZoneFileHelper creates a pretty zonefile. // generateZoneFileHelper creates a pretty zonefile.
func (z *zoneGenData) generateZoneFileHelper(w io.Writer) error { func (z *ZoneGenData) generateZoneFileHelper(w io.Writer) error {
nameShortPrevious := "" nameShortPrevious := ""

View file

@ -12,16 +12,17 @@ import (
"github.com/StackExchange/dnscontrol/v2/models" "github.com/StackExchange/dnscontrol/v2/models"
) )
type zoneGenData struct { // ZoneGenData is the configuration description for the zone generator.
type ZoneGenData struct {
Origin string Origin string
DefaultTTL uint32 DefaultTTL uint32
Records models.Records Records models.Records
Comments []string Comments []string
} }
func (z *zoneGenData) Len() int { return len(z.Records) } 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) 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) Less(i, j int) bool {
a, b := z.Records[i], z.Records[j] a, b := z.Records[i], z.Records[j]
// Sort by name. // 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 indicates the provider support the specific R53_ALIAS records that only the Route53 provider supports
CanUseRoute53Alias CanUseRoute53Alias
// CanGetZoe indicates the provider supports the get-zones subcommand. // CanGetZones indicates the provider supports the get-zones subcommand.
CanGetZones CanGetZones
// CanUseAzureAlias indicates the provider support the specific Azure_ALIAS records that only the Azure provider supports // 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 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 // ability to list the zones they manage. This facilitates using the
// "get-zones" command for "all" zones. // "get-zones" command for "all" zones.
type ZoneLister interface { 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. // 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") return nil, fmt.Errorf("not implemented")
// This enables the get-zones subcommand. // This enables the get-zones subcommand.
// Implement this by extracting the code from GetDomainCorrections into // Implement this by extracting the code from GetDomainCorrections into