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

Create a dynamic provider features matrix (#201)

* adding simple provider feature matrix generator

* filling out matrix

* clean output

* dead code

* explanatory text

* explanatory text

* typo

* move stuff around

* clean

* editing
This commit is contained in:
Craig Peterson
2017-09-14 16:13:17 -04:00
committed by GitHub
parent 6ce221df49
commit 3a90435357
21 changed files with 765 additions and 79 deletions

97
providers/capabilities.go Normal file
View File

@@ -0,0 +1,97 @@
package providers
import (
"log"
"strings"
)
//Capability is a bitmasked set of "features" that a provider supports. Only use constants from this package.
type Capability uint32
const (
// CanUseAlias indicates the provider support ALIAS records (or flattened CNAMES). Up to the provider to translate them to the appropriate record type.
// If you add something to this list, you probably want to add it to pkg/normalize/validate.go checkProviderCapabilities() or somewhere near there.
CanUseAlias Capability = iota
// CanUsePTR indicates the provider can handle PTR records
CanUsePTR
// CanUseSRV indicates the provider can handle SRV records
CanUseSRV
// CanUseCAA indicates the provider can handle CAA records
CanUseCAA
// CantUseNOPURGE indicates NO_PURGE is broken for this provider. To make it
// work would require complex emulation of an incremental update mechanism,
// so it is easier to simply mark this feature as not working for this
// provider.
CantUseNOPURGE
// DocOfficiallySupported means it is actively used and maintained by stack exchange
DocOfficiallySupported
// DocDualHost means provider allows full management of apex NS records, so we can safely dual-host with anothe provider
DocDualHost
// DocCreateDomains means provider can add domains with the `dnscontrol create-domains` command
DocCreateDomains
)
var providerCapabilities = map[string]map[Capability]bool{}
func ProviderHasCabability(pType string, cap Capability) bool {
if providerCapabilities[pType] == nil {
return false
}
return providerCapabilities[pType][cap]
}
// DocumentationNote is a way for providers to give more detail about what features they support.
type DocumentationNote struct {
HasFeature bool
Comment string
}
// DocumentationNotes is a full list of notes for a single provider
type DocumentationNotes map[Capability]*DocumentationNote
// ProviderMetadata is a common interface for DocumentationNotes and Capability to be used interchangably
type ProviderMetadata interface{}
// Notes is a collection of all documentation notes, keyed by provider type
var Notes = map[string]DocumentationNotes{}
func unwrapProviderCapabilities(pName string, meta []ProviderMetadata) {
for _, pm := range meta {
switch x := pm.(type) {
case Capability:
if providerCapabilities[pName] == nil {
providerCapabilities[pName] = map[Capability]bool{}
}
providerCapabilities[pName][x] = true
case DocumentationNotes:
if Notes[pName] == nil {
Notes[pName] = DocumentationNotes{}
}
for k, v := range x {
Notes[pName][k] = v
}
default:
log.Fatalf("Unrecognized ProviderMetadata type: %T", pm)
}
}
}
// Can is a small helper for concisely creating Documentation Notes
// comments are variadic for easy ommission, so you generally should pass 0 or 1 only.
func Can(comments ...string) *DocumentationNote {
return &DocumentationNote{
HasFeature: true,
Comment: strings.Join(comments, " "),
}
}
// Cannot is a small helper for concisely creating Documentation Notes
// comments are variadic for easy ommission, so you generally should pass 0 or 1 only.
func Cannot(comments ...string) *DocumentationNote {
return &DocumentationNote{
HasFeature: false,
Comment: strings.Join(comments, " "),
}
}