mirror of
https://github.com/go-acme/lego.git
synced 2025-01-03 07:19:39 +02:00
chore: adds a new generator to create dns_provider.go
(#2305)
This commit is contained in:
parent
895a953590
commit
d6c1ed9138
166
.golangci.yml
166
.golangci.yml
@ -1,5 +1,45 @@
|
|||||||
run:
|
linters:
|
||||||
timeout: 10m
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
- gomnd # deprecated
|
||||||
|
- cyclop # duplicate of gocyclo
|
||||||
|
- sqlclosecheck # not relevant (SQL)
|
||||||
|
- rowserrcheck # not relevant (SQL)
|
||||||
|
- execinquery # not relevant (SQL)
|
||||||
|
- lll
|
||||||
|
- gosec
|
||||||
|
- dupl # not relevant
|
||||||
|
- prealloc # too many false-positive
|
||||||
|
- bodyclose # too many false-positive
|
||||||
|
- mnd
|
||||||
|
- testpackage # not relevant
|
||||||
|
- tparallel # not relevant
|
||||||
|
- paralleltest # not relevant
|
||||||
|
- nestif # too many false-positive
|
||||||
|
- wrapcheck
|
||||||
|
- err113 # not relevant
|
||||||
|
- nlreturn # not relevant
|
||||||
|
- wsl # not relevant
|
||||||
|
- exhaustive # not relevant
|
||||||
|
- exhaustruct # not relevant
|
||||||
|
- makezero # not relevant
|
||||||
|
- forbidigo
|
||||||
|
- varnamelen # not relevant
|
||||||
|
- nilnil # not relevant
|
||||||
|
- ireturn # not relevant
|
||||||
|
- contextcheck # too many false-positive
|
||||||
|
- tenv # we already have a test "framework" to handle env vars
|
||||||
|
- noctx
|
||||||
|
- forcetypeassert
|
||||||
|
- tagliatelle
|
||||||
|
- errname
|
||||||
|
- errchkjson
|
||||||
|
- nonamedreturns
|
||||||
|
- musttag # false-positive https://github.com/junk1tm/musttag/issues/17
|
||||||
|
- gosmopolitan # not relevant
|
||||||
|
- exportloopref # Useless with go1.22
|
||||||
|
- canonicalheader # Can create side effects in the context of API clients
|
||||||
|
- usestdlibvars # false-positive https://github.com/sashamelentyev/usestdlibvars/issues/96
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
@ -96,50 +136,18 @@ linters-settings:
|
|||||||
sprintf1: true
|
sprintf1: true
|
||||||
strconcat: false
|
strconcat: false
|
||||||
|
|
||||||
linters:
|
run:
|
||||||
enable-all: true
|
timeout: 10m
|
||||||
disable:
|
|
||||||
- gomnd # deprecated
|
output:
|
||||||
- cyclop # duplicate of gocyclo
|
show-stats: true
|
||||||
- sqlclosecheck # not relevant (SQL)
|
sort-results: true
|
||||||
- rowserrcheck # not relevant (SQL)
|
sort-order:
|
||||||
- execinquery # not relevant (SQL)
|
- linter
|
||||||
- lll
|
- file
|
||||||
- gosec
|
|
||||||
- dupl # not relevant
|
|
||||||
- prealloc # too many false-positive
|
|
||||||
- bodyclose # too many false-positive
|
|
||||||
- mnd
|
|
||||||
- testpackage # not relevant
|
|
||||||
- tparallel # not relevant
|
|
||||||
- paralleltest # not relevant
|
|
||||||
- nestif # too many false-positive
|
|
||||||
- wrapcheck
|
|
||||||
- err113 # not relevant
|
|
||||||
- nlreturn # not relevant
|
|
||||||
- wsl # not relevant
|
|
||||||
- exhaustive # not relevant
|
|
||||||
- exhaustruct # not relevant
|
|
||||||
- makezero # not relevant
|
|
||||||
- forbidigo
|
|
||||||
- varnamelen # not relevant
|
|
||||||
- nilnil # not relevant
|
|
||||||
- ireturn # not relevant
|
|
||||||
- contextcheck # too many false-positive
|
|
||||||
- tenv # we already have a test "framework" to handle env vars
|
|
||||||
- noctx
|
|
||||||
- forcetypeassert
|
|
||||||
- tagliatelle
|
|
||||||
- errname
|
|
||||||
- errchkjson
|
|
||||||
- nonamedreturns
|
|
||||||
- musttag # false-positive https://github.com/junk1tm/musttag/issues/17
|
|
||||||
- gosmopolitan # not relevant
|
|
||||||
- exportloopref # Useless with go1.22
|
|
||||||
- canonicalheader # Can create side effects in the context of API clients
|
|
||||||
- usestdlibvars # false-positive https://github.com/sashamelentyev/usestdlibvars/issues/96
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
|
exclude-generated: strict
|
||||||
exclude-use-default: false
|
exclude-use-default: false
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
@ -160,86 +168,96 @@ issues:
|
|||||||
- path: providers/dns/dns_providers.go
|
- path: providers/dns/dns_providers.go
|
||||||
linters:
|
linters:
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- path: providers/dns/gcloud/googlecloud_test.go
|
|
||||||
text: 'string `(lego\.wtf|manhattan)` has (\d+) occurrences, make it a constant'
|
|
||||||
- path: providers/dns/zoneee/zoneee_test.go
|
|
||||||
text: 'string `(bar|foo)` has (\d+) occurrences, make it a constant'
|
|
||||||
- path: certcrypto/crypto.go
|
- path: certcrypto/crypto.go
|
||||||
text: '(tlsFeatureExtensionOID|ocspMustStapleFeature) is a global variable'
|
text: '(tlsFeatureExtensionOID|ocspMustStapleFeature) is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: challenge/dns01/nameserver.go
|
- path: challenge/dns01/nameserver.go
|
||||||
text: '(defaultNameservers|recursiveNameservers|fqdnSoaCache|muFqdnSoaCache) is a global variable'
|
text: '(defaultNameservers|recursiveNameservers|fqdnSoaCache|muFqdnSoaCache) is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: challenge/dns01/nameserver_.+.go
|
- path: challenge/dns01/nameserver_.+.go
|
||||||
text: 'dnsTimeout is a global variable'
|
text: 'dnsTimeout is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: challenge/dns01/nameserver_test.go
|
- path: challenge/dns01/nameserver_test.go
|
||||||
text: 'findXByFqdnTestCases is a global variable'
|
text: 'findXByFqdnTestCases is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: challenge/http01/domain_matcher.go
|
- path: challenge/http01/domain_matcher.go
|
||||||
text: 'string `Host` has \d occurrences, make it a constant'
|
text: 'string `Host` has \d occurrences, make it a constant'
|
||||||
|
linters:
|
||||||
|
- goconst
|
||||||
- path: challenge/http01/domain_matcher.go
|
- path: challenge/http01/domain_matcher.go
|
||||||
text: 'cyclomatic complexity \d+ of func `parseForwardedHeader` is high'
|
text: 'cyclomatic complexity \d+ of func `parseForwardedHeader` is high'
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
- path: challenge/http01/domain_matcher.go
|
- path: challenge/http01/domain_matcher.go
|
||||||
text: "Function 'parseForwardedHeader' has too many statements"
|
text: "Function 'parseForwardedHeader' has too many statements"
|
||||||
|
linters:
|
||||||
|
- funlen
|
||||||
- path: challenge/tlsalpn01/tls_alpn_challenge.go
|
- path: challenge/tlsalpn01/tls_alpn_challenge.go
|
||||||
text: 'idPeAcmeIdentifierV1 is a global variable'
|
text: 'idPeAcmeIdentifierV1 is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: log/logger.go
|
- path: log/logger.go
|
||||||
text: 'Logger is a global variable'
|
text: 'Logger is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: 'e2e/(dnschallenge/)?[\d\w]+_test.go'
|
- path: 'e2e/(dnschallenge/)?[\d\w]+_test.go'
|
||||||
text: load is a global variable
|
text: load is a global variable
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: 'providers/dns/([\d\w]+/)*[\d\w]+_test.go'
|
- path: 'providers/dns/([\d\w]+/)*[\d\w]+_test.go'
|
||||||
text: 'envTest is a global variable'
|
text: 'envTest is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: 'providers/http/([\d\w]+/)*[\d\w]+_test.go'
|
- path: 'providers/http/([\d\w]+/)*[\d\w]+_test.go'
|
||||||
text: 'envTest is a global variable'
|
text: 'envTest is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: providers/dns/namecheap/namecheap_test.go
|
- path: providers/dns/namecheap/namecheap_test.go
|
||||||
text: 'testCases is a global variable'
|
text: 'testCases is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: providers/dns/acmedns/acmedns_test.go
|
- path: providers/dns/acmedns/acmedns_test.go
|
||||||
text: 'egTestAccount is a global variable'
|
text: 'egTestAccount is a global variable'
|
||||||
|
linters:
|
||||||
|
- gochecknoglobals
|
||||||
- path: providers/http/memcached/memcached_test.go
|
- path: providers/http/memcached/memcached_test.go
|
||||||
text: 'memcachedHosts is a global variable'
|
text: 'memcachedHosts is a global variable'
|
||||||
- path: providers/dns/sakuracloud/client_test.go
|
linters:
|
||||||
text: 'cyclomatic complexity 13 of func `(TestDNSProvider_cleanupTXTRecord_concurrent|TestDNSProvider_addTXTRecord_concurrent)` is high'
|
- gochecknoglobals
|
||||||
- path: providers/dns/dns_providers.go
|
|
||||||
text: "Function 'NewDNSChallengeProviderByName' has too many statements"
|
|
||||||
- path: cmd/flags.go
|
|
||||||
text: "Function 'CreateFlags' is too long"
|
|
||||||
- path: certificate/certificates.go
|
|
||||||
text: "Function 'GetOCSP' is too long"
|
|
||||||
- path: providers/dns/otc/client.go
|
|
||||||
text: "Function 'loginRequest' is too long"
|
|
||||||
- path: providers/dns/gandi/gandi.go
|
|
||||||
text: "Function 'Present' is too long"
|
|
||||||
- path: cmd/zz_gen_cmd_dnshelp.go
|
- path: cmd/zz_gen_cmd_dnshelp.go
|
||||||
linters:
|
linters:
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- funlen
|
- funlen
|
||||||
- path: providers/dns/checkdomain/internal/types.go
|
- path: providers/dns/checkdomain/internal/types.go
|
||||||
text: '`payed` is a misspelling of `paid`'
|
text: '`payed` is a misspelling of `paid`'
|
||||||
- path: providers/dns/namecheap/namecheap_test.go
|
linters:
|
||||||
text: 'cognitive complexity (\d+) of func `TestDNSProvider_getHosts` is high'
|
- misspell
|
||||||
- path: platform/tester/env_test.go
|
- path: platform/tester/env_test.go
|
||||||
linters:
|
linters:
|
||||||
- thelper
|
- thelper
|
||||||
- path: providers/dns/oraclecloud/oraclecloud_test.go
|
- path: providers/dns/oraclecloud/oraclecloud_test.go
|
||||||
text: 'SA1019: x509.EncryptPEMBlock has been deprecated since Go 1.16'
|
text: 'SA1019: x509.EncryptPEMBlock has been deprecated since Go 1.16'
|
||||||
- path: challenge/http01/domain_matcher.go
|
linters:
|
||||||
text: 'yodaStyleExpr'
|
- staticcheck
|
||||||
- path: providers/dns/dns_providers.go
|
|
||||||
text: 'Function name: NewDNSChallengeProviderByName,'
|
|
||||||
- path: providers/dns/sakuracloud/wrapper.go
|
- path: providers/dns/sakuracloud/wrapper.go
|
||||||
text: 'mu is a global variable'
|
text: 'mu is a global variable'
|
||||||
- path: providers/dns/hosttech/internal/client_test.go
|
linters:
|
||||||
text: 'Duplicate words \(0\) found'
|
- gochecknoglobals
|
||||||
- path: cmd/cmd_renew.go
|
- path: cmd/cmd_renew.go
|
||||||
text: 'cyclomatic complexity \d+ of func `(renewForDomains|renewForCSR)` is high'
|
text: 'cyclomatic complexity \d+ of func `(renewForDomains|renewForCSR)` is high'
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
- path: providers/dns/cpanel/cpanel.go
|
- path: providers/dns/cpanel/cpanel.go
|
||||||
text: 'cyclomatic complexity 13 of func `\(\*DNSProvider\)\.CleanUp` is high'
|
text: 'cyclomatic complexity 13 of func `\(\*DNSProvider\)\.CleanUp` is high'
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
|
||||||
# Those elements have been replaced by non-exposed structures.
|
# Those elements have been replaced by non-exposed structures.
|
||||||
- path: providers/dns/linode/linode_test.go
|
- path: providers/dns/linode/linode_test.go
|
||||||
linters:
|
linters:
|
||||||
- staticcheck
|
- staticcheck
|
||||||
text: "SA1019: linodego\\.(DomainsPagedResponse|DomainRecordsPagedResponse) is deprecated"
|
text: "SA1019: linodego\\.(DomainsPagedResponse|DomainRecordsPagedResponse) is deprecated"
|
||||||
|
|
||||||
output:
|
|
||||||
sort-results: true
|
|
||||||
sort-order:
|
|
||||||
- linter
|
|
||||||
- file
|
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const outputFile = "../../../docs/data/zz_cli_help.toml"
|
const outputFile = "../../docs/data/zz_cli_help.toml"
|
||||||
|
|
||||||
const baseTemplate = `# THIS FILE IS AUTO-GENERATED. PLEASE DO NOT EDIT.
|
const baseTemplate = `# THIS FILE IS AUTO-GENERATED. PLEASE DO NOT EDIT.
|
||||||
|
|
76
internal/dns/descriptors/descriptors.go
Normal file
76
internal/dns/descriptors/descriptors.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package descriptors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Providers struct {
|
||||||
|
Providers []Provider
|
||||||
|
}
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
Name string // Real name of the DNS provider
|
||||||
|
Code string // DNS code
|
||||||
|
Aliases []string // DNS code aliases (for compatibility/deprecation)
|
||||||
|
Since string // First lego version
|
||||||
|
URL string // DNS provider URL
|
||||||
|
Description string // Provider summary
|
||||||
|
Example string // CLI example
|
||||||
|
Configuration *Configuration // Environment variables
|
||||||
|
Links *Links // Links
|
||||||
|
Additional string // Extra documentation
|
||||||
|
GeneratedFrom string // Source file
|
||||||
|
}
|
||||||
|
|
||||||
|
type Configuration struct {
|
||||||
|
Credentials map[string]string
|
||||||
|
Additional map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Links struct {
|
||||||
|
API string
|
||||||
|
GoClient string
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProviderInformation extract provider information from TOML description files.
|
||||||
|
func GetProviderInformation(root string) (*Providers, error) {
|
||||||
|
models := &Providers{}
|
||||||
|
|
||||||
|
err := filepath.Walk(filepath.Join(root, "providers", "dns"), walker(root, models))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return models, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func walker(root string, prs *Providers) func(string, os.FileInfo, error) error {
|
||||||
|
return func(path string, _ os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Ext(path) != ".toml" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m := Provider{}
|
||||||
|
|
||||||
|
m.GeneratedFrom, err = filepath.Rel(root, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = toml.DecodeFile(path, &m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
prs.Providers = append(prs.Providers, m)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
@ -16,14 +16,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/go-acme/lego/v4/internal/dns/descriptors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
root = "../../"
|
root = "../../../"
|
||||||
dnsPackage = root + "providers/dns"
|
|
||||||
mdTemplate = root + "internal/dnsdocs/dns.md.tmpl"
|
mdTemplate = root + "internal/dns/docs/dns.md.tmpl"
|
||||||
cliTemplate = root + "internal/dnsdocs/dns.go.tmpl"
|
cliTemplate = root + "internal/dns/docs/dns.go.tmpl"
|
||||||
cliOutput = root + "cmd/zz_gen_cmd_dnshelp.go"
|
cliOutput = root + "cmd/zz_gen_cmd_dnshelp.go"
|
||||||
docOutput = root + "docs/content/dns"
|
docOutput = root + "docs/content/dns"
|
||||||
readmePath = root + "README.md"
|
readmePath = root + "README.md"
|
||||||
@ -34,41 +34,20 @@ const (
|
|||||||
endLine = "<!-- END DNS PROVIDERS LIST -->"
|
endLine = "<!-- END DNS PROVIDERS LIST -->"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
|
||||||
Name string // Real name of the DNS provider
|
|
||||||
Code string // DNS code
|
|
||||||
Since string // First lego version
|
|
||||||
URL string // DNS provider URL
|
|
||||||
Description string // Provider summary
|
|
||||||
Example string // CLI example
|
|
||||||
Configuration *Configuration // Environment variables
|
|
||||||
Links *Links // Links
|
|
||||||
Additional string // Extra documentation
|
|
||||||
GeneratedFrom string // Source file
|
|
||||||
}
|
|
||||||
|
|
||||||
type Configuration struct {
|
|
||||||
Credentials map[string]string
|
|
||||||
Additional map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Links struct {
|
|
||||||
API string
|
|
||||||
GoClient string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Providers struct {
|
|
||||||
Providers []Model
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
models := &Providers{}
|
models, err := descriptors.GetProviderInformation(root)
|
||||||
|
|
||||||
err := filepath.Walk(dnsPackage, walker(models))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, m := range models.Providers {
|
||||||
|
// generate documentation
|
||||||
|
err = generateDocumentation(m)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// generate CLI help
|
// generate CLI help
|
||||||
err = generateCLIHelp(models)
|
err = generateCLIHelp(models)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,36 +63,7 @@ func main() {
|
|||||||
fmt.Printf("Documentation for %d DNS providers has been generated.\n", len(models.Providers)+1)
|
fmt.Printf("Documentation for %d DNS providers has been generated.\n", len(models.Providers)+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func walker(prs *Providers) func(string, os.FileInfo, error) error {
|
func generateDocumentation(m descriptors.Provider) error {
|
||||||
return func(path string, _ os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if filepath.Ext(path) == ".toml" {
|
|
||||||
m := Model{}
|
|
||||||
|
|
||||||
m.GeneratedFrom, err = filepath.Rel(root, path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := toml.DecodeFile(path, &m)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
prs.Providers = append(prs.Providers, m)
|
|
||||||
|
|
||||||
// generate documentation
|
|
||||||
return generateDocumentation(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateDocumentation(m Model) error {
|
|
||||||
filename := filepath.Join(docOutput, "zz_gen_"+m.Code+".md")
|
filename := filepath.Join(docOutput, "zz_gen_"+m.Code+".md")
|
||||||
|
|
||||||
file, err := os.Create(filename)
|
file, err := os.Create(filename)
|
||||||
@ -121,10 +71,12 @@ func generateDocumentation(m Model) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() { _ = file.Close() }()
|
||||||
|
|
||||||
return template.Must(template.ParseFiles(mdTemplate)).Execute(file, m)
|
return template.Must(template.ParseFiles(mdTemplate)).Execute(file, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateCLIHelp(models *Providers) error {
|
func generateCLIHelp(models *descriptors.Providers) error {
|
||||||
filename := filepath.Clean(cliOutput)
|
filename := filepath.Clean(cliOutput)
|
||||||
|
|
||||||
file, err := os.Create(filename)
|
file, err := os.Create(filename)
|
||||||
@ -132,6 +84,8 @@ func generateCLIHelp(models *Providers) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() { _ = file.Close() }()
|
||||||
|
|
||||||
tlt := template.New(filepath.Base(cliTemplate)).Funcs(map[string]interface{}{
|
tlt := template.New(filepath.Base(cliTemplate)).Funcs(map[string]interface{}{
|
||||||
"safe": func(src string) string {
|
"safe": func(src string) string {
|
||||||
return strings.ReplaceAll(src, "`", "'")
|
return strings.ReplaceAll(src, "`", "'")
|
||||||
@ -154,7 +108,7 @@ func generateCLIHelp(models *Providers) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateReadMe(models *Providers) error {
|
func generateReadMe(models *descriptors.Providers) error {
|
||||||
maximum, lines := extractTableData(models)
|
maximum, lines := extractTableData(models)
|
||||||
|
|
||||||
file, err := os.Open(readmePath)
|
file, err := os.Open(readmePath)
|
||||||
@ -203,7 +157,7 @@ func generateReadMe(models *Providers) error {
|
|||||||
return os.WriteFile(readmePath, buffer.Bytes(), 0o666)
|
return os.WriteFile(readmePath, buffer.Bytes(), 0o666)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractTableData(models *Providers) (int, [][]string) {
|
func extractTableData(models *descriptors.Providers) (int, [][]string) {
|
||||||
readmePattern := "[%s](https://go-acme.github.io/lego/dns/%s/)"
|
readmePattern := "[%s](https://go-acme.github.io/lego/dns/%s/)"
|
||||||
|
|
||||||
items := []string{fmt.Sprintf(readmePattern, "Manual", "manual")}
|
items := []string{fmt.Sprintf(readmePattern, "Manual", "manual")}
|
27
internal/dns/providers/dns_providers.go.tmpl
Normal file
27
internal/dns/providers/dns_providers.go.tmpl
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Code generated by 'make generate-dns'; DO NOT EDIT.
|
||||||
|
|
||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/go-acme/lego/v4/challenge"
|
||||||
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
|
{{- range $provider := .Providers }}
|
||||||
|
"github.com/go-acme/lego/v4/providers/dns/{{ cleanName $provider.Code }}"
|
||||||
|
{{- end}}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewDNSChallengeProviderByName Factory for DNS providers.
|
||||||
|
func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
||||||
|
switch name {
|
||||||
|
case "manual":
|
||||||
|
return dns01.NewDNSProviderManual()
|
||||||
|
{{- range $provider := .Providers }}
|
||||||
|
case "{{ $provider.Code }}"{{range $alias := $provider.Aliases }},"{{ $alias }}"{{end}}:
|
||||||
|
return {{ cleanName $provider.Code }}.NewDNSProvider()
|
||||||
|
{{- end}}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unrecognized DNS provider: %s", name)
|
||||||
|
}
|
||||||
|
}
|
73
internal/dns/providers/generator.go
Normal file
73
internal/dns/providers/generator.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run .
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"go/format"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/go-acme/lego/v4/internal/dns/descriptors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
root = "../../../"
|
||||||
|
|
||||||
|
srcTemplate = "internal/dns/providers/dns_providers.go.tmpl"
|
||||||
|
outputPath = "providers/dns/zz_gen_dns_providers.go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := generate()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generate() error {
|
||||||
|
info, err := descriptors.GetProviderInformation(root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Create(filepath.Join(root, outputPath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() { _ = file.Close() }()
|
||||||
|
|
||||||
|
tmplFile := filepath.Join(root, srcTemplate)
|
||||||
|
|
||||||
|
tlt := template.New(filepath.Base(tmplFile)).Funcs(map[string]interface{}{
|
||||||
|
"cleanName": func(src string) string {
|
||||||
|
return strings.ReplaceAll(src, "-", "")
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
b := &bytes.Buffer{}
|
||||||
|
err = template.Must(tlt.ParseFiles(tmplFile)).Execute(b, info)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// gofmt
|
||||||
|
source, err := format.Source(b.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = file.Write(source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Switch mapping for %d DNS providers has been generated.\n", len(info.Providers)+1)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -2,6 +2,7 @@ Name = "Joohoi's ACME-DNS"
|
|||||||
Description = ''''''
|
Description = ''''''
|
||||||
URL = "https://github.com/joohoi/acme-dns"
|
URL = "https://github.com/joohoi/acme-dns"
|
||||||
Code = "acme-dns"
|
Code = "acme-dns"
|
||||||
|
Aliases = ["acmedns"] # TODO(ldez): remove "-" in v5
|
||||||
Since = "v1.1.0"
|
Since = "v1.1.0"
|
||||||
|
|
||||||
Example = '''
|
Example = '''
|
||||||
|
@ -2,6 +2,7 @@ Name = "Domeneshop"
|
|||||||
Description = ''''''
|
Description = ''''''
|
||||||
URL = "https://domene.shop"
|
URL = "https://domene.shop"
|
||||||
Code = "domeneshop"
|
Code = "domeneshop"
|
||||||
|
Aliases = ["domainnameshop"]
|
||||||
Since = "v4.3.0"
|
Since = "v4.3.0"
|
||||||
|
|
||||||
Example = '''
|
Example = '''
|
||||||
|
@ -4,6 +4,7 @@ Akamai edgedns supersedes FastDNS; implementing a DNS provider for solving the D
|
|||||||
'''
|
'''
|
||||||
URL = "https://www.akamai.com/us/en/products/security/edge-dns.jsp"
|
URL = "https://www.akamai.com/us/en/products/security/edge-dns.jsp"
|
||||||
Code = "edgedns"
|
Code = "edgedns"
|
||||||
|
Aliases = ["fastdns"] # "fastdns" is for compatibility with v3, must be dropped in v5
|
||||||
Since = "v3.9.0"
|
Since = "v3.9.0"
|
||||||
|
|
||||||
Example = '''
|
Example = '''
|
||||||
|
@ -2,6 +2,7 @@ Name = "Linode (v4)"
|
|||||||
Description = ''''''
|
Description = ''''''
|
||||||
URL = "https://www.linode.com/"
|
URL = "https://www.linode.com/"
|
||||||
Code = "linode"
|
Code = "linode"
|
||||||
|
Aliases = ["linodev4"] # "linodev4" is for compatibility with v3, must be dropped in v5
|
||||||
Since = "v1.1.0"
|
Since = "v1.1.0"
|
||||||
|
|
||||||
Example = '''
|
Example = '''
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// Code generated by 'make generate-dns'; DO NOT EDIT.
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -148,7 +150,9 @@ import (
|
|||||||
// NewDNSChallengeProviderByName Factory for DNS providers.
|
// NewDNSChallengeProviderByName Factory for DNS providers.
|
||||||
func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
||||||
switch name {
|
switch name {
|
||||||
case "acme-dns": // TODO(ldez): remove "-" in v5
|
case "manual":
|
||||||
|
return dns01.NewDNSProviderManual()
|
||||||
|
case "acme-dns", "acmedns":
|
||||||
return acmedns.NewDNSProvider()
|
return acmedns.NewDNSProvider()
|
||||||
case "alidns":
|
case "alidns":
|
||||||
return alidns.NewDNSProvider()
|
return alidns.NewDNSProvider()
|
||||||
@ -156,14 +160,14 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||||||
return allinkl.NewDNSProvider()
|
return allinkl.NewDNSProvider()
|
||||||
case "arvancloud":
|
case "arvancloud":
|
||||||
return arvancloud.NewDNSProvider()
|
return arvancloud.NewDNSProvider()
|
||||||
case "azure":
|
|
||||||
return azure.NewDNSProvider()
|
|
||||||
case "azuredns":
|
|
||||||
return azuredns.NewDNSProvider()
|
|
||||||
case "auroradns":
|
case "auroradns":
|
||||||
return auroradns.NewDNSProvider()
|
return auroradns.NewDNSProvider()
|
||||||
case "autodns":
|
case "autodns":
|
||||||
return autodns.NewDNSProvider()
|
return autodns.NewDNSProvider()
|
||||||
|
case "azure":
|
||||||
|
return azure.NewDNSProvider()
|
||||||
|
case "azuredns":
|
||||||
|
return azuredns.NewDNSProvider()
|
||||||
case "bindman":
|
case "bindman":
|
||||||
return bindman.NewDNSProvider()
|
return bindman.NewDNSProvider()
|
||||||
case "bluecat":
|
case "bluecat":
|
||||||
@ -224,7 +228,7 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||||||
return dynu.NewDNSProvider()
|
return dynu.NewDNSProvider()
|
||||||
case "easydns":
|
case "easydns":
|
||||||
return easydns.NewDNSProvider()
|
return easydns.NewDNSProvider()
|
||||||
case "edgedns", "fastdns": // "fastdns" is for compatibility with v3, must be dropped in v5
|
case "edgedns", "fastdns":
|
||||||
return edgedns.NewDNSProvider()
|
return edgedns.NewDNSProvider()
|
||||||
case "efficientip":
|
case "efficientip":
|
||||||
return efficientip.NewDNSProvider()
|
return efficientip.NewDNSProvider()
|
||||||
@ -294,7 +298,7 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||||||
return lightsail.NewDNSProvider()
|
return lightsail.NewDNSProvider()
|
||||||
case "limacity":
|
case "limacity":
|
||||||
return limacity.NewDNSProvider()
|
return limacity.NewDNSProvider()
|
||||||
case "linode", "linodev4": // "linodev4" is for compatibility with v3, must be dropped in v5
|
case "linode", "linodev4":
|
||||||
return linode.NewDNSProvider()
|
return linode.NewDNSProvider()
|
||||||
case "liquidweb":
|
case "liquidweb":
|
||||||
return liquidweb.NewDNSProvider()
|
return liquidweb.NewDNSProvider()
|
||||||
@ -304,8 +308,6 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
|
|||||||
return luadns.NewDNSProvider()
|
return luadns.NewDNSProvider()
|
||||||
case "mailinabox":
|
case "mailinabox":
|
||||||
return mailinabox.NewDNSProvider()
|
return mailinabox.NewDNSProvider()
|
||||||
case "manual":
|
|
||||||
return dns01.NewDNSProviderManual()
|
|
||||||
case "metaname":
|
case "metaname":
|
||||||
return metaname.NewDNSProvider()
|
return metaname.NewDNSProvider()
|
||||||
case "mijnhost":
|
case "mijnhost":
|
Loading…
Reference in New Issue
Block a user