Skip to content

Commit d6c1ed9

Browse files
authored
chore: adds a new generator to create dns_provider.go (#2305)
1 parent 895a953 commit d6c1ed9

File tree

13 files changed

+306
-152
lines changed

13 files changed

+306
-152
lines changed

.golangci.yml

Lines changed: 92 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
1-
run:
2-
timeout: 10m
1+
linters:
2+
enable-all: true
3+
disable:
4+
- gomnd # deprecated
5+
- cyclop # duplicate of gocyclo
6+
- sqlclosecheck # not relevant (SQL)
7+
- rowserrcheck # not relevant (SQL)
8+
- execinquery # not relevant (SQL)
9+
- lll
10+
- gosec
11+
- dupl # not relevant
12+
- prealloc # too many false-positive
13+
- bodyclose # too many false-positive
14+
- mnd
15+
- testpackage # not relevant
16+
- tparallel # not relevant
17+
- paralleltest # not relevant
18+
- nestif # too many false-positive
19+
- wrapcheck
20+
- err113 # not relevant
21+
- nlreturn # not relevant
22+
- wsl # not relevant
23+
- exhaustive # not relevant
24+
- exhaustruct # not relevant
25+
- makezero # not relevant
26+
- forbidigo
27+
- varnamelen # not relevant
28+
- nilnil # not relevant
29+
- ireturn # not relevant
30+
- contextcheck # too many false-positive
31+
- tenv # we already have a test "framework" to handle env vars
32+
- noctx
33+
- forcetypeassert
34+
- tagliatelle
35+
- errname
36+
- errchkjson
37+
- nonamedreturns
38+
- musttag # false-positive https://github.com/junk1tm/musttag/issues/17
39+
- gosmopolitan # not relevant
40+
- exportloopref # Useless with go1.22
41+
- canonicalheader # Can create side effects in the context of API clients
42+
- usestdlibvars # false-positive https://github.com/sashamelentyev/usestdlibvars/issues/96
343

444
linters-settings:
545
govet:
@@ -96,50 +136,18 @@ linters-settings:
96136
sprintf1: true
97137
strconcat: false
98138

99-
linters:
100-
enable-all: true
101-
disable:
102-
- gomnd # deprecated
103-
- cyclop # duplicate of gocyclo
104-
- sqlclosecheck # not relevant (SQL)
105-
- rowserrcheck # not relevant (SQL)
106-
- execinquery # not relevant (SQL)
107-
- lll
108-
- gosec
109-
- dupl # not relevant
110-
- prealloc # too many false-positive
111-
- bodyclose # too many false-positive
112-
- mnd
113-
- testpackage # not relevant
114-
- tparallel # not relevant
115-
- paralleltest # not relevant
116-
- nestif # too many false-positive
117-
- wrapcheck
118-
- err113 # not relevant
119-
- nlreturn # not relevant
120-
- wsl # not relevant
121-
- exhaustive # not relevant
122-
- exhaustruct # not relevant
123-
- makezero # not relevant
124-
- forbidigo
125-
- varnamelen # not relevant
126-
- nilnil # not relevant
127-
- ireturn # not relevant
128-
- contextcheck # too many false-positive
129-
- tenv # we already have a test "framework" to handle env vars
130-
- noctx
131-
- forcetypeassert
132-
- tagliatelle
133-
- errname
134-
- errchkjson
135-
- nonamedreturns
136-
- musttag # false-positive https://github.com/junk1tm/musttag/issues/17
137-
- gosmopolitan # not relevant
138-
- exportloopref # Useless with go1.22
139-
- canonicalheader # Can create side effects in the context of API clients
140-
- usestdlibvars # false-positive https://github.com/sashamelentyev/usestdlibvars/issues/96
139+
run:
140+
timeout: 10m
141+
142+
output:
143+
show-stats: true
144+
sort-results: true
145+
sort-order:
146+
- linter
147+
- file
141148

142149
issues:
150+
exclude-generated: strict
143151
exclude-use-default: false
144152
max-issues-per-linter: 0
145153
max-same-issues: 0
@@ -160,86 +168,96 @@ issues:
160168
- path: providers/dns/dns_providers.go
161169
linters:
162170
- gocyclo
163-
- path: providers/dns/gcloud/googlecloud_test.go
164-
text: 'string `(lego\.wtf|manhattan)` has (\d+) occurrences, make it a constant'
165-
- path: providers/dns/zoneee/zoneee_test.go
166-
text: 'string `(bar|foo)` has (\d+) occurrences, make it a constant'
167171
- path: certcrypto/crypto.go
168172
text: '(tlsFeatureExtensionOID|ocspMustStapleFeature) is a global variable'
173+
linters:
174+
- gochecknoglobals
169175
- path: challenge/dns01/nameserver.go
170176
text: '(defaultNameservers|recursiveNameservers|fqdnSoaCache|muFqdnSoaCache) is a global variable'
177+
linters:
178+
- gochecknoglobals
171179
- path: challenge/dns01/nameserver_.+.go
172180
text: 'dnsTimeout is a global variable'
181+
linters:
182+
- gochecknoglobals
173183
- path: challenge/dns01/nameserver_test.go
174184
text: 'findXByFqdnTestCases is a global variable'
185+
linters:
186+
- gochecknoglobals
175187
- path: challenge/http01/domain_matcher.go
176188
text: 'string `Host` has \d occurrences, make it a constant'
189+
linters:
190+
- goconst
177191
- path: challenge/http01/domain_matcher.go
178192
text: 'cyclomatic complexity \d+ of func `parseForwardedHeader` is high'
193+
linters:
194+
- gocyclo
179195
- path: challenge/http01/domain_matcher.go
180196
text: "Function 'parseForwardedHeader' has too many statements"
197+
linters:
198+
- funlen
181199
- path: challenge/tlsalpn01/tls_alpn_challenge.go
182200
text: 'idPeAcmeIdentifierV1 is a global variable'
201+
linters:
202+
- gochecknoglobals
183203
- path: log/logger.go
184204
text: 'Logger is a global variable'
205+
linters:
206+
- gochecknoglobals
185207
- path: 'e2e/(dnschallenge/)?[\d\w]+_test.go'
186208
text: load is a global variable
209+
linters:
210+
- gochecknoglobals
187211
- path: 'providers/dns/([\d\w]+/)*[\d\w]+_test.go'
188212
text: 'envTest is a global variable'
213+
linters:
214+
- gochecknoglobals
189215
- path: 'providers/http/([\d\w]+/)*[\d\w]+_test.go'
190216
text: 'envTest is a global variable'
217+
linters:
218+
- gochecknoglobals
191219
- path: providers/dns/namecheap/namecheap_test.go
192220
text: 'testCases is a global variable'
221+
linters:
222+
- gochecknoglobals
193223
- path: providers/dns/acmedns/acmedns_test.go
194224
text: 'egTestAccount is a global variable'
225+
linters:
226+
- gochecknoglobals
195227
- path: providers/http/memcached/memcached_test.go
196228
text: 'memcachedHosts is a global variable'
197-
- path: providers/dns/sakuracloud/client_test.go
198-
text: 'cyclomatic complexity 13 of func `(TestDNSProvider_cleanupTXTRecord_concurrent|TestDNSProvider_addTXTRecord_concurrent)` is high'
199-
- path: providers/dns/dns_providers.go
200-
text: "Function 'NewDNSChallengeProviderByName' has too many statements"
201-
- path: cmd/flags.go
202-
text: "Function 'CreateFlags' is too long"
203-
- path: certificate/certificates.go
204-
text: "Function 'GetOCSP' is too long"
205-
- path: providers/dns/otc/client.go
206-
text: "Function 'loginRequest' is too long"
207-
- path: providers/dns/gandi/gandi.go
208-
text: "Function 'Present' is too long"
229+
linters:
230+
- gochecknoglobals
209231
- path: cmd/zz_gen_cmd_dnshelp.go
210232
linters:
211233
- gocyclo
212234
- funlen
213235
- path: providers/dns/checkdomain/internal/types.go
214236
text: '`payed` is a misspelling of `paid`'
215-
- path: providers/dns/namecheap/namecheap_test.go
216-
text: 'cognitive complexity (\d+) of func `TestDNSProvider_getHosts` is high'
237+
linters:
238+
- misspell
217239
- path: platform/tester/env_test.go
218240
linters:
219241
- thelper
220242
- path: providers/dns/oraclecloud/oraclecloud_test.go
221243
text: 'SA1019: x509.EncryptPEMBlock has been deprecated since Go 1.16'
222-
- path: challenge/http01/domain_matcher.go
223-
text: 'yodaStyleExpr'
224-
- path: providers/dns/dns_providers.go
225-
text: 'Function name: NewDNSChallengeProviderByName,'
244+
linters:
245+
- staticcheck
226246
- path: providers/dns/sakuracloud/wrapper.go
227247
text: 'mu is a global variable'
228-
- path: providers/dns/hosttech/internal/client_test.go
229-
text: 'Duplicate words \(0\) found'
248+
linters:
249+
- gochecknoglobals
230250
- path: cmd/cmd_renew.go
231251
text: 'cyclomatic complexity \d+ of func `(renewForDomains|renewForCSR)` is high'
252+
linters:
253+
- gocyclo
232254
- path: providers/dns/cpanel/cpanel.go
233255
text: 'cyclomatic complexity 13 of func `\(\*DNSProvider\)\.CleanUp` is high'
256+
linters:
257+
- gocyclo
234258

235259
# Those elements have been replaced by non-exposed structures.
236260
- path: providers/dns/linode/linode_test.go
237261
linters:
238262
- staticcheck
239263
text: "SA1019: linodego\\.(DomainsPagedResponse|DomainRecordsPagedResponse) is deprecated"
240-
241-
output:
242-
sort-results: true
243-
sort-order:
244-
- linter
245-
- file

internal/dnsdocs/cli_help/generator.go renamed to internal/clihelp/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/urfave/cli/v2"
1515
)
1616

