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

View File

@@ -28,61 +28,33 @@ type DomainCreator interface {
//RegistrarInitializer is a function to create a registrar. Function will be passed the unprocessed json payload from the configuration file for the given provider.
type RegistrarInitializer func(map[string]string) (Registrar, error)
var registrarTypes = map[string]RegistrarInitializer{}
var RegistrarTypes = map[string]RegistrarInitializer{}
//DspInitializer is a function to create a DNS service provider. Function will be passed the unprocessed json payload from the configuration file for the given provider.
type DspInitializer func(map[string]string, json.RawMessage) (DNSServiceProvider, error)
var dspTypes = map[string]DspInitializer{}
var dspCapabilities = map[string]Capability{}
//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 = 1 << 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
)
func ProviderHasCabability(pType string, cap Capability) bool {
return dspCapabilities[pType]&cap != 0
}
var DNSProviderTypes = map[string]DspInitializer{}
//RegisterRegistrarType adds a registrar type to the registry by providing a suitable initialization function.
func RegisterRegistrarType(name string, init RegistrarInitializer) {
if _, ok := registrarTypes[name]; ok {
func RegisterRegistrarType(name string, init RegistrarInitializer, pm ...ProviderMetadata) {
if _, ok := RegistrarTypes[name]; ok {
log.Fatalf("Cannot register registrar type %s multiple times", name)
}
registrarTypes[name] = init
RegistrarTypes[name] = init
unwrapProviderCapabilities(name, pm)
}
//RegisterDomainServiceProviderType adds a dsp to the registry with the given initialization function.
func RegisterDomainServiceProviderType(name string, init DspInitializer, caps ...Capability) {
if _, ok := dspTypes[name]; ok {
func RegisterDomainServiceProviderType(name string, init DspInitializer, pm ...ProviderMetadata) {
if _, ok := DNSProviderTypes[name]; ok {
log.Fatalf("Cannot register registrar type %s multiple times", name)
}
var abilities Capability
for _, c := range caps {
abilities |= c
}
dspTypes[name] = init
dspCapabilities[name] = abilities
DNSProviderTypes[name] = init
unwrapProviderCapabilities(name, pm)
}
func createRegistrar(rType string, config map[string]string) (Registrar, error) {
initer, ok := registrarTypes[rType]
initer, ok := RegistrarTypes[rType]
if !ok {
return nil, fmt.Errorf("Registrar type %s not declared.", rType)
}
@@ -90,7 +62,7 @@ func createRegistrar(rType string, config map[string]string) (Registrar, error)
}
func CreateDNSProvider(dType string, config map[string]string, meta json.RawMessage) (DNSServiceProvider, error) {
initer, ok := dspTypes[dType]
initer, ok := DNSProviderTypes[dType]
if !ok {
return nil, fmt.Errorf("DSP type %s not declared", dType)
}