Skip to content

Commit 8afdc9d

Browse files
jakdeptldez
andauthored
liquidweb: detect zone automatically (#2031)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 2140e6b commit 8afdc9d

File tree

8 files changed

+469
-131
lines changed

8 files changed

+469
-131
lines changed

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,17 +1635,17 @@ func displayDNSHelp(w io.Writer, name string) error {
16351635
ew.writeln()
16361636

16371637
ew.writeln(`Credentials:`)
1638-
ew.writeln(` - "LIQUID_WEB_PASSWORD": Storm API Password`)
1639-
ew.writeln(` - "LIQUID_WEB_USERNAME": Storm API Username`)
1640-
ew.writeln(` - "LIQUID_WEB_ZONE": DNS Zone`)
1638+
ew.writeln(` - "LIQUID_WEB_PASSWORD": Liquid Web API Password`)
1639+
ew.writeln(` - "LIQUID_WEB_USERNAME": Liquid Web API Username`)
16411640
ew.writeln()
16421641

16431642
ew.writeln(`Additional Configuration:`)
16441643
ew.writeln(` - "LIQUID_WEB_HTTP_TIMEOUT": Maximum waiting time for the DNS records to be created (not verified)`)
16451644
ew.writeln(` - "LIQUID_WEB_POLLING_INTERVAL": Time between DNS propagation check`)
16461645
ew.writeln(` - "LIQUID_WEB_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
16471646
ew.writeln(` - "LIQUID_WEB_TTL": The TTL of the TXT record used for the DNS challenge`)
1648-
ew.writeln(` - "LIQUID_WEB_URL": Storm API endpoint`)
1647+
ew.writeln(` - "LIQUID_WEB_URL": Liquid Web API endpoint`)
1648+
ew.writeln(` - "LIQUID_WEB_ZONE": DNS Zone`)
16491649

16501650
ew.writeln()
16511651
ew.writeln(`More information: https://go-acme.github.io/lego/dns/liquidweb`)

docs/content/dns/zz_gen_liquidweb.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Here is an example bash command using the Liquid Web provider:
2828
```bash
2929
LIQUID_WEB_USERNAME=someuser \
3030
LIQUID_WEB_PASSWORD=somepass \
31-
LIQUID_WEB_ZONE=tacoman.com.net \
3231
lego --email [email protected] --dns liquidweb --domains my.example.org run
3332
```
3433

@@ -39,9 +38,8 @@ lego --email [email protected] --dns liquidweb --domains my.example.org run
3938

4039
| Environment Variable Name | Description |
4140
|-----------------------|-------------|
42-
| `LIQUID_WEB_PASSWORD` | Storm API Password |
43-
| `LIQUID_WEB_USERNAME` | Storm API Username |
44-
| `LIQUID_WEB_ZONE` | DNS Zone |
41+
| `LIQUID_WEB_PASSWORD` | Liquid Web API Password |
42+
| `LIQUID_WEB_USERNAME` | Liquid Web API Username |
4543

4644
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
4745
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
@@ -55,7 +53,8 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
5553
| `LIQUID_WEB_POLLING_INTERVAL` | Time between DNS propagation check |
5654
| `LIQUID_WEB_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
5755
| `LIQUID_WEB_TTL` | The TTL of the TXT record used for the DNS challenge |
58-
| `LIQUID_WEB_URL` | Storm API endpoint |
56+
| `LIQUID_WEB_URL` | Liquid Web API endpoint |
57+
| `LIQUID_WEB_ZONE` | DNS Zone |
5958

6059
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
6160
More information [here]({{< ref "dns#configuration-and-credentials" >}}).
@@ -65,7 +64,7 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}).
6564

6665
## More information
6766

68-
- [API documentation](https://cart.liquidweb.com/storm/api/docs/v1/)
67+
- [API documentation](https://api.liquidweb.com/docs/)
6968
- [Go client](https://github.com/liquidweb/liquidweb-go)
7069

7170
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ require (
4040
github.com/infobloxopen/infoblox-go-client v1.1.1
4141
github.com/labbsr0x/bindman-dns-webhook v1.0.2
4242
github.com/linode/linodego v1.17.2
43-
github.com/liquidweb/liquidweb-go v1.6.3
43+
github.com/liquidweb/liquidweb-go v1.6.4
4444
github.com/mattn/go-isatty v0.0.19
4545
github.com/miekg/dns v1.1.55
4646
github.com/mimuret/golang-iij-dpf v0.9.1
@@ -134,7 +134,6 @@ require (
134134
github.com/kolo/xmlrpc v0.0.0-20220921171641-a4b6fa1dd06b // indirect
135135
github.com/kylelemons/godebug v1.1.0 // indirect
136136
github.com/labbsr0x/goh v1.0.1 // indirect
137-
github.com/liquidweb/go-lwApi v0.0.5 // indirect
138137
github.com/liquidweb/liquidweb-cli v0.6.9 // indirect
139138
github.com/mitchellh/go-homedir v1.1.0 // indirect
140139
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,10 @@ github.com/lestrrat-go/option v1.0.0/go.mod h1:5ZHFbivi4xwXxhxY9XHDe2FHo6/Z7WWmt
386386
github.com/linode/linodego v1.17.2 h1:b32dj4662PGG5P9qVa6nBezccWdqgukndlMIuPGq1CQ=
387387
github.com/linode/linodego v1.17.2/go.mod h1:C2iyT3Vg2O2sPxkWka4XAQ5WSUtm5LmTZ3Adw43Ra7Q=
388388
github.com/liquidweb/go-lwApi v0.0.0-20190605172801-52a4864d2738/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
389-
github.com/liquidweb/go-lwApi v0.0.5 h1:CT4cdXzJXmo0bon298kS7NeSk+Gt8/UHpWBBol1NGCA=
390-
github.com/liquidweb/go-lwApi v0.0.5/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs=
391389
github.com/liquidweb/liquidweb-cli v0.6.9 h1:acbIvdRauiwbxIsOCEMXGwF75aSJDbDiyAWPjVnwoYM=
392390
github.com/liquidweb/liquidweb-cli v0.6.9/go.mod h1:cE1uvQ+x24NGUL75D0QagOFCG8Wdvmwu8aL9TLmA/eQ=
393-
github.com/liquidweb/liquidweb-go v1.6.3 h1:NVHvcnX3eb3BltiIoA+gLYn15nOpkYkdizOEYGSKrk4=
394-
github.com/liquidweb/liquidweb-go v1.6.3/go.mod h1:SuXXp+thr28LnjEw18AYtWwIbWMHSUiajPQs8T9c/Rc=
391+
github.com/liquidweb/liquidweb-go v1.6.4 h1:6S0m3hHSpiLqGD7AFSb7lH/W/qr1wx+tKil9fgIbjMc=
392+
github.com/liquidweb/liquidweb-go v1.6.4/go.mod h1:B934JPIIcdA+uTq2Nz5PgOtG6CuCaEvQKe/Ge/5GgZ4=
395393
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
396394
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
397395
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=

providers/dns/liquidweb/liquidweb.go

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ package liquidweb
44
import (
55
"errors"
66
"fmt"
7+
"sort"
78
"strconv"
9+
"strings"
810
"sync"
911
"time"
1012

@@ -14,7 +16,7 @@ import (
1416
"github.com/liquidweb/liquidweb-go/network"
1517
)
1618

17-
const defaultBaseURL = "https://api.stormondemand.com"
19+
const defaultBaseURL = "https://api.liquidweb.com"
1820

1921
// Environment variables names.
2022
const (
@@ -45,15 +47,13 @@ type Config struct {
4547

4648
// NewDefaultConfig returns a default configuration for the DNSProvider.
4749
func NewDefaultConfig() *Config {
48-
config := &Config{
50+
return &Config{
4951
BaseURL: defaultBaseURL,
5052
TTL: env.GetOrDefaultInt(EnvTTL, 300),
5153
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 2*time.Minute),
5254
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
5355
HTTPTimeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 1*time.Minute),
5456
}
55-
56-
return config
5757
}
5858

5959
// DNSProvider implements the challenge.Provider interface.
@@ -66,7 +66,7 @@ type DNSProvider struct {
6666

6767
// NewDNSProvider returns a DNSProvider instance configured for Liquid Web.
6868
func NewDNSProvider() (*DNSProvider, error) {
69-
values, err := env.Get(EnvUsername, EnvPassword, EnvZone)
69+
values, err := env.Get(EnvUsername, EnvPassword)
7070
if err != nil {
7171
return nil, fmt.Errorf("liquidweb: %w", err)
7272
}
@@ -75,7 +75,7 @@ func NewDNSProvider() (*DNSProvider, error) {
7575
config.BaseURL = env.GetOrFile(EnvURL)
7676
config.Username = values[EnvUsername]
7777
config.Password = values[EnvPassword]
78-
config.Zone = values[EnvZone]
78+
config.Zone = env.GetOrDefaultString(EnvZone, "")
7979

8080
return NewDNSProviderConfig(config)
8181
}
@@ -90,19 +90,6 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
9090
config.BaseURL = defaultBaseURL
9191
}
9292

93-
if config.Zone == "" {
94-
return nil, errors.New("liquidweb: zone is missing")
95-
}
96-
97-
if config.Username == "" {
98-
return nil, errors.New("liquidweb: username is missing")
99-
}
100-
101-
if config.Password == "" {
102-
return nil, errors.New("liquidweb: password is missing")
103-
}
104-
105-
// Initialize LW client.
10693
client, err := lw.NewAPI(config.Username, config.Password, config.BaseURL, int(config.HTTPTimeout.Seconds()))
10794
if err != nil {
10895
return nil, fmt.Errorf("liquidweb: could not create Liquid Web API client: %w", err)
@@ -133,6 +120,15 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
133120
TTL: d.config.TTL,
134121
}
135122

123+
if params.Zone == "" {
124+
bestZone, err := d.findZone(params.Name)
125+
if err != nil {
126+
return fmt.Errorf("liquidweb: %w", err)
127+
}
128+
129+
params.Zone = bestZone
130+
}
131+
136132
dnsEntry, err := d.client.NetworkDNS.Create(params)
137133
if err != nil {
138134
return fmt.Errorf("liquidweb: could not create TXT record: %w", err)
@@ -167,3 +163,31 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
167163

168164
return nil
169165
}
166+
167+
func (d *DNSProvider) findZone(domain string) (string, error) {
168+
zones, err := d.client.NetworkDNSZone.ListAll()
169+
if err != nil {
170+
return "", fmt.Errorf("failed to retrieve zones for account: %w", err)
171+
}
172+
173+
// filter the zones on the account to only ones that match
174+
var zs []network.DNSZone
175+
for _, item := range zones.Items {
176+
if strings.HasSuffix(domain, item.Name) {
177+
zs = append(zs, item)
178+
}
179+
}
180+
181+
if len(zs) < 1 {
182+
return "", fmt.Errorf("no valid zone in account for certificate '%s'", domain)
183+
}
184+
185+
// powerdns _only_ looks for records on the longest matching subdomain zone aka,
186+
// for test.sub.example.com if sub.example.com exists,
187+
// it will look there it will not look atexample.com even if it also exists
188+
sort.Slice(zs, func(i, j int) bool {
189+
return len(zs[i].Name) > len(zs[j].Name)
190+
})
191+
192+
return zs[0].Name, nil
193+
}

providers/dns/liquidweb/liquidweb.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@ Since = "v3.1.0"
77
Example = '''
88
LIQUID_WEB_USERNAME=someuser \
99
LIQUID_WEB_PASSWORD=somepass \
10-
LIQUID_WEB_ZONE=tacoman.com.net \
1110
lego --email [email protected] --dns liquidweb --domains my.example.org run
1211
'''
1312

1413
[Configuration]
1514
[Configuration.Credentials]
16-
LIQUID_WEB_USERNAME = "Storm API Username"
17-
LIQUID_WEB_PASSWORD = "Storm API Password"
18-
LIQUID_WEB_ZONE = "DNS Zone"
15+
LIQUID_WEB_USERNAME = "Liquid Web API Username"
16+
LIQUID_WEB_PASSWORD = "Liquid Web API Password"
1917
[Configuration.Additional]
20-
LIQUID_WEB_URL = "Storm API endpoint"
18+
LIQUID_WEB_ZONE = "DNS Zone"
19+
LIQUID_WEB_URL = "Liquid Web API endpoint"
2120
LIQUID_WEB_TTL = "The TTL of the TXT record used for the DNS challenge"
2221
LIQUID_WEB_POLLING_INTERVAL = "Time between DNS propagation check"
2322
LIQUID_WEB_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
2423
LIQUID_WEB_HTTP_TIMEOUT = "Maximum waiting time for the DNS records to be created (not verified)"
2524

2625
[Links]
27-
API = "https://cart.liquidweb.com/storm/api/docs/v1/"
26+
API = "https://api.liquidweb.com/docs/"
2827
GoClient = "https://github.com/liquidweb/liquidweb-go"

0 commit comments

Comments
 (0)