17-
const outputFile = "../../../docs/data/zz_cli_help.toml"
17+
const outputFile = "../../docs/data/zz_cli_help.toml"
1818

1919
const baseTemplate = `# THIS FILE IS AUTO-GENERATED. PLEASE DO NOT EDIT.
2020
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package descriptors
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/BurntSushi/toml"
8+
)
9+
10+
type Providers struct {
11+
Providers []Provider
12+
}
13+
14+
type Provider struct {
15+
Name string // Real name of the DNS provider
16+
Code string // DNS code
17+
Aliases []string // DNS code aliases (for compatibility/deprecation)
18+
Since string // First lego version
19+
URL string // DNS provider URL
20+
Description string // Provider summary
21+
Example string // CLI example
22+
Configuration *Configuration // Environment variables
23+
Links *Links // Links
24+
Additional string // Extra documentation
25+
GeneratedFrom string // Source file
26+
}
27+
28+
type Configuration struct {
29+
Credentials map[string]string
30+
Additional map[string]string
31+
}
32+
33+
type Links struct {
34+
API string
35+
GoClient string
36+
}
37+
38+
// GetProviderInformation extract provider information from TOML description files.
39+
func GetProviderInformation(root string) (*Providers, error) {
40+
models := &Providers{}
41+
42+
err := filepath.Walk(filepath.Join(root, "providers", "dns"), walker(root, models))
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
return models, nil
48+
}
49+
50+
func walker(root string, prs *Providers) func(string, os.FileInfo, error) error {
51+
return func(path string, _ os.FileInfo, err error) error {
52+
if err != nil {
53+
return err
54+
}
55+
56+
if filepath.Ext(path) != ".toml" {
57+
return nil
58+
}
59+
60+
m := Provider{}
61+
62+
m.GeneratedFrom, err = filepath.Rel(root, path)
63+
if err != nil {
64+
return err
65+
}
66+
67+
_, err = toml.DecodeFile(path, &m)
68+
if err != nil {
69+
return err
70+
}
71+
72+
prs.Providers = append(prs.Providers, m)
73+
74+
return nil
75+
}
76+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